diff options
author | jsorg71 <jsorg71> | 2007-02-03 06:17:24 +0000 |
---|---|---|
committer | jsorg71 <jsorg71> | 2007-02-03 06:17:24 +0000 |
commit | c94344a6f4d9f033a4ae84acfc4bb622f6c945e7 (patch) | |
tree | ee5327af989a970eeb0cd32b737ad96af18b463a | |
parent | 96fd0b8a000f3d1c871bf0276c1ec39fd0885a37 (diff) | |
download | xrdp-proprietary-c94344a6f4d9f033a4ae84acfc4bb622f6c945e7.tar.gz xrdp-proprietary-c94344a6f4d9f033a4ae84acfc4bb622f6c945e7.zip |
work on threads
-rw-r--r-- | common/thread_calls.c | 63 | ||||
-rw-r--r-- | common/thread_calls.h | 12 |
2 files changed, 70 insertions, 5 deletions
diff --git a/common/thread_calls.c b/common/thread_calls.c index 8bd399ad..62bc2be4 100644 --- a/common/thread_calls.c +++ b/common/thread_calls.c @@ -27,12 +27,13 @@ #endif #include "arch.h" #include "thread_calls.h" +#include "os_calls.h" /*****************************************************************************/ /* returns error */ #if defined(_WIN32) int APP_CC -g_thread_create(unsigned long (__stdcall * start_routine)(void*), void* arg) +tc_thread_create(unsigned long (__stdcall * start_routine)(void*), void* arg) { DWORD thread_id; HANDLE thread; @@ -46,7 +47,7 @@ g_thread_create(unsigned long (__stdcall * start_routine)(void*), void* arg) } #else int APP_CC -g_thread_create(void* (* start_routine)(void*), void* arg) +tc_thread_create(void* (* start_routine)(void*), void* arg) { pthread_t thread; int rv; @@ -60,7 +61,7 @@ g_thread_create(void* (* start_routine)(void*), void* arg) /*****************************************************************************/ long APP_CC -g_get_threadid(void) +tc_get_threadid(void) { #if defined(_WIN32) return (long)GetCurrentThreadId(); @@ -68,3 +69,59 @@ g_get_threadid(void) return (long)pthread_self(); #endif } + +/*****************************************************************************/ +long APP_CC +tc_create_mutex(void) +{ +#if defined(_WIN32) + return (long)CreateMutex(0, 0, 0); +#else + pthread_mutex_t* lmutex; + + lmutex = (pthread_mutex_t*)g_malloc(sizeof(pthread_mutex_t), 0); + pthread_mutex_init(lmutex, 0); + return (long)lmutex; +#endif +} + +/*****************************************************************************/ +void APP_CC +tc_delete_mutex(long mutex) +{ +#if defined(_WIN32) + CloseHandle((HANDLE)mutex); +#else + pthread_mutex_t* lmutex; + + lmutex = (pthread_mutex_t*)mutex; + pthread_mutex_destroy(lmutex); + g_free(lmutex); +#endif +} + +/*****************************************************************************/ +int APP_CC +tc_lock_mutex(long mutex) +{ +#if defined(_WIN32) + WaitForSingleObject((HANDLE)mutex, INFINITE); + return 0; +#else + pthread_mutex_lock((pthread_mutex_t*)mutex); + return 0; +#endif +} + +/*****************************************************************************/ +int APP_CC +tc_unlock_mutex(long mutex) +{ +#if defined(_WIN32) + ReleaseMutex((HANDLE)mutex); + return 0; +#else + pthread_mutex_unlock((pthread_mutex_t*)mutex); + return 0; +#endif +} diff --git a/common/thread_calls.h b/common/thread_calls.h index 93debdfe..e1697d36 100644 --- a/common/thread_calls.h +++ b/common/thread_calls.h @@ -24,8 +24,16 @@ #include "arch.h" int APP_CC -g_thread_create(THREAD_RV (THREAD_CC * start_routine)(void*), void* arg); +tc_thread_create(THREAD_RV (THREAD_CC * start_routine)(void*), void* arg); long APP_CC -g_get_threadid(void); +tc_get_threadid(void); +long APP_CC +tc_create_mutex(void); +void APP_CC +tc_delete_mutex(long mutex); +int APP_CC +tc_lock_mutex(long mutex); +int APP_CC +tc_unlock_mutex(long mutex); #endif |