00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "ThreadUtil.h"
00034 #include "mace-macros.h"
00035
00036 void ThreadUtil::create(pthread_t& t, const pthread_attr_t& attr,
00037 void *(*start_routine)(void*), void* arg) {
00038 ADD_SELECTORS("ThreadUtil::create");
00039 traceout << Log::end;
00040 int r = pthread_create(&t, &attr, start_routine, arg);
00041 if (r != 0) {
00042 Log::perror("pthread_create");
00043 assert(0);
00044 }
00045 }
00046
00047 void ThreadUtil::lock(pthread_mutex_t& mutex) {
00048 ADD_SELECTORS("ThreadUtil::lock");
00049 traceout << Log::end;
00050 int r = pthread_mutex_lock(&mutex);
00051 if (r != 0) {
00052 Log::perror("pthread_mutex_lock");
00053 assert(0);
00054 }
00055 }
00056
00057 void ThreadUtil::unlock(pthread_mutex_t& mutex) {
00058 ADD_SELECTORS("ThreadUtil::unlock");
00059 traceout << Log::end;
00060 int r = pthread_mutex_unlock(&mutex);
00061 if (r != 0) {
00062 Log::perror("pthread_mutex_unlock");
00063 assert(0);
00064 }
00065 }
00066
00067 void ThreadUtil::wait(pthread_cond_t& signal, pthread_mutex_t& mutex) {
00068 ADD_SELECTORS("ThreadUtil::wait");
00069 traceout << Log::end;
00070 int r = pthread_cond_wait(&signal, &mutex);
00071 if (r != 0) {
00072 Log::perror("pthread_cond_wait");
00073 assert(0);
00074 }
00075 }
00076
00077 void ThreadUtil::signal(pthread_cond_t& sig) {
00078 ADD_SELECTORS("ThreadUtil::signal");
00079 traceout << Log::end;
00080 int r = pthread_cond_signal(&sig);
00081 if (r != 0) {
00082 Log::perror("pthread_cond_signal");
00083 assert(0);
00084 }
00085 }
00086
00087 void ThreadUtil::broadcast(pthread_cond_t& sig) {
00088 ADD_SELECTORS("ThreadUtil::broadcast");
00089 traceout << Log::end;
00090 int r = pthread_cond_broadcast(&sig);
00091 if (r != 0) {
00092 Log::perror("pthread_cond_broadcast");
00093 assert(0);
00094 }
00095 }
00096