Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

cpmthread.c

Go to the documentation of this file.
00001 #include "cpmthread.h"
00002 
00003 // Threads
00004 pmthread pmthread_new(void *(*thread)(void *args), void *args)
00005 {
00006         pmthread id;
00007         int ret = pthread_create(&id, NULL, thread, args);
00008 
00009         return ret ? PMTHREAD_ERROR : id;
00010 }
00011 
00012 int pmthread_destroy(pmthread threadID)
00013 {
00014         int ret = pthread_cancel(threadID);
00015 
00016         return ret ? PMTHREAD_ERROR : 0;
00017 }
00018 
00019 int pmthread_wait(pmthread threadID)
00020 {
00021         int ret = pthread_join(threadID, NULL);
00022         ret |= pthread_detach(threadID);
00023 
00024         return ret ? PMTHREAD_ERROR : 0;
00025 }
00026 
00027 // Mutexs
00028 pmmutex pmmutex_new()
00029 {
00030         pmmutex mutex;
00031         pthread_mutex_init(&mutex, NULL);
00032 
00033         return mutex;
00034 }
00035 
00036 int pmmutex_destroy(pmmutex *mutex)
00037 {
00038         int ret = pthread_mutex_destroy(mutex);
00039 
00040         return ret ? PMTHREAD_ERROR : 0;
00041 }
00042 
00043 int pmmutex_lock(pmmutex *mutex)
00044 {
00045         int ret = pthread_mutex_lock(mutex);
00046 
00047         return ret ? PMTHREAD_ERROR : 0;
00048 }
00049 
00050 int pmmutex_unlock(pmmutex *mutex)
00051 {
00052         int ret = pthread_mutex_unlock(mutex);
00053 
00054         return ret ? PMTHREAD_ERROR : 0;
00055 }
00056 
00057 // Conditional variables
00058 pmcond pmcond_new()
00059 {
00060         pmcond cond;
00061         pthread_cond_init(&cond, NULL);
00062 
00063         return cond;
00064 }
00065 
00066 int pmcond_destroy(pmcond *cond)
00067 {
00068         int ret = pthread_cond_destroy(cond);
00069 
00070         return ret ? PMTHREAD_ERROR : 0;
00071 }
00072 
00073 int pmcond_wait(pmcond *cond, pmmutex *mutex)
00074 {
00075         int ret = pthread_cond_wait(cond, mutex);
00076 
00077         return ret ? PMTHREAD_ERROR : 0;
00078 }
00079 
00080 int pmcond_signal(pmcond *cond)
00081 {
00082         int ret = pthread_cond_signal(cond);
00083 
00084         return ret ? PMTHREAD_ERROR : 0;
00085 }
00086 
00087 int pmcond_broadcast(pmcond *cond)
00088 {
00089         int ret = pthread_cond_broadcast(cond);
00090 
00091         return ret ? PMTHREAD_ERROR : 0;
00092 }
00093 

Generated on Mon Dec 1 17:00:22 2003 for Protomake by doxygen1.3