From b4b3dab2b00c3b179b0198ad003e8699b249db27 Mon Sep 17 00:00:00 2001 From: YX Hao Date: Sat, 24 Sep 2022 19:34:49 +0800 Subject: [PATCH] Use NULL_RWLOCK and NULL_THREAD for different platforms --- common.h | 4 ++-- dnscache.c | 2 +- dynamichosts.c | 2 +- filter.c | 2 +- ipmisc.c | 2 +- mmgr.c | 8 ++++---- rwlock.h | 2 ++ tcpm.c | 2 +- udpm.c | 6 +++--- utils.c | 2 +- 10 files changed, 17 insertions(+), 15 deletions(-) diff --git a/common.h b/common.h index 5a01bf4..0df2460 100755 --- a/common.h +++ b/common.h @@ -35,6 +35,7 @@ /* In Windows, the indetifer of a thread is just a 'HANDLE'. */ typedef HANDLE ThreadHandle; + #define NULL_THREAD ((ThreadHandle)NULL) /* And Mutex */ typedef HANDLE MutexHandle; @@ -142,6 +143,7 @@ /* We use pthread to implement multi threads */ /* The indetifer of pthread is 'pthread_t'. */ typedef pthread_t ThreadHandle; + #define NULL_THREAD ((ThreadHandle)0) /* And mutex */ typedef pthread_mutex_t MutexHandle; /* spin lock */ @@ -282,8 +284,6 @@ #define GetFileDirectory(out) (GetConfigDirectory(out)) #endif /* WIN32 */ -#define INVALID_THREAD ((ThreadHandle)NULL) - #ifndef MSG_NOSIGNAL #define MSG_NOSIGNAL 0 #endif /* MSG_NOSIGNAL */ diff --git a/dnscache.c b/dnscache.c index df78524..c6e697e 100755 --- a/dnscache.c +++ b/dnscache.c @@ -19,7 +19,7 @@ static BOOL Inited = FALSE; static BOOL CacheParallel = FALSE; -static RWLock CacheLock = {NULL}; +static RWLock CacheLock = NULL_RWLOCK; static FileHandle CacheFileHandle = INVALID_FILE; static MappingHandle CacheMappingHandle = INVALID_MAP; diff --git a/dynamichosts.c b/dynamichosts.c index a05cb0a..c7c83e7 100755 --- a/dynamichosts.c +++ b/dynamichosts.c @@ -14,7 +14,7 @@ #define SIZE_OF_PATH_BUFFER 384 static const char *File = NULL; -static RWLock HostsLock = {NULL}; +static RWLock HostsLock = NULL_RWLOCK; static volatile HostsContainer *MainDynamicContainer = NULL; /* Arguments for updating */ diff --git a/filter.c b/filter.c index 2247d31..da25051 100755 --- a/filter.c +++ b/filter.c @@ -12,7 +12,7 @@ static Bst *DisabledTypes = NULL; static StringChunk *DisabledDomain = NULL; -static RWLock DisabledDomainLock = {NULL}; +static RWLock DisabledDomainLock = NULL_RWLOCK; static ConfigFileInfo *CurrConfigInfo = NULL; diff --git a/ipmisc.c b/ipmisc.c index 5a1db86..a230dcf 100755 --- a/ipmisc.c +++ b/ipmisc.c @@ -159,7 +159,7 @@ int IPMisc_Init(IPMisc *m) /** Mapping */ static IPMisc *CurrIpMiscMapping = NULL; -static RWLock IpMiscMappingLock = {NULL}; +static RWLock IpMiscMappingLock = NULL_RWLOCK; static ConfigFileInfo *CurrConfigInfo = NULL; static void IpMiscMapping_Free(IPMisc *ipMiscMapping) diff --git a/mmgr.c b/mmgr.c index 104eaa6..1667dda 100755 --- a/mmgr.c +++ b/mmgr.c @@ -34,7 +34,7 @@ typedef struct _ModuleMap { } ModuleMap; static ModuleMap *CurModuleMap = NULL; -static RWLock ModulesLock = {NULL}; +static RWLock ModulesLock = NULL_RWLOCK; static ConfigFileInfo *CurrConfigInfo = NULL; static BOOL EnableUDPtoTCP; @@ -599,13 +599,13 @@ static int Modules_SafeCleanup(ModuleMap *ModuleMap) if( strcmp(M->ModuleName, "UDP") == 0 ) { M->ModuleUnion.Udp.IsServer = 0; - InUse |= M->ModuleUnion.Udp.WorkThread != NULL; - InUse |= M->ModuleUnion.Udp.SwepThread != NULL; + InUse |= M->ModuleUnion.Udp.WorkThread != NULL_THREAD; + InUse |= M->ModuleUnion.Udp.SwepThread != NULL_THREAD; } else if( strcmp(M->ModuleName, "TCP") == 0 ) { M->ModuleUnion.Tcp.IsServer = 0; - InUse |= M->ModuleUnion.Tcp.WorkThread != NULL; + InUse |= M->ModuleUnion.Tcp.WorkThread != NULL_THREAD; } } } diff --git a/rwlock.h b/rwlock.h index 8467013..b2f7e2c 100755 --- a/rwlock.h +++ b/rwlock.h @@ -18,6 +18,7 @@ #else /* WIN64 */ typedef CRITICAL_SECTION RWLock; #endif /* WIN64 */ + #define NULL_RWLOCK {NULL} #else /* WIN32 */ #ifdef HAVE_PTHREAD_RWLOCK_INIT @@ -25,6 +26,7 @@ #else /* HAVE_PTHREAD_RWLOCK_INIT */ typedef pthread_mutex_t RWLock; #endif /* HAVE_PTHREAD_RWLOCK_INIT */ + #define NULL_RWLOCK {0} #endif /* WIN32 */ diff --git a/tcpm.c b/tcpm.c index 451be3d..dc31be2 100755 --- a/tcpm.c +++ b/tcpm.c @@ -561,7 +561,7 @@ static int TcpM_Cleanup(TcpM *m) SafeFree(m->ServiceFamilies); SafeFree(m->SocksProxyFamilies); - m->WorkThread = NULL; + m->WorkThread = NULL_THREAD; return 0; } diff --git a/udpm.c b/udpm.c index 60299b7..62059bf 100755 --- a/udpm.c +++ b/udpm.c @@ -35,7 +35,7 @@ static int SwepTask(UdpM *m, SwepCallback cb) static int UdpM_Swep_Thread(UdpM *m) { - while( m->IsServer || m->WorkThread != NULL) + while( m->IsServer || m->WorkThread != NULL_THREAD) { SwepTask(m, (SwepCallback)SweepWorks); SLEEP(10000); @@ -44,7 +44,7 @@ static int UdpM_Swep_Thread(UdpM *m) ModuleContext_Free(&(m->Context)); EFFECTIVE_LOCK_DESTROY(m->Lock); - m->SwepThread = NULL; + m->SwepThread = NULL_THREAD; return 0; } @@ -59,7 +59,7 @@ static int UdpM_Cleanup(UdpM *m) SafeFree(m->Parallels.addrs); AddressList_Free(&(m->AddrList)); - m->WorkThread = NULL; + m->WorkThread = NULL_THREAD; return 0; } diff --git a/utils.c b/utils.c index a77c946..d37e003 100755 --- a/utils.c +++ b/utils.c @@ -126,7 +126,7 @@ int GetModulePath(char *Buffer, int BufferLength) return strlen(Buffer); #else -#warning Implement this + return -1; #endif }