00001 #ifndef _WIN32 00002 00003 #include <pthread.h> 00004 #include "code.h" 00005 00006 void* naNewLock() 00007 { 00008 pthread_mutex_t* lock = naAlloc(sizeof(pthread_mutex_t)); 00009 pthread_mutex_init(lock, 0); 00010 return lock; 00011 } 00012 00013 void naFreeLock(void* lock) 00014 { 00015 pthread_mutex_destroy(lock); 00016 naFree(lock); 00017 } 00018 00019 void naLock(void* lock) 00020 { 00021 pthread_mutex_lock((pthread_mutex_t*)lock); 00022 } 00023 00024 void naUnlock(void* lock) 00025 { 00026 pthread_mutex_unlock((pthread_mutex_t*)lock); 00027 } 00028 00029 struct naSem { 00030 pthread_mutex_t lock; 00031 pthread_cond_t cvar; 00032 int count; 00033 }; 00034 00035 void* naNewSem() 00036 { 00037 struct naSem* sem = naAlloc(sizeof(struct naSem)); 00038 pthread_mutex_init(&sem->lock , 0); 00039 pthread_cond_init(&sem->cvar, 0); 00040 sem->count = 0; 00041 return sem; 00042 } 00043 00044 void naFreeSem(void* p) 00045 { 00046 struct naSem* sem = p; 00047 pthread_mutex_destroy(&sem->lock); 00048 pthread_cond_destroy(&sem->cvar); 00049 naFree(sem); 00050 } 00051 00052 void naSemDown(void* sh) 00053 { 00054 struct naSem* sem = (struct naSem*)sh; 00055 pthread_mutex_lock(&sem->lock); 00056 while(sem->count <= 0) 00057 pthread_cond_wait(&sem->cvar, &sem->lock); 00058 sem->count--; 00059 pthread_mutex_unlock(&sem->lock); 00060 } 00061 00062 void naSemUp(void* sh, int count) 00063 { 00064 struct naSem* sem = (struct naSem*)sh; 00065 pthread_mutex_lock(&sem->lock); 00066 sem->count += count; 00067 pthread_cond_broadcast(&sem->cvar); 00068 pthread_mutex_unlock(&sem->lock); 00069 } 00070 00071 #endif 00072 00073 extern int GccWarningWorkaround_IsoCForbidsAnEmptySourceFile;