thread_unix.c

Go to the documentation of this file.
00001 /*
00002  * MUSCLE SmartCard Development ( http://www.linuxnet.com )
00003  *
00004  * Copyright (C) 2000-2004
00005  *  David Corcoran <corcoran@linuxnet.com>
00006  *  Damien Sauveron <damien.sauveron@labri.fr>
00007  *  Ludovic Rousseau <ludovic.rousseau@free.fr>
00008  *
00009  * $Id: thread_unix.c 2750 2008-01-21 10:02:00Z rousseau $
00010  */
00011 
00017 #include "config.h"
00018 #include "wintypes.h"
00019 #include "thread_generic.h"
00020 #include "misc.h"
00021 
00022 #ifndef TRUE
00023 #define TRUE 1
00024 #define FALSE 0
00025 #endif
00026 
00027 INTERNAL int SYS_MutexInit(PCSCLITE_MUTEX_T mMutex)
00028 {
00029     return pthread_mutex_init(mMutex, NULL);
00030 }
00031 
00032 INTERNAL int SYS_MutexDestroy(PCSCLITE_MUTEX_T mMutex)
00033 {
00034     return pthread_mutex_destroy(mMutex);
00035 }
00036 
00037 INTERNAL int SYS_MutexLock(PCSCLITE_MUTEX_T mMutex)
00038 {
00039     return pthread_mutex_lock(mMutex);
00040 }
00041 
00042 INTERNAL int SYS_MutexUnLock(PCSCLITE_MUTEX_T mMutex)
00043 {
00044     return pthread_mutex_unlock(mMutex);
00045 }
00046 
00047 INTERNAL int SYS_ThreadCreate(PCSCLITE_THREAD_T * pthThread, int attributes,
00048     PCSCLITE_THREAD_FUNCTION(pvFunction), LPVOID pvArg)
00049 {
00050     pthread_attr_t attr;
00051     int ret = FALSE;
00052 
00053     if (0 != pthread_attr_init(&attr))
00054         return FALSE;
00055 
00056     if (0 != pthread_attr_setdetachstate(&attr,
00057         attributes & THREAD_ATTR_DETACHED ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE))
00058     {
00059         pthread_attr_destroy(&attr);
00060         return FALSE;
00061     }
00062 
00063     if (0 == pthread_create(pthThread, &attr, pvFunction, pvArg))
00064         ret = TRUE;
00065 
00066     pthread_attr_destroy(&attr);
00067     return ret;
00068 }
00069 
00070 INTERNAL int SYS_ThreadCancel(PCSCLITE_THREAD_T pthThread)
00071 {
00072     if (0 == pthread_cancel(pthThread))
00073         return TRUE;
00074     else
00075         return FALSE;
00076 }
00077 
00078 INTERNAL int SYS_ThreadDetach(PCSCLITE_THREAD_T pthThread)
00079 {
00080     if (0 == pthread_detach(pthThread))
00081         return TRUE;
00082     else
00083         return FALSE;
00084 }
00085 
00086 INTERNAL int SYS_ThreadJoin(PCSCLITE_THREAD_T pthThread, LPVOID* pvRetVal)
00087 {
00088     if (0 == pthread_join(pthThread, pvRetVal))
00089         return TRUE;
00090     else
00091         return FALSE;
00092 }
00093 
00094 INTERNAL int SYS_ThreadExit(LPVOID pvRetVal)
00095 {
00096     pthread_exit(pvRetVal);
00097     return 1;
00098 }
00099 
00100 INTERNAL PCSCLITE_THREAD_T SYS_ThreadSelf(void)
00101 {
00102     return pthread_self();
00103 }
00104 
00105 INTERNAL int SYS_ThreadEqual(PCSCLITE_THREAD_T *pthThread1, PCSCLITE_THREAD_T *pthThread2)
00106 {
00107     return pthread_equal(*pthThread1, *pthThread2);
00108 }
00109 
00110 INTERNAL int SYS_ThreadSetCancelType(int type, int *oldtype)
00111 {
00112     return pthread_setcanceltype(type, oldtype);
00113 }
00114 

Generated on Wed Apr 30 17:11:41 2008 for pcsc-lite by  doxygen 1.5.5