From b1ac46da79d9f98391a6ad62971a2f81b8f0b8f6 Mon Sep 17 00:00:00 2001 From: Vladimir Dubrovin <3proxy@3proxy.ru> Date: Tue, 28 Apr 2026 18:06:54 +0300 Subject: [PATCH] Remove linux futext implementation --- src/3proxy.c | 25 ++++++--------- src/auth.c | 12 ++++---- src/authradius.c | 6 ++-- src/common.c | 37 +++------------------- src/conf.c | 46 ++++++++++++++-------------- src/hash.c | 30 +++++++++--------- src/limiter.c | 16 +++++----- src/log.c | 2 +- src/plugins/FilePlugin/FilePlugin.c | 20 ++++++------ src/plugins/PCREPlugin/pcre_plugin.c | 12 ++++---- src/plugins/PamAuth/pamauth.c | 8 ++--- src/plugins/SSLPlugin/my_ssl.c | 16 +++++----- src/proxy.h | 12 ++++---- src/proxymain.c | 30 +++++++++--------- src/sql.c | 6 ++-- src/structures.h | 36 ++++++++-------------- 16 files changed, 134 insertions(+), 180 deletions(-) diff --git a/src/3proxy.c b/src/3proxy.c index 19a8367..8232c41 100644 --- a/src/3proxy.c +++ b/src/3proxy.c @@ -66,9 +66,9 @@ void __stdcall CommandHandler( DWORD dwCommand ) Sleep(2000); SetStatus( SERVICE_STOPPED, 0, 0 ); #ifndef NOODBC - pthread_mutex_lock(&log_mutex); + _3proxy_mutex_lock(&log_mutex); close_sql(); - pthread_mutex_unlock(&log_mutex); + _3proxy_mutex_unlock(&log_mutex); #endif break; case SERVICE_CONTROL_PAUSE: @@ -118,13 +118,6 @@ void mysigpause (int sig){ void mysigterm (int sig){ conf.paused++; - usleep(999*SLEEPTIME); - usleep(999*SLEEPTIME); -#ifndef NOODBC - pthread_mutex_lock(&log_mutex); - close_sql(); - pthread_mutex_unlock(&log_mutex); -#endif conf.timetoexit = 1; } @@ -512,13 +505,13 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int return 1; } - pthread_mutex_init(&config_mutex, NULL); - pthread_mutex_init(&bandlim_mutex, NULL); - pthread_mutex_init(&connlim_mutex, NULL); - pthread_mutex_init(&tc_mutex, NULL); - pthread_mutex_init(&log_mutex, NULL); + _3proxy_mutex_init(&config_mutex); + _3proxy_mutex_init(&bandlim_mutex); + _3proxy_mutex_init(&connlim_mutex); + _3proxy_mutex_init(&tc_mutex); + _3proxy_mutex_init(&log_mutex); #ifndef NORADIUS - pthread_mutex_init(&rad_mutex, NULL); + _3proxy_mutex_init(&rad_mutex); #endif #ifdef _WIN32 conf.threadinit = CreateSemaphore(NULL, 0, 1, NULL); @@ -527,7 +520,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int return 1; } #else - pthread_mutex_init(&conf.threadinit, NULL); + _3proxy_mutex_init(&conf.threadinit); #endif freeconf(&conf); diff --git a/src/auth.c b/src/auth.c index 28ae07c..0727cb3 100644 --- a/src/auth.c +++ b/src/auth.c @@ -20,13 +20,13 @@ int alwaysauth(struct clientparam * param){ res = doconnect(param); if(!res){ if(conf.bandlimfunc && (conf.bandlimiter||conf.bandlimiterout)){ - pthread_mutex_lock(&bandlim_mutex); + _3proxy_mutex_lock(&bandlim_mutex); initbandlims(param); - pthread_mutex_unlock(&bandlim_mutex); + _3proxy_mutex_unlock(&bandlim_mutex); } if(conf.trafcountfunc && conf.trafcounter) { - pthread_mutex_lock(&tc_mutex); + _3proxy_mutex_lock(&tc_mutex); for(tc = conf.trafcounter; tc; tc = tc->next) { if(tc->disabled) continue; if(ACLmatches(tc->ace, param)){ @@ -40,7 +40,7 @@ int alwaysauth(struct clientparam * param){ if(tc->ace->action != COUNTALL) continue; } if(tc->traflim64 <= tc->traf64) { - pthread_mutex_unlock(&tc_mutex); + _3proxy_mutex_unlock(&tc_mutex); return 10; } param->trafcountfunc = conf.trafcountfunc; @@ -55,14 +55,14 @@ int alwaysauth(struct clientparam * param){ continue; } if(tc->traflim64 <= tc->traf64) { - pthread_mutex_unlock(&tc_mutex); + _3proxy_mutex_unlock(&tc_mutex); return 10; } param->trafcountfunc = conf.trafcountfunc; param->maxtrafout64 = tc->traflim64 - tc->traf64; } } - pthread_mutex_unlock(&tc_mutex); + _3proxy_mutex_unlock(&tc_mutex); } } return res; diff --git a/src/authradius.c b/src/authradius.c index a1bf540..2ff0c4a 100644 --- a/src/authradius.c +++ b/src/authradius.c @@ -166,7 +166,7 @@ static int ntry = 0; int nradservers = 0; char radiussecret[64]=""; -pthread_mutex_t rad_mutex; +_3proxy_mutex_t rad_mutex; void md5_calc(unsigned char *output, unsigned char *input, unsigned int inputlen); @@ -327,11 +327,11 @@ int radsend(struct clientparam * param, int auth, int stop){ memset(&packet, 0, sizeof(packet)); - pthread_mutex_lock(&rad_mutex); + _3proxy_mutex_lock(&rad_mutex); if(auth)random_vector(packet.vector, param); id = ((ntry++) & 0xff); - pthread_mutex_unlock(&rad_mutex); + _3proxy_mutex_unlock(&rad_mutex); packet.code = auth?PW_AUTHENTICATION_REQUEST:PW_ACCOUNTING_REQUEST; packet.id=id; diff --git a/src/common.c b/src/common.c index 6c56184..c04f3bf 100644 --- a/src/common.c +++ b/src/common.c @@ -38,35 +38,6 @@ int randomizer = 1; unsigned char **stringtable = NULL; -#ifdef WITH_LINUX_FUTEX -int sys_futex(void *addr1, int op, int val1, struct timespec *timeout, void *addr2, int val3) -{ - return syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3); -} -int mutex_lock(int *val) -{ - int c; - if ((c = __sync_val_compare_and_swap(val, 0, 1)) != 0) - do { - if(c == 2 || __sync_val_compare_and_swap(val, 1, 2) != 0) - sys_futex(val, FUTEX_WAIT_PRIVATE, 2, NULL, NULL, 0); - } while ((c = __sync_val_compare_and_swap(val, 0, 2)) != 0); - - return 0; -} - -int mutex_unlock(int *val) -{ - if(__sync_fetch_and_sub (val, 1) != 1){ - *val = 0; - sys_futex(val, FUTEX_WAKE_PRIVATE, 1, NULL, NULL, 0); - } - - - return 0; -} -#endif - #ifdef WITH_UN void make_un(const unsigned char *path, struct sockaddr_un * sun){ memset(sun, 0, sizeof(*sun)); @@ -691,7 +662,7 @@ int scanaddr(const unsigned char *s, uint32_t * ip, uint32_t * mask) { RESOLVFUNC resolvfunc = NULL; #ifndef _WIN32 -pthread_mutex_t gethostbyname_mutex; +_3proxy_mutex_t gethostbyname_mutex; int ghbn_init = 0; #endif @@ -747,10 +718,10 @@ uint32_t getip(unsigned char *name){ #ifndef NOSTDRESOLVE #if !defined(_WIN32) && !defined(GETHOSTBYNAME_R) if(!ghbn_init){ - pthread_mutex_init(&gethostbyname_mutex, NULL); + _3proxy_mutex_init(&gethostbyname_mutex); ghbn_init++; } - pthread_mutex_lock(&gethostbyname_mutex); + _3proxy_mutex_lock(&gethostbyname_mutex); #endif hp=gethostbyname((char *)name); if (!hp && conf.demanddialprog) { @@ -759,7 +730,7 @@ uint32_t getip(unsigned char *name){ } retval = hp?*(uint32_t *)hp->h_addr:0; #if !defined(_WIN32) && !defined(GETHOSTBYNAME_R) - pthread_mutex_unlock(&gethostbyname_mutex); + _3proxy_mutex_unlock(&gethostbyname_mutex); #endif #ifdef GETHOSTBYNAME_R #undef gethostbyname diff --git a/src/conf.c b/src/conf.c index cd635ce..ae2aa93 100644 --- a/src/conf.c +++ b/src/conf.c @@ -20,10 +20,10 @@ #define DEFAULTCONFIG conf.stringtable[25] #endif -pthread_mutex_t bandlim_mutex; -pthread_mutex_t connlim_mutex; -pthread_mutex_t tc_mutex; -pthread_mutex_t config_mutex; +_3proxy_mutex_t bandlim_mutex; +_3proxy_mutex_t connlim_mutex; +_3proxy_mutex_t tc_mutex; +_3proxy_mutex_t config_mutex; int haveerror = 0; int linenum = 0; @@ -164,15 +164,15 @@ int start_proxy_thread(struct child * chp){ pthread_attr_init(&pa); pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + (32768+conf.stacksize)); pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED); - pthread_mutex_lock(&conf.threadinit); + _3proxy_mutex_lock(&conf.threadinit); pthread_create(&thread, &pa, startsrv, (void *)chp); pthread_attr_destroy(&pa); #endif #ifdef _WIN32 WaitForSingleObject(conf.threadinit, INFINITE); #else - pthread_mutex_lock(&conf.threadinit); - pthread_mutex_unlock(&conf.threadinit); + _3proxy_mutex_lock(&conf.threadinit); + _3proxy_mutex_unlock(&conf.threadinit); #endif if(haveerror) { fprintf(stderr, "Service not started on line: %d%s\n", linenum, haveerror == 2? ": insufficient memory":""); @@ -337,10 +337,10 @@ static int h_log(int argc, unsigned char ** argv){ else if(*argv[1]=='&'){ conf.logfunc = logsql; if(notchanged) return 0; - pthread_mutex_lock(&log_mutex); + _3proxy_mutex_lock(&log_mutex); close_sql(); init_sql((char *)argv[1]+1); - pthread_mutex_unlock(&log_mutex); + _3proxy_mutex_unlock(&log_mutex); } #endif #ifndef NORADIUS @@ -1257,7 +1257,7 @@ static int h_ace(int argc, unsigned char **argv){ sscanf((char *)argv[1], "%u", &ncl->rate); sscanf((char *)argv[2], "%u", &ncl->period); } - pthread_mutex_lock(&connlim_mutex); + _3proxy_mutex_lock(&connlim_mutex); if(!conf.connlimiter){ conf.connlimiter = ncl; } @@ -1267,7 +1267,7 @@ static int h_ace(int argc, unsigned char **argv){ for(cli = conf.connlimiter; cli->next; cli = cli->next); cli->next = ncl; } - pthread_mutex_unlock(&connlim_mutex); + _3proxy_mutex_unlock(&connlim_mutex); break; case BANDLIM: @@ -1289,7 +1289,7 @@ static int h_ace(int argc, unsigned char **argv){ return(4); } } - pthread_mutex_lock(&bandlim_mutex); + _3proxy_mutex_lock(&bandlim_mutex); if(!strcmp((char *)argv[0], "bandlimin") || !strcmp((char *)argv[0], "nobandlimin")){ if(!conf.bandlimiter){ conf.bandlimiter = nbl; @@ -1313,7 +1313,7 @@ static int h_ace(int argc, unsigned char **argv){ } } conf.bandlimver++; - pthread_mutex_unlock(&bandlim_mutex); + _3proxy_mutex_unlock(&bandlim_mutex); break; case COUNTIN: @@ -1365,7 +1365,7 @@ static int h_ace(int argc, unsigned char **argv){ } } } - pthread_mutex_lock(&tc_mutex); + _3proxy_mutex_lock(&tc_mutex); if(!conf.trafcounter){ conf.trafcounter = tl; } @@ -1375,7 +1375,7 @@ static int h_ace(int argc, unsigned char **argv){ for(ntl = conf.trafcounter; ntl->next; ntl = ntl->next); ntl->next = tl; } - pthread_mutex_unlock(&tc_mutex); + _3proxy_mutex_unlock(&tc_mutex); } return 0; @@ -1856,27 +1856,27 @@ void freeconf(struct extparam *confp){ - pthread_mutex_lock(&tc_mutex); + _3proxy_mutex_lock(&tc_mutex); confp->trafcountfunc = NULL; tc = confp->trafcounter; confp->trafcounter = NULL; counterd = confp->counterd; confp->counterd = -1; confp->countertype = NONE; - pthread_mutex_unlock(&tc_mutex); + _3proxy_mutex_unlock(&tc_mutex); - pthread_mutex_lock(&bandlim_mutex); + _3proxy_mutex_lock(&bandlim_mutex); bl = confp->bandlimiter; blout = confp->bandlimiterout; confp->bandlimiter = NULL; confp->bandlimiterout = NULL; confp->bandlimfunc = NULL; confp->bandlimver++; - pthread_mutex_unlock(&bandlim_mutex); - pthread_mutex_lock(&connlim_mutex); + _3proxy_mutex_unlock(&bandlim_mutex); + _3proxy_mutex_lock(&connlim_mutex); cl = confp->connlimiter; confp->connlimiter = NULL; - pthread_mutex_unlock(&connlim_mutex); + _3proxy_mutex_unlock(&connlim_mutex); destroyhashtable(&pw_table); destroyhashtable(&pwnt_table); @@ -1949,7 +1949,7 @@ int reload (void){ FILE *fp; int error = -2; - pthread_mutex_lock(&config_mutex); + _3proxy_mutex_lock(&config_mutex); conf.paused++; freeconf(&conf); conf.paused++; @@ -1963,6 +1963,6 @@ int reload (void){ } if(!writable)fclose(fp); } - pthread_mutex_unlock(&config_mutex); + _3proxy_mutex_unlock(&config_mutex); return error; } diff --git a/src/hash.c b/src/hash.c index d20bd20..1bb8183 100644 --- a/src/hash.c +++ b/src/hash.c @@ -12,7 +12,7 @@ static uint32_t hashindex(unsigned tablesize, const uint8_t* hash){ void destroyhashtable(struct hashtable *ht){ - pthread_mutex_lock(&ht->hash_mutex); + _3proxy_mutex_lock(&ht->hash_mutex); if(ht->ihashtable){ myfree(ht->ihashtable); ht->ihashtable = NULL; @@ -28,8 +28,8 @@ void destroyhashtable(struct hashtable *ht){ ht->poolsize = 0; ht->tablesize = 0; ht->ihashempty = 0; - pthread_mutex_unlock(&ht->hash_mutex); - pthread_mutex_destroy(&ht->hash_mutex); + _3proxy_mutex_unlock(&ht->hash_mutex); + _3proxy_mutex_destroy(&ht->hash_mutex); } #define hvalue(ht,I) ((struct hashentry *)(ht->hashvalues + (I-1)*(sizeof(struct hashentry) + ht->recsize - 4))) @@ -53,7 +53,7 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u if(tablesize < 2 || poolsize < tablesize || growlimit < poolsize) return 1; if(ht->ihashtable){ - pthread_mutex_lock(&ht->hash_mutex); + _3proxy_mutex_lock(&ht->hash_mutex); if(ht->ihashtable){ myfree(ht->ihashtable); ht->ihashtable = NULL; @@ -70,8 +70,8 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u ht->tablesize = 0; } else { - pthread_mutex_init(&ht->hash_mutex, NULL); - pthread_mutex_lock(&ht->hash_mutex); + _3proxy_mutex_init(&ht->hash_mutex); + _3proxy_mutex_lock(&ht->hash_mutex); } if(!(ht->ihashtable = myalloc(tablesize * sizeof(uint32_t))) || !(ht->hashvalues = myalloc(poolsize * (sizeof(struct hashentry) + ht->recsize - 4))) @@ -81,7 +81,7 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u ht->ihashtable = NULL; myfree(ht->hashvalues); ht->hashvalues = NULL; - pthread_mutex_unlock(&ht->hash_mutex); + _3proxy_mutex_unlock(&ht->hash_mutex); return 3; } ht->poolsize = poolsize; @@ -94,7 +94,7 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u hvalue(ht,i)->inext = i+1; } ht->ihashempty = 1; - pthread_mutex_unlock(&ht->hash_mutex); + _3proxy_mutex_unlock(&ht->hash_mutex); return 0; } @@ -179,7 +179,7 @@ void hashadd(struct hashtable *ht, void* name, void* value, time_t expires){ } ht->index2hash_add(ht, name, hash); - pthread_mutex_lock(&ht->hash_mutex); + _3proxy_mutex_lock(&ht->hash_mutex); index = hashindex(ht->tablesize, hash); for(hep = ht->ihashtable + index; (he = *hep)!=0; ){ @@ -214,7 +214,7 @@ void hashadd(struct hashtable *ht, void* name, void* value, time_t expires){ hvalue(ht,hen)->expires = expires; } - pthread_mutex_unlock(&ht->hash_mutex); + _3proxy_mutex_unlock(&ht->hash_mutex); } int hashresolv(struct hashtable *ht, void* name, void* value, uint32_t *ttl){ @@ -227,7 +227,7 @@ int hashresolv(struct hashtable *ht, void* name, void* value, uint32_t *ttl){ return 0; } ht->index2hash_search(ht,name, hash); - pthread_mutex_lock(&ht->hash_mutex); + _3proxy_mutex_lock(&ht->hash_mutex); index = hashindex(ht->tablesize, hash); for(hep = ht->ihashtable + index; (he = *hep)!=0; ){ if(hvalue(ht, he)->expires < conf.time) { @@ -239,12 +239,12 @@ int hashresolv(struct hashtable *ht, void* name, void* value, uint32_t *ttl){ else if(!memcmp(hash, hhash(ht,he), ht->hash_size)){ if(ttl) *ttl = (uint32_t)(hvalue(ht,he)->expires - conf.time); memcpy(value, hvalue(ht,he)->value, ht->recsize); - pthread_mutex_unlock(&ht->hash_mutex); + _3proxy_mutex_unlock(&ht->hash_mutex); return 1; } else hep=&(hvalue(ht,he)->inext); } - pthread_mutex_unlock(&ht->hash_mutex); + _3proxy_mutex_unlock(&ht->hash_mutex); return 0; } @@ -258,7 +258,7 @@ void hashdelete(struct hashtable *ht, void *name){ return; } ht->index2hash_search(ht, name, hash); - pthread_mutex_lock(&ht->hash_mutex); + _3proxy_mutex_lock(&ht->hash_mutex); index = hashindex(ht->tablesize, hash); for(hep = ht->ihashtable + index; (he = *hep) != 0; ){ if((hvalue(ht, he)->expires && hvalue(ht, he)->expires < conf.time) || !memcmp(hash, hhash(ht, he), ht->hash_size)) { @@ -269,7 +269,7 @@ void hashdelete(struct hashtable *ht, void *name){ } else hep = &(hvalue(ht, he)->inext); } - pthread_mutex_unlock(&ht->hash_mutex); + _3proxy_mutex_unlock(&ht->hash_mutex); } #define MURMUR_C1 0xcc9e2d51u diff --git a/src/limiter.c b/src/limiter.c index 02ae5cf..6ec2d26 100644 --- a/src/limiter.c +++ b/src/limiter.c @@ -15,7 +15,7 @@ int startconnlims (struct clientparam *param){ int ret = 0; param->connlim = 1; - pthread_mutex_lock(&connlim_mutex); + _3proxy_mutex_lock(&connlim_mutex); for(ce = conf.connlimiter; ce; ce = ce->next) { if(ACLmatches(ce->ace, param)){ if(ce->ace->action == NOCONNLIM)break; @@ -51,14 +51,14 @@ int startconnlims (struct clientparam *param){ } param->connlim = 0; } - pthread_mutex_unlock(&connlim_mutex); + _3proxy_mutex_unlock(&connlim_mutex); return ret; } void stopconnlims (struct clientparam *param){ struct connlim * ce; - pthread_mutex_lock(&connlim_mutex); + _3proxy_mutex_lock(&connlim_mutex); for(ce = conf.connlimiter; ce; ce = ce->next) { if(ACLmatches(ce->ace, param)){ if(ce->ace->action == NOCONNLIM)break; @@ -68,7 +68,7 @@ void stopconnlims (struct clientparam *param){ } } } - pthread_mutex_unlock(&connlim_mutex); + _3proxy_mutex_unlock(&connlim_mutex); } void initbandlims (struct clientparam *param){ @@ -124,7 +124,7 @@ unsigned bandlimitfunc(struct clientparam *param, unsigned nbytesin, unsigned nb #endif if(!nbytesin && !nbytesout) return 0; - pthread_mutex_lock(&bandlim_mutex); + _3proxy_mutex_lock(&bandlim_mutex); if(param->bandlimver != conf.bandlimver){ initbandlims(param); param->bandlimver = conf.bandlimver; @@ -163,7 +163,7 @@ unsigned bandlimitfunc(struct clientparam *param, unsigned nbytesin, unsigned nb param->bandlimsout[i]->basetime = sec; param->bandlimsout[i]->nexttime = msec + nsleeptime + ((nbytesout > 512)? ((nbytesout+32)/64)*((64*8*1000000)/param->bandlimsout[i]->rate) : ((nbytesout+1)* (8*1000000))/param->bandlimsout[i]->rate); } - pthread_mutex_unlock(&bandlim_mutex); + _3proxy_mutex_unlock(&bandlim_mutex); return sleeptime/1000; } @@ -171,7 +171,7 @@ void trafcountfunc(struct clientparam *param){ struct trafcount * tc; int countout = 0; - pthread_mutex_lock(&tc_mutex); + _3proxy_mutex_lock(&tc_mutex); for(tc = conf.trafcounter; tc; tc = tc->next) { if(ACLmatches(tc->ace, param)){ @@ -199,6 +199,6 @@ void trafcountfunc(struct clientparam *param){ } } - pthread_mutex_unlock(&tc_mutex); + _3proxy_mutex_unlock(&tc_mutex); } diff --git a/src/log.c b/src/log.c index 969d258..c1279c5 100644 --- a/src/log.c +++ b/src/log.c @@ -10,7 +10,7 @@ #include "proxy.h" -pthread_mutex_t log_mutex; +_3proxy_mutex_t log_mutex; int havelog = 0; diff --git a/src/plugins/FilePlugin/FilePlugin.c b/src/plugins/FilePlugin/FilePlugin.c index 0a4e941..0c2d6c7 100644 --- a/src/plugins/FilePlugin/FilePlugin.c +++ b/src/plugins/FilePlugin/FilePlugin.c @@ -45,7 +45,7 @@ extern "C" { static struct pluginlink * pl; -static pthread_mutex_t file_mutex; +static _3proxy_mutex_t file_mutex; unsigned long preview = 0; @@ -207,7 +207,7 @@ static void closefiles(struct fp_stream *fps){ static int searchsocket(SOCKET s, struct fp_stream **pfps){ struct fp_stream *fps = NULL; int ret = 0; - pthread_mutex_lock(&file_mutex); + _3proxy_mutex_lock(&file_mutex); for(fps = fp_streams; fps; fps = fps->next){ if(fps->fpd.cp->clisock == s) { ret = 1; @@ -222,7 +222,7 @@ static int searchsocket(SOCKET s, struct fp_stream **pfps){ break; } } - pthread_mutex_unlock(&file_mutex); + _3proxy_mutex_unlock(&file_mutex); *pfps = fps; return ret; } @@ -235,7 +235,7 @@ static void freecallback(struct fp_stream * fps, struct fp_callback * fpc){ static void removefps(struct fp_stream * fps){ if(!fp_streams) return; - pthread_mutex_lock(&file_mutex); + _3proxy_mutex_lock(&file_mutex); if(fp_streams == fps)fp_streams = fps->next; else { struct fp_stream *fps2; @@ -248,7 +248,7 @@ static void removefps(struct fp_stream * fps){ } } - pthread_mutex_unlock(&file_mutex); + _3proxy_mutex_unlock(&file_mutex); if(fps->callbacks){ freecallback(fps, fps->callbacks); fps->callbacks = 0; @@ -754,7 +754,7 @@ static int fp_registercallback (int what, int max_size, int preview_size, struct fpc->max_size = max_size; fpc->data = data; fpc->callback = cb; - pthread_mutex_lock(&file_mutex); + _3proxy_mutex_lock(&file_mutex); fps = addfps(cp); if(fps){ fpc->next = fps->callbacks; @@ -763,7 +763,7 @@ static int fp_registercallback (int what, int max_size, int preview_size, struct if(preview_size > fps->preview_size) fps->preview_size = preview_size; } else free(fpc); - pthread_mutex_unlock(&file_mutex); + _3proxy_mutex_unlock(&file_mutex); return fps?1:0; } @@ -777,9 +777,9 @@ static void * fp_open(void * idata, struct srvparam * param){ static FILTER_ACTION fp_client(void *fo, struct clientparam * param, void** fc){ - pthread_mutex_lock(&file_mutex); + _3proxy_mutex_lock(&file_mutex); (*fc) = (void *)addfps(param); - pthread_mutex_unlock(&file_mutex); + _3proxy_mutex_unlock(&file_mutex); return CONTINUE; } @@ -913,7 +913,7 @@ static int file_loaded=0; int argc, char** argv){ if(!file_loaded){ - pthread_mutex_init(&file_mutex, NULL); + _3proxy_mutex_init(&file_mutex); file_loaded = 1; pl = pluginlink; memcpy(&sso, pl->so, sizeof(struct sockfuncs)); diff --git a/src/plugins/PCREPlugin/pcre_plugin.c b/src/plugins/PCREPlugin/pcre_plugin.c index 1d09203..fa6438c 100644 --- a/src/plugins/PCREPlugin/pcre_plugin.c +++ b/src/plugins/PCREPlugin/pcre_plugin.c @@ -21,7 +21,7 @@ extern "C" { static struct pluginlink * pl; -static pthread_mutex_t pcre_mutex; +static _3proxy_mutex_t pcre_mutex; static struct filter pcre_first_filter = { @@ -112,7 +112,7 @@ struct pcre_filter_data { }; static void pcre_data_free(struct pcre_filter_data *pcrefd){ - pthread_mutex_lock(&pcre_mutex); + _3proxy_mutex_lock(&pcre_mutex); pcrefd->users--; if(!pcrefd->users){ if(pcrefd->match_data) pcre2_match_data_free(pcrefd->match_data); @@ -121,7 +121,7 @@ static void pcre_data_free(struct pcre_filter_data *pcrefd){ if(pcrefd->replace) pl->freefunc(pcrefd->replace); pl->freefunc(pcrefd); } - pthread_mutex_unlock(&pcre_mutex); + _3proxy_mutex_unlock(&pcre_mutex); } @@ -130,9 +130,9 @@ static void pcre_data_free(struct pcre_filter_data *pcrefd){ static void* pcre_filter_open(void * idata, struct srvparam * param){ #define pcrefd ((struct pcre_filter_data *)idata) if(idata){ - pthread_mutex_lock(&pcre_mutex); + _3proxy_mutex_lock(&pcre_mutex); pcrefd->users++; - pthread_mutex_unlock(&pcre_mutex); + _3proxy_mutex_unlock(&pcre_mutex); } #undef pcrefd return idata; @@ -517,7 +517,7 @@ PLUGINAPI int PLUGINCALL pcre_plugin (struct pluginlink * pluginlink, pcre_options = 0; if(!pcre_loaded){ pcre_loaded = 1; - pthread_mutex_init(&pcre_mutex, NULL); + _3proxy_mutex_init(&pcre_mutex); regexp_symbols[2].next = pl->symbols.next; pl->symbols.next = regexp_symbols; pcre_commandhandlers[3].next = pl->commandhandlers->next; diff --git a/src/plugins/PamAuth/pamauth.c b/src/plugins/PamAuth/pamauth.c index d8646aa..160ae3a 100644 --- a/src/plugins/PamAuth/pamauth.c +++ b/src/plugins/PamAuth/pamauth.c @@ -12,7 +12,7 @@ Kirill Lopuchov #include -pthread_mutex_t pam_mutex; +_3proxy_mutex_t pam_mutex; static int already_loaded = 0; @@ -89,7 +89,7 @@ static int pamfunc(struct clientparam *param) /*start process auth */ conv.appdata_ptr = (char *) param->password; - pthread_mutex_lock(&pam_mutex); + _3proxy_mutex_lock(&pam_mutex); if (!pamh) { retval = pam_start ((char *)service, (char *)param->username, &conv, &pamh); @@ -113,7 +113,7 @@ static int pamfunc(struct clientparam *param) retval = pam_end (pamh, retval); if (retval != PAM_SUCCESS) { pamh = NULL; } - pthread_mutex_unlock(&pam_mutex); + _3proxy_mutex_unlock(&pam_mutex); return rc; @@ -140,7 +140,7 @@ PLUGINAPI int PLUGINCALL start(struct pluginlink * pluginlink, int argc, unsigne already_loaded = 1; - pthread_mutex_init(&pam_mutex, NULL); + _3proxy_mutex_init(&pam_mutex); pamauth.authenticate = pamfunc; pamauth.authorize = pluginlink->checkACL; pamauth.desc = "pam"; diff --git a/src/plugins/SSLPlugin/my_ssl.c b/src/plugins/SSLPlugin/my_ssl.c index abc25f7..f76bd52 100644 --- a/src/plugins/SSLPlugin/my_ssl.c +++ b/src/plugins/SSLPlugin/my_ssl.c @@ -32,7 +32,7 @@ typedef struct _ssl_conn { SSL *ssl; } ssl_conn; -pthread_mutex_t ssl_file_mutex; +_3proxy_mutex_t ssl_file_mutex; static char errbuf[256]; @@ -229,15 +229,15 @@ void _ssl_cert_free(SSL_CERT cert) /* This array will store all of the mutexes available to OpenSSL. */ -static pthread_mutex_t *mutex_buf= NULL; +static _3proxy_mutex_t *mutex_buf= NULL; static void locking_function(int mode, int n, const char * file, int line) { if (mode & CRYPTO_LOCK) - pthread_mutex_lock(mutex_buf + n); + _3proxy_mutex_lock(mutex_buf + n); else - pthread_mutex_unlock(mutex_buf + n); + _3proxy_mutex_unlock(mutex_buf + n); } static unsigned long id_function(void) @@ -253,11 +253,11 @@ int thread_setup(void) { int i; - mutex_buf = malloc(CRYPTO_num_locks( ) * sizeof(pthread_mutex_t)); + mutex_buf = malloc(CRYPTO_num_locks( ) * sizeof(_3proxy_mutex_t)); if (!mutex_buf) return 0; for (i = 0; i < CRYPTO_num_locks( ); i++) - pthread_mutex_init(mutex_buf +i, NULL); + _3proxy_mutex_init(mutex_buf +i); CRYPTO_set_id_callback(id_function); CRYPTO_set_locking_callback(locking_function); return 1; @@ -272,7 +272,7 @@ int thread_cleanup(void) CRYPTO_set_id_callback(NULL); CRYPTO_set_locking_callback(NULL); for (i = 0; i < CRYPTO_num_locks( ); i++) - pthread_mutex_destroy(mutex_buf +i); + _3proxy_mutex_destroy(mutex_buf +i); free(mutex_buf); mutex_buf = NULL; return 1; @@ -291,7 +291,7 @@ void ssl_init() thread_setup(); SSLeay_add_ssl_algorithms(); SSL_load_error_strings(); - pthread_mutex_init(&ssl_file_mutex, NULL); + _3proxy_mutex_init(&ssl_file_mutex); bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); } } diff --git a/src/proxy.h b/src/proxy.h index 7484525..cfc3971 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -323,12 +323,12 @@ struct datatype; struct dictionary; struct node; struct property; -extern pthread_mutex_t config_mutex; -extern pthread_mutex_t bandlim_mutex; -extern pthread_mutex_t connlim_mutex; -extern pthread_mutex_t tc_mutex; -extern pthread_mutex_t log_mutex; -extern pthread_mutex_t rad_mutex; +extern _3proxy_mutex_t config_mutex; +extern _3proxy_mutex_t bandlim_mutex; +extern _3proxy_mutex_t connlim_mutex; +extern _3proxy_mutex_t tc_mutex; +extern _3proxy_mutex_t log_mutex; +extern _3proxy_mutex_t rad_mutex; extern struct datatype datatypes[64]; extern struct commands commandhandlers[]; diff --git a/src/proxymain.c b/src/proxymain.c index 60649ea..855bb09 100644 --- a/src/proxymain.c +++ b/src/proxymain.c @@ -119,7 +119,7 @@ int pushthreadinit(){ #ifdef _WIN32 return ReleaseSemaphore(conf.threadinit, 1, NULL) ? 1 : 0; #else - pthread_mutex_unlock(&conf.threadinit); + _3proxy_mutex_unlock(&conf.threadinit); return 1; #endif } @@ -383,7 +383,7 @@ int MODULEMAINFUNC (int argc, char** argv){ #endif #else srv.needuser = 0; - pthread_mutex_init(&log_mutex, NULL); + _3proxy_mutex_init(&log_mutex); #endif for (i=1; iremsock, (struct sockaddr *)&toparam->sinsr, udpbuf, udplen, 0); toparam->statscli64 += udplen; toparam->nwrites++; - pthread_mutex_unlock(&srv.counter_mutex); + _3proxy_mutex_unlock(&srv.counter_mutex); continue; } - pthread_mutex_unlock(&srv.counter_mutex); + _3proxy_mutex_unlock(&srv.counter_mutex); } #endif if(! (newparam = myalloc (sizeof(defparam)))){ @@ -996,7 +996,7 @@ int MODULEMAINFUNC (int argc, char** argv){ #endif newparam->prev = newparam->next = NULL; error = 0; - pthread_mutex_lock(&srv.counter_mutex); + _3proxy_mutex_lock(&srv.counter_mutex); if(!srv.child){ srv.child = newparam; } @@ -1020,7 +1020,7 @@ int MODULEMAINFUNC (int argc, char** argv){ if(!srv.silent)dolog(&defparam, buf); error = 1; } - pthread_mutex_unlock(&srv.counter_mutex); + _3proxy_mutex_unlock(&srv.counter_mutex); if(error) freeparam(newparam); #else @@ -1031,14 +1031,14 @@ int MODULEMAINFUNC (int argc, char** argv){ if(newparam->prev) newparam->prev->next = newparam->next; else srv.child = newparam->next; if(newparam->next) newparam->next->prev = newparam->prev; - pthread_mutex_unlock(&srv.counter_mutex); + _3proxy_mutex_unlock(&srv.counter_mutex); newparam->srv = NULL; freeparam(newparam); } else { srv.childcount++; newparam->threadid = (uint64_t)thread; - pthread_mutex_unlock(&srv.counter_mutex); + _3proxy_mutex_unlock(&srv.counter_mutex); } #endif @@ -1048,11 +1048,11 @@ int MODULEMAINFUNC (int argc, char** argv){ #ifndef STDMAIN - pthread_mutex_lock(&config_mutex); + _3proxy_mutex_lock(&config_mutex); if(srv.next)srv.next->prev = srv.prev; if(srv.prev)srv.prev->next = srv.next; else conf.services = srv.next; - pthread_mutex_unlock(&config_mutex); + _3proxy_mutex_unlock(&config_mutex); #endif if(!srv.silent) srv.logfunc(&defparam, (unsigned char *)"Exiting thread"); @@ -1101,7 +1101,7 @@ void srvinit(struct srvparam * srv, struct clientparam *param){ param->paused = srv->paused; param->remsock = param->clisock = param->ctrlsock = param->ctrlsocksrv = INVALID_SOCKET; *SAFAMILY(¶m->req) = *SAFAMILY(¶m->sinsl) = *SAFAMILY(¶m->sinsr) = *SAFAMILY(¶m->sincr) = *SAFAMILY(¶m->sincl) = AF_INET; - pthread_mutex_init(&srv->counter_mutex, NULL); + _3proxy_mutex_init(&srv->counter_mutex); srv->intsa = conf.intsa; srv->extsa = conf.extsa; #ifndef NOIPV6 @@ -1166,7 +1166,7 @@ void srvfree(struct srvparam * srv){ if(srv->acl)freeacl(srv->acl); if(srv->authfuncs)freeauth(srv->authfuncs); #endif - pthread_mutex_destroy(&srv->counter_mutex); + _3proxy_mutex_destroy(&srv->counter_mutex); if(srv->target) myfree(srv->target); if(srv->logtarget) myfree(srv->logtarget); if(srv->logformat) myfree(srv->logformat); @@ -1183,7 +1183,7 @@ void freeparam(struct clientparam * param) { if(param->res == 2) return; if(param->srv){ if(param->srv->so.freefunc) param->srv->so.freefunc(param->sostate); - pthread_mutex_lock(¶m->srv->counter_mutex); + _3proxy_mutex_lock(¶m->srv->counter_mutex); #ifndef STDMAIN if(param->srv->service == S_UDPPM) hashdelete(&udp_table, param); #endif @@ -1196,7 +1196,7 @@ void freeparam(struct clientparam * param) { param->next->prev = param->prev; } (param->srv->childcount)--; - pthread_mutex_unlock(¶m->srv->counter_mutex); + _3proxy_mutex_unlock(¶m->srv->counter_mutex); } if(param->clibuf) myfree(param->clibuf); if(param->srvbuf) myfree(param->srvbuf); diff --git a/src/sql.c b/src/sql.c index da905cc..626e984 100644 --- a/src/sql.c +++ b/src/sql.c @@ -98,7 +98,7 @@ void sqlerr (char *buf){ fprintf(conf.stdlog, "%s\n", buf); fflush(conf.stdlog); } - pthread_mutex_unlock(&log_mutex); + _3proxy_mutex_unlock(&log_mutex); } unsigned char statbuf[8192]; @@ -109,7 +109,7 @@ void logsql(struct clientparam * param, const unsigned char *s) { if(param->nolog) return; - pthread_mutex_lock(&log_mutex); + _3proxy_mutex_lock(&log_mutex); len = dobuf(param, statbuf, s, (unsigned char *)"\'"); if(attempt > 5){ @@ -146,7 +146,7 @@ void logsql(struct clientparam * param, const unsigned char *s) { } attempt = 0; } - pthread_mutex_unlock(&log_mutex); + _3proxy_mutex_unlock(&log_mutex); } #endif \ No newline at end of file diff --git a/src/structures.h b/src/structures.h index 81abbe2..225c1f2 100644 --- a/src/structures.h +++ b/src/structures.h @@ -37,29 +37,19 @@ extern "C" { #define SASIZETYPE socklen_t #define SOCKET int #define INVALID_SOCKET (-1) -#ifdef WITH_LINUX_FUTEX -#define _GNU_SOURCE -#include -#include -#include -#include -#define pthread_mutex_t int -#define pthread_mutex_init(x, y) (*(x)=0) -#define pthread_mutex_destroy(x) (*(x)=0) -#define pthread_mutex_lock(x) mutex_lock(x) -#define pthread_mutex_unlock(x) mutex_unlock(x) -int mutex_lock(int *val); -int mutex_unlock(int *val); -#else -#endif +#define _3proxy_mutex_t pthread_mutex_t +#define _3proxy_mutex_init(x) pthread_mutex_init(x,NULL) +#define _3proxy_mutex_destroy pthread_mutex_destroy +#define _3proxy_mutex_lock pthread_mutex_lock +#define _3proxy_mutex_unlock pthread_mutex_unlock #else #include #include -#define pthread_mutex_t CRITICAL_SECTION -#define pthread_mutex_init(x, y) InitializeCriticalSection(x) -#define pthread_mutex_lock(x) EnterCriticalSection(x) -#define pthread_mutex_unlock(x) LeaveCriticalSection(x) -#define pthread_mutex_destroy(x) DeleteCriticalSection(x) +#define _3proxy_mutex_t CRITICAL_SECTION +#define _3proxy_mutex_init(x) InitializeCriticalSection(x) +#define _3proxy_mutex_lock(x) EnterCriticalSection(x) +#define _3proxy_mutex_unlock(x) LeaveCriticalSection(x) +#define _3proxy_mutex_destroy(x) DeleteCriticalSection(x) #ifdef MSVC #pragma warning (disable : 4996) #endif @@ -511,7 +501,7 @@ struct hashtable { uint32_t * ihashtable; uint8_t * hashvalues; uint8_t * hashhashvalues; - pthread_mutex_t hash_mutex; + _3proxy_mutex_t hash_mutex; time_t compacted; uint32_t ihashhashempty; uint32_t ihashempty; @@ -556,7 +546,7 @@ struct srvparam { PROXYSOCKADDRTYPE extsa6; #endif PROXYSOCKADDRTYPE extsa; - pthread_mutex_t counter_mutex; + _3proxy_mutex_t counter_mutex; struct pollfd fds; FILE *stdlog; unsigned char * target; @@ -675,7 +665,7 @@ struct extparam { #ifdef _WIN32 HANDLE threadinit; #else - pthread_mutex_t threadinit; + _3proxy_mutex_t threadinit; #endif int *timeouts; struct ace * acl;