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 2151 2006-09-06 20:02:47Z 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 
00052     if (0 != pthread_attr_init(&attr))
00053         return FALSE;
00054 
00055     if (0 != pthread_attr_setdetachstate(&attr,
00056         attributes & THREAD_ATTR_DETACHED ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE))
00057         return FALSE;
00058 
00059     if (0 == pthread_create(pthThread, &attr, pvFunction, pvArg))
00060         return TRUE;
00061     else
00062         return FALSE;
00063 }
00064 
00065 INTERNAL int SYS_ThreadCancel(PCSCLITE_THREAD_T * pthThread)
00066 {
00067     if (0 == pthread_cancel(*pthThread))
00068         return TRUE;
00069     else
00070         return FALSE;
00071 }
00072 
00073 INTERNAL int SYS_ThreadDetach(PCSCLITE_THREAD_T pthThread)
00074 {
00075     if (0 == pthread_detach(pthThread))
00076         return TRUE;
00077     else
00078         return FALSE;
00079 }
00080 
00081 INTERNAL int SYS_ThreadJoin(PCSCLITE_THREAD_T *pthThread, LPVOID* pvRetVal)
00082 {
00083     if (0 == pthread_join(*pthThread, pvRetVal))
00084         return TRUE;
00085     else
00086         return FALSE;
00087 }
00088 
00089 INTERNAL int SYS_ThreadExit(LPVOID pvRetVal)
00090 {
00091     pthread_exit(pvRetVal);
00092     return 1;
00093 }
00094 
00095 INTERNAL PCSCLITE_THREAD_T SYS_ThreadSelf(void)
00096 {
00097     return pthread_self();
00098 }
00099 
00100 INTERNAL int SYS_ThreadEqual(PCSCLITE_THREAD_T *pthThread1, PCSCLITE_THREAD_T *pthThread2)
00101 {
00102     return pthread_equal(*pthThread1, *pthThread2);
00103 }
00104 

Generated on Tue Aug 14 13:59:18 2007 for pcsc-lite by  doxygen 1.5.2