thread_unix.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00018 #include "config.h"
00019 #include "wintypes.h"
00020 #include "thread_generic.h"
00021 #include "misc.h"
00022
00023 INTERNAL int SYS_MutexInit(PCSCLITE_MUTEX_T mMutex)
00024 {
00025 if (mMutex)
00026 return pthread_mutex_init(mMutex, NULL);
00027 else
00028 return -1;
00029 }
00030
00031 INTERNAL int SYS_MutexDestroy(PCSCLITE_MUTEX_T mMutex)
00032 {
00033 if (mMutex)
00034 return pthread_mutex_destroy(mMutex);
00035 else
00036 return -1;
00037 }
00038
00039 INTERNAL int SYS_MutexLock(PCSCLITE_MUTEX_T mMutex)
00040 {
00041 if (mMutex)
00042 return pthread_mutex_lock(mMutex);
00043 else
00044 return -1;
00045 }
00046
00047 INTERNAL int SYS_MutexTryLock(PCSCLITE_MUTEX_T mMutex)
00048 {
00049 if (mMutex)
00050 return pthread_mutex_trylock(mMutex);
00051 else
00052 return -1;
00053 }
00054
00055 INTERNAL int SYS_MutexUnLock(PCSCLITE_MUTEX_T mMutex)
00056 {
00057 if (mMutex)
00058 return pthread_mutex_unlock(mMutex);
00059 else
00060 return -1;
00061 }
00062
00063 INTERNAL int SYS_ThreadCreate(PCSCLITE_THREAD_T * pthThread, int attributes,
00064 PCSCLITE_THREAD_FUNCTION(pvFunction), LPVOID pvArg)
00065 {
00066 pthread_attr_t attr;
00067 int ret;
00068
00069 ret = pthread_attr_init(&attr);
00070 if (ret)
00071 return ret;
00072
00073 ret = pthread_attr_setdetachstate(&attr,
00074 attributes & THREAD_ATTR_DETACHED ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE);
00075 if (ret)
00076 {
00077 (void)pthread_attr_destroy(&attr);
00078 return ret;
00079 }
00080
00081 ret = pthread_create(pthThread, &attr, pvFunction, pvArg);
00082 if (ret)
00083 return ret;
00084
00085 ret = pthread_attr_destroy(&attr);
00086 return ret;
00087 }
00088
00089 INTERNAL int SYS_ThreadCancel(PCSCLITE_THREAD_T pthThread)
00090 {
00091 return pthread_cancel(pthThread);
00092 }
00093
00094 INTERNAL int SYS_ThreadDetach(PCSCLITE_THREAD_T pthThread)
00095 {
00096 return pthread_detach(pthThread);
00097 }
00098
00099 INTERNAL int SYS_ThreadJoin(PCSCLITE_THREAD_T pthThread, LPVOID* pvRetVal)
00100 {
00101 return pthread_join(pthThread, pvRetVal);
00102 }
00103
00104 INTERNAL int SYS_ThreadExit(LPVOID pvRetVal)
00105 {
00106 pthread_exit(pvRetVal);
00107 return 1;
00108 }
00109
00110 INTERNAL PCSCLITE_THREAD_T SYS_ThreadSelf(void)
00111 {
00112 return pthread_self();
00113 }
00114
00115 INTERNAL int SYS_ThreadEqual(PCSCLITE_THREAD_T *pthThread1, PCSCLITE_THREAD_T *pthThread2)
00116 {
00117 return pthread_equal(*pthThread1, *pthThread2);
00118 }
00119
00120 INTERNAL int SYS_ThreadSetCancelType(int type, int *oldtype)
00121 {
00122 return pthread_setcanceltype(type, oldtype);
00123 }
00124