mirror of
https://github.com/pissnet/pissircd.git
synced 2025-08-05 09:45:23 +01:00
Changed the thread API to fix some win32 crashes
This commit is contained in:
parent
1a64c71e7f
commit
5d31e2ac68
4 changed files with 12 additions and 9 deletions
1
Changes
1
Changes
|
@ -1703,3 +1703,4 @@ seen. gmtime warning still there
|
|||
- Fixed an oper count bug with SVS2MODE reported by confused (#0000490)
|
||||
- Removed m_kline.c and m_zline.c these are now implimented as part of m_tkl.c
|
||||
- Implemented a patch by poisoner to log vhosts in connect/disconnect logging (#0000487)
|
||||
- Made some changes to the thread API to fix some win32 crashes
|
||||
|
|
|
@ -35,13 +35,15 @@
|
|||
#include <pthread.h>
|
||||
typedef pthread_t THREAD;
|
||||
typedef pthread_mutex_t MUTEX;
|
||||
#define IRCCreateThread(thread, start, arg) TDebug(CreateThread); pthread_create(&thread, NULL, (void*)start, arg)
|
||||
#define IRCCreateThreadEx(thread, start, arg) TDebug(CreateThread); pthread_create(&thread, NULL, (void*)start, arg)
|
||||
#define IRCCreateThread(thread, start, arg) TDebug(CreateThread); pthread_create(&thread, NULL, (void*)start, arg)
|
||||
#define IRCMutexLock(mutex) TDebug(MutexLock); pthread_mutex_lock(&mutex)
|
||||
#define IRCMutexTryLock(mutex) TDebug(MutexTryLock); pthread_mutex_trylock(&mutex);
|
||||
#define IRCMutexUnlock(mutex) TDebug(MutexUnlcok); pthread_mutex_unlock(&mutex)
|
||||
#define IRCCreateMutex(mutex) TDebug(CreateMutex); pthread_mutex_init(&mutex, NULL)
|
||||
#define IRCMutexDestroy(mutex) TDebug(MutexDestroy); pthread_mutex_destroy(&mutex)
|
||||
#define IRCJoinThread(thread,return) TDebug(JoinThread); pthread_join(thread, return)
|
||||
#define IRCExitThreadEx(value) TDebug(ExitThread); pthread_exit(value)
|
||||
#define IRCExitThread(value) TDebug(ExitThread); pthread_exit(value)
|
||||
#define IRCDetachThread(value) TDebug(DetachThread); pthread_detach(value);
|
||||
#define IRCTerminateThread(thread, value) pthread_cancel(&thread)
|
||||
|
@ -50,13 +52,15 @@ typedef pthread_mutex_t MUTEX;
|
|||
#else
|
||||
typedef unsigned long THREAD;
|
||||
typedef HANDLE MUTEX;
|
||||
#define IRCCreateThreadEx(thread, start, arg) _beginthreadex(NULL, 0, (void *)start, arg, 0, &thread)
|
||||
#define IRCCreateThread(thread, start, arg) thread = _beginthread((void *)start, 0, arg)
|
||||
#define IRCMutexLock(mutex) WaitForSingleObject(mutex, INFINITE)
|
||||
#define IRCMutexTryLock(mutex) WaitForSingleObject(mutex, 0)
|
||||
#define IRCMutexUnlock(mutex) ReleaseMutex(mutex)
|
||||
#define IRCCreateMutex(mutex) mutex = CreateMutex(NULL, FALSE, NULL)
|
||||
#define IRCMutexDestroy(mutex) CloseHandle(mutex)
|
||||
#define IRCJoinThread(thread,return) WaitForSingleObject((HANDLE)thread, INFINITE); GetExitCodeThread((HANDLE)thread, (DWORD)return);
|
||||
#define IRCJoinThread(thread,return) { WaitForSingleObject((HANDLE)thread, INFINITE); GetExitCodeThread((HANDLE)thread, (DWORD)return); CloseHandle((HANDLE)thread); }
|
||||
#define IRCExitThreadEx(value) _endthreadex((unsigned int)value)
|
||||
#define IRCExitThread(value) _endthread()
|
||||
#define IRCTerminateThread(thread, value) TerminateThread((HANDLE)thread, value)
|
||||
#define IRCThreadSelf() GetCurrentThread()
|
||||
|
|
|
@ -158,19 +158,19 @@ void scan_http_scan(Scan_AddrStruct *h)
|
|||
p = MyMalloc(sizeof(HSStruct));
|
||||
p->hs = h;
|
||||
p->port = 3128;
|
||||
IRCCreateThread(thread[0], scan_http_scan_port, p);
|
||||
IRCCreateThreadEx(thread[0], scan_http_scan_port, p);
|
||||
/* Then we take 8080 .. */
|
||||
h->refcnt++;
|
||||
p = MyMalloc(sizeof(HSStruct));
|
||||
p->hs = h;
|
||||
p->port = 8080;
|
||||
IRCCreateThread(thread[1], scan_http_scan_port, p);
|
||||
IRCCreateThreadEx(thread[1], scan_http_scan_port, p);
|
||||
/* And then we try to infect them with Code Red .. */
|
||||
h->refcnt++;
|
||||
p = MyMalloc(sizeof(HSStruct));
|
||||
p->hs = h;
|
||||
p->port = 80;
|
||||
IRCCreateThread(thread[2], scan_http_scan_port, p);
|
||||
IRCCreateThreadEx(thread[2], scan_http_scan_port, p);
|
||||
IRCMutexUnlock((h->lock));
|
||||
IRCJoinThread(thread[0], NULL);
|
||||
IRCJoinThread(thread[1], NULL);
|
||||
|
@ -179,7 +179,6 @@ void scan_http_scan(Scan_AddrStruct *h)
|
|||
h->refcnt--;
|
||||
IRCMutexUnlock((h->lock));
|
||||
IRCDetachThread(IRCThreadSelf());
|
||||
IRCExitThread(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -148,9 +148,9 @@ void scan_socks_scan(Scan_AddrStruct *h)
|
|||
THREAD thread[2];
|
||||
IRCMutexLock((h->lock));
|
||||
h->refcnt++;
|
||||
IRCCreateThread(thread[0], scan_socks4_scan, h);
|
||||
IRCCreateThreadEx(thread[0], scan_socks4_scan, h);
|
||||
h->refcnt++;
|
||||
IRCCreateThread(thread[1], scan_socks5_scan, h);
|
||||
IRCCreateThreadEx(thread[1], scan_socks5_scan, h);
|
||||
IRCMutexUnlock((h->lock));
|
||||
IRCJoinThread(thread[0], NULL);
|
||||
IRCJoinThread(thread[1], NULL);
|
||||
|
@ -158,7 +158,6 @@ void scan_socks_scan(Scan_AddrStruct *h)
|
|||
h->refcnt--;
|
||||
IRCMutexUnlock((h->lock));
|
||||
IRCDetachThread(IRCThreadSelf());
|
||||
IRCExitThread(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue