1
0
mirror of https://github.com/lxsang/ant-http synced 2024-07-01 12:59:47 +02:00

fix bug: two threads load a same plugin as the same time

This commit is contained in:
Xuan Sang LE 2018-03-14 12:41:51 +01:00
parent 4679f6ab04
commit f2a2139e5b

View File

@ -1,4 +1,5 @@
#include "http_server.h"
static pthread_mutex_t server_mux = PTHREAD_MUTEX_INITIALIZER;
/**********************************************************************/
/* A request has caused a call to accept() on the server port to
* return. Process the request appropriately.
@ -958,11 +959,16 @@ int execute_plugin(void* client, const char *path, const char *method, dictionar
//load the plugin
if((plugin = plugin_lookup(pname)) == NULL)
if((plugin= plugin_load(pname)) == NULL)
{
pthread_mutex_lock(&server_mux);
plugin= plugin_load(pname);
pthread_mutex_unlock(&server_mux);
if( plugin == NULL)
{
if(orgs) free(orgs);
return -1;
}
}
// load the function
fn = (void (*)(void*, const char *, const char*, dictionary))dlsym(plugin->handle, PLUGIN_HANDLER);
if ((error = dlerror()) != NULL)