diff options
author | certus certus@31f1291d-b8d6-0310-a050-a5561fc1590b <certus certus@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864> | 2004-06-12 18:23:54 +0000 |
---|---|---|
committer | certus certus@31f1291d-b8d6-0310-a050-a5561fc1590b <certus certus@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864> | 2004-06-12 18:23:54 +0000 |
commit | a0211857cd029fea81aead88cd50c03ff7b1f8d3 (patch) | |
tree | 452e288ed1a36100030ff07e5dae523c0ec04826 /threads.h | |
parent | d3956b71486727dafbe72550f6baec5f4108bf7b (diff) |
BUILD : 1.7.3 (191) BUGS : 91 NOTES : Fixed bug 91 and added new win32 stuff for codemastr
git-svn-id: svn://svn.anope.org/anope/trunk@191 31f1291d-b8d6-0310-a050-a5561fc1590b
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@136 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'threads.h')
-rw-r--r-- | threads.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/threads.h b/threads.h new file mode 100644 index 000000000..b78e6a106 --- /dev/null +++ b/threads.h @@ -0,0 +1,65 @@ +/* + * + * (C) 2004 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for furhter details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + +#ifndef THREADS_H +#define THREADS_H + +#ifdef _WIN32 +typedef long ano_thread_t; +typedef HANDLE ano_mutex_t; +typedef HANDLE ano_cond_t; +typedef unsigned (__stdcall *ano_thread_start) (void *); +typedef struct +{ + ano_thread_start func; + void *arg; +} ano_cleanup_t; + +extern ano_thread_start __declspec(thread) cleanup_func; + +#define ano_thread_create(thread,start,arg) !_beginthreadex(NULL, 0, (ano_thread_start)start, arg, 0, &thread) +#define ano_thread_self() GetCurrentThreadId() +#define ano_thread_detach(thread) 0 +#define ano_mutex_lock(mutex) WaitForSingleObject(mutex, INFINITE) +#define ano_mutex_unlock(mutex) ReleaseMutex(mutex) + +/* ano_cond_wait is in compat.c */ +#define ano_cond_signal(cond) SetEvent(cond) + +/* very minimalistic implementation */ +#define ano_cleanup_push(func, arg) cleanup_func = (ano_thread_start)func +#define ano_cleanup_pop(execute) cleanup_func(NULL) +#else +typedef pthread_t ano_thread_t; +typedef ano_mutex_t pthread_mutex_t; +typedef ano_cond_t pthread_cond_t; +typedef void *(*ano_thread_start) (void *); + +#define ano_thread_create(thread,start,arg) pthread_create(&thread, NULL, (void *)start, arg) +#define ano_thread_self() pthread_self() +#define ano_thread_detach(thread) pthread_detach(thread) + +#define ano_mutex_lock(mutex) pthread_mutex_lock(&mutex) +#define ano_mutex_unlock(mutex) pthread_mutex_unlock(&mutex) + +#define ano_cond_wait(cond, mutex) pthread_cond_wait(&cond, &mutex) +#define ano_cond_signal(cond) pthread_cond_signal(&cond) + +#define ano_cleanup_push(func, arg) pthread_cleanup_push(func, arg) +#define ano_cleanup_pop(execute) pthread_cleanup_pop(execute) + +#define ano_thread_cancel(thread) pthread_cancel(thread) + +#endif + +#endif |