Skip to content

Commit

Permalink
Use NULL_RWLOCK and NULL_THREAD for different platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
lifenjoiner committed Sep 25, 2022
1 parent 98a7122 commit b4b3dab
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion dnscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dynamichosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion ipmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions mmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions rwlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
#else /* WIN64 */
typedef CRITICAL_SECTION RWLock;
#endif /* WIN64 */
#define NULL_RWLOCK {NULL}
#else /* WIN32 */

#ifdef HAVE_PTHREAD_RWLOCK_INIT
typedef pthread_rwlock_t RWLock;
#else /* HAVE_PTHREAD_RWLOCK_INIT */
typedef pthread_mutex_t RWLock;
#endif /* HAVE_PTHREAD_RWLOCK_INIT */
#define NULL_RWLOCK {0}

#endif /* WIN32 */

Expand Down
2 changes: 1 addition & 1 deletion tcpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions udpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ int GetModulePath(char *Buffer, int BufferLength)

return strlen(Buffer);
#else
#warning Implement this
return -1;
#endif
}

Expand Down

0 comments on commit b4b3dab

Please sign in to comment.