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
|
||||
CLAUDE.md
|
||||
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);
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
if(!CreatePipe(&conf.threadinit[0], &conf.threadinit[1], NULL, 1)){
|
||||
#else
|
||||
if(pipe(conf.threadinit)) {
|
||||
#endif
|
||||
fprintf(stderr, "CreatePipe failed\n");
|
||||
conf.threadinit = CreateSemaphore(NULL, 0, 1, NULL);
|
||||
if(!conf.threadinit){
|
||||
fprintf(stderr, "semaphore init failed\n");
|
||||
return 1;
|
||||
};
|
||||
}
|
||||
#else
|
||||
pthread_mutex_init(&conf.threadinit, NULL);
|
||||
#endif
|
||||
|
||||
freeconf(&conf);
|
||||
res = readconfig(fp);
|
||||
|
||||
@ -2,14 +2,8 @@
|
||||
# 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
|
||||
|
||||
|
||||
sockmap$(OBJSUFFICS): sockmap.c proxy.h structures.h
|
||||
$(CC) $(CFLAGS) sockmap.c
|
||||
|
||||
|
||||
@ -144,7 +144,11 @@ int timeouts[12] = {
|
||||
};
|
||||
|
||||
struct extparam conf = {
|
||||
.threadinit = {0, 0},
|
||||
#ifdef _WIN32
|
||||
.threadinit = NULL,
|
||||
#else
|
||||
.threadinit = 0,
|
||||
#endif
|
||||
.timeouts = timeouts,
|
||||
.acl = 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;
|
||||
#ifdef _WIN32
|
||||
HANDLE h;
|
||||
DWORD num;
|
||||
#endif
|
||||
char r[1];
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef _WINCE
|
||||
@ -166,16 +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);
|
||||
pthread_create(&thread, &pa, startsrv, (void *)chp);
|
||||
pthread_attr_destroy(&pa);
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
ReadFile(conf.threadinit[0], r, 1, &num, NULL);
|
||||
WaitForSingleObject(conf.threadinit, INFINITE);
|
||||
#else
|
||||
while(read(conf.threadinit[0], r, 1) !=1) if(errno != EINTR) {
|
||||
fprintf(stderr, "pipe failed\n");
|
||||
return 40;
|
||||
}
|
||||
pthread_mutex_lock(&conf.threadinit);
|
||||
pthread_mutex_unlock(&conf.threadinit);
|
||||
#endif
|
||||
if(haveerror) {
|
||||
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(){
|
||||
#ifdef _WIN32
|
||||
DWORD n;
|
||||
return WriteFile(conf.threadinit[1], "1", 1, &n, NULL);
|
||||
return ReleaseSemaphore(conf.threadinit, 1, NULL) ? 1 : 0;
|
||||
#else
|
||||
return write(conf.threadinit[1], "1", 1);
|
||||
pthread_mutex_unlock(&conf.threadinit);
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -673,9 +673,9 @@ struct filemon {
|
||||
|
||||
struct extparam {
|
||||
#ifdef _WIN32
|
||||
HANDLE threadinit[2];
|
||||
HANDLE threadinit;
|
||||
#else
|
||||
int threadinit[2];
|
||||
pthread_mutex_t threadinit;
|
||||
#endif
|
||||
int *timeouts;
|
||||
struct ace * acl;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user