mirror of
https://github.com/3proxy/3proxy.git
synced 2026-04-29 07:30:11 +08:00
Use semaphore/mutex insted of pipe for threads sync
This commit is contained in:
parent
ba2584cebf
commit
ada24a98ec
8
.gitignore
vendored
8
.gitignore
vendored
@ -259,3 +259,11 @@ pip-log.txt
|
|||||||
.mr.developer.cfg
|
.mr.developer.cfg
|
||||||
CLAUDE.md
|
CLAUDE.md
|
||||||
bin/3proxy_crypt
|
bin/3proxy_crypt
|
||||||
|
bin/3proxy_ftppr
|
||||||
|
bin/3proxy_pop3p
|
||||||
|
bin/3proxy_proxy
|
||||||
|
bin/3proxy_smtpp
|
||||||
|
bin/3proxy_socks
|
||||||
|
bin/3proxy_tcppm
|
||||||
|
bin/3proxy_tlspr
|
||||||
|
bin/3proxy_udppm
|
||||||
|
|||||||
13
src/3proxy.c
13
src/3proxy.c
@ -521,13 +521,14 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
|
|||||||
pthread_mutex_init(&rad_mutex, NULL);
|
pthread_mutex_init(&rad_mutex, NULL);
|
||||||
#endif
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if(!CreatePipe(&conf.threadinit[0], &conf.threadinit[1], NULL, 1)){
|
conf.threadinit = CreateSemaphore(NULL, 0, 1, NULL);
|
||||||
#else
|
if(!conf.threadinit){
|
||||||
if(pipe(conf.threadinit)) {
|
fprintf(stderr, "semaphore init failed\n");
|
||||||
#endif
|
|
||||||
fprintf(stderr, "CreatePipe failed\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
};
|
}
|
||||||
|
#else
|
||||||
|
pthread_mutex_init(&conf.threadinit, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
freeconf(&conf);
|
freeconf(&conf);
|
||||||
res = readconfig(fp);
|
res = readconfig(fp);
|
||||||
|
|||||||
@ -2,14 +2,8 @@
|
|||||||
# 3 proxy common Makefile
|
# 3 proxy common Makefile
|
||||||
#
|
#
|
||||||
|
|
||||||
# PREFIX: prefix for standalone module binaries (default: 3proxy_)
|
|
||||||
# CRYPT_PREFIX: prefix for crypt binary (default: same as PREFIX)
|
|
||||||
PREFIX ?= 3proxy_
|
|
||||||
CRYPT_PREFIX ?= $(PREFIX)
|
|
||||||
|
|
||||||
all: $(BUILDDIR)3proxy$(EXESUFFICS) $(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS) $(BUILDDIR)$(PREFIX)pop3p$(EXESUFFICS) $(BUILDDIR)$(PREFIX)smtpp$(EXESUFFICS) $(BUILDDIR)$(PREFIX)ftppr$(EXESUFFICS) $(BUILDDIR)$(PREFIX)tcppm$(EXESUFFICS) $(BUILDDIR)$(PREFIX)udppm$(EXESUFFICS) $(BUILDDIR)$(PREFIX)tlspr$(EXESUFFICS) $(BUILDDIR)$(PREFIX)socks$(EXESUFFICS) $(BUILDDIR)$(PREFIX)proxy$(EXESUFFICS) allplugins
|
all: $(BUILDDIR)3proxy$(EXESUFFICS) $(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS) $(BUILDDIR)$(PREFIX)pop3p$(EXESUFFICS) $(BUILDDIR)$(PREFIX)smtpp$(EXESUFFICS) $(BUILDDIR)$(PREFIX)ftppr$(EXESUFFICS) $(BUILDDIR)$(PREFIX)tcppm$(EXESUFFICS) $(BUILDDIR)$(PREFIX)udppm$(EXESUFFICS) $(BUILDDIR)$(PREFIX)tlspr$(EXESUFFICS) $(BUILDDIR)$(PREFIX)socks$(EXESUFFICS) $(BUILDDIR)$(PREFIX)proxy$(EXESUFFICS) allplugins
|
||||||
|
|
||||||
|
|
||||||
sockmap$(OBJSUFFICS): sockmap.c proxy.h structures.h
|
sockmap$(OBJSUFFICS): sockmap.c proxy.h structures.h
|
||||||
$(CC) $(CFLAGS) sockmap.c
|
$(CC) $(CFLAGS) sockmap.c
|
||||||
|
|
||||||
|
|||||||
@ -144,7 +144,11 @@ int timeouts[12] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct extparam conf = {
|
struct extparam conf = {
|
||||||
.threadinit = {0, 0},
|
#ifdef _WIN32
|
||||||
|
.threadinit = NULL,
|
||||||
|
#else
|
||||||
|
.threadinit = 0,
|
||||||
|
#endif
|
||||||
.timeouts = timeouts,
|
.timeouts = timeouts,
|
||||||
.acl = NULL,
|
.acl = NULL,
|
||||||
.conffile = NULL,
|
.conffile = NULL,
|
||||||
|
|||||||
11
src/conf.c
11
src/conf.c
@ -151,9 +151,7 @@ int start_proxy_thread(struct child * chp){
|
|||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
DWORD num;
|
|
||||||
#endif
|
#endif
|
||||||
char r[1];
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#ifndef _WINCE
|
#ifndef _WINCE
|
||||||
@ -166,16 +164,15 @@ int start_proxy_thread(struct child * chp){
|
|||||||
pthread_attr_init(&pa);
|
pthread_attr_init(&pa);
|
||||||
pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + (32768+conf.stacksize));
|
pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + (32768+conf.stacksize));
|
||||||
pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED);
|
pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED);
|
||||||
|
pthread_mutex_lock(&conf.threadinit);
|
||||||
pthread_create(&thread, &pa, startsrv, (void *)chp);
|
pthread_create(&thread, &pa, startsrv, (void *)chp);
|
||||||
pthread_attr_destroy(&pa);
|
pthread_attr_destroy(&pa);
|
||||||
#endif
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ReadFile(conf.threadinit[0], r, 1, &num, NULL);
|
WaitForSingleObject(conf.threadinit, INFINITE);
|
||||||
#else
|
#else
|
||||||
while(read(conf.threadinit[0], r, 1) !=1) if(errno != EINTR) {
|
pthread_mutex_lock(&conf.threadinit);
|
||||||
fprintf(stderr, "pipe failed\n");
|
pthread_mutex_unlock(&conf.threadinit);
|
||||||
return 40;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
if(haveerror) {
|
if(haveerror) {
|
||||||
fprintf(stderr, "Service not started on line: %d%s\n", linenum, haveerror == 2? ": insufficient memory":"");
|
fprintf(stderr, "Service not started on line: %d%s\n", linenum, haveerror == 2? ": insufficient memory":"");
|
||||||
|
|||||||
@ -117,10 +117,10 @@ void * threadfunc (void *p) {
|
|||||||
|
|
||||||
int pushthreadinit(){
|
int pushthreadinit(){
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
DWORD n;
|
return ReleaseSemaphore(conf.threadinit, 1, NULL) ? 1 : 0;
|
||||||
return WriteFile(conf.threadinit[1], "1", 1, &n, NULL);
|
|
||||||
#else
|
#else
|
||||||
return write(conf.threadinit[1], "1", 1);
|
pthread_mutex_unlock(&conf.threadinit);
|
||||||
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -673,9 +673,9 @@ struct filemon {
|
|||||||
|
|
||||||
struct extparam {
|
struct extparam {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HANDLE threadinit[2];
|
HANDLE threadinit;
|
||||||
#else
|
#else
|
||||||
int threadinit[2];
|
pthread_mutex_t threadinit;
|
||||||
#endif
|
#endif
|
||||||
int *timeouts;
|
int *timeouts;
|
||||||
struct ace * acl;
|
struct ace * acl;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user