24 pthread_mutex_init(&
mutex, NULL);
28 pthread_mutex_destroy(&
mutex);
32 int ret = pthread_mutex_lock(&
mutex);
34 cerr <<
"ERROR: (" << __FILE__ <<
":" << __LINE__ <<
") pthread_mutex_lock(&mutex) returned " << ret << endl;
40 return pthread_mutex_unlock(&
mutex);
49 #if (defined THREAD_NOTES || defined THREAD_MUTEX_NOTES || defined THREAD_COND_NOTES) 51 map<int,pz_pthread_info_t> threads_info;
52 static bool pz_pthread_logging =
false;
53 static unsigned max_sim_threads = 0;
54 static unsigned sim_threads = 0;
59 pz_pthread_logging =
true;
69 pz_pthread_logging =
false;
74 cout <<
"pz_pthread_log_report:" << endl;
76 cout <<
"Max number of simultaneous threads = " << max_sim_threads << endl;
80 #else // THREAD_NOTES || THREAD_MUTEX_NOTES || THREAD_COND_NOTES 86 #endif // THREAD_NOTES || THREAD_MUTEX_NOTES || THREAD_COND_NOTES 92 int pz_pthread_join(pthread_t thread,
void **value_ptr,
const char*
fn,
93 const char* file,
unsigned line)
95 int ret = pthread_join(thread, value_ptr);
97 if (pz_pthread_logging && (ret == 0)) {
102 std::cout << (
int*) thread <<
" -> " 103 << (
int*) pthread_self() <<
"; Join thread at " 104 <<
fn <<
" (" << file <<
":" << line <<
")." 105 <<
" sim_threads = " << sim_threads << std::endl;
114 int pz_pthread_create(pthread_t *thread,
const pthread_attr_t *attr,
void 115 *(*start_routine)(
void *),
void *arg,
const char*
fn,
116 const char* file,
unsigned line)
118 int ret = pthread_create(thread, attr, start_routine, arg);
120 if (pz_pthread_logging && (ret == 0)) {
125 if (sim_threads > max_sim_threads) max_sim_threads = sim_threads;
127 std::cout << (
int*) pthread_self() <<
" - " 128 << (
int*) *thread <<
"; Create thread at " 129 <<
fn <<
" (" << file <<
":" << line <<
")." 130 <<
" sim_threads = " << sim_threads << std::endl;
139 #endif //THREAD_NOTES 142 #ifdef THREAD_MUTEX_NOTES 144 int pz_pthread_mutex_init(pthread_mutex_t*
mutex,
const pthread_mutexattr_t* attr,
145 const char*
fn,
const char* file,
unsigned line)
147 int ret = pthread_mutex_init(
mutex, attr);
149 if (pz_pthread_logging) {
153 std::cout <<
"pthread_mutex_init() ret : " << ret
154 <<
" : self thread " << (
int*) pthread_self() <<
" : at : " 155 <<
fn <<
" : " << file <<
" : " << line << std::endl;
164 int pz_pthread_mutex_destroy(pthread_mutex_t *
mutex,
165 const char*
fn,
const char* file,
unsigned line)
167 int ret = pthread_mutex_destroy(
mutex);
169 if (pz_pthread_logging) {
173 std::cout <<
"pthread_mutex_destroy() ret : " << ret
174 <<
" : self thread " << (
int*) pthread_self() <<
" : at : " 175 <<
fn <<
" : " << file <<
" : " << line << std::endl;
183 int pz_pthread_mutex_lock(pthread_mutex_t *
mutex,
184 const char*
fn,
const char* file,
unsigned line)
186 int ret = pthread_mutex_lock(
mutex);
188 if (pz_pthread_logging) {
192 std::cout <<
"pthread_mutex_lock() ret : " << ret
193 <<
" : self thread " << (
int*) pthread_self() <<
" : at : " 194 <<
fn <<
" : " << file <<
" : " << line << std::endl;
202 int pz_pthread_mutex_unlock(pthread_mutex_t *
mutex,
203 const char*
fn,
const char* file,
unsigned line)
205 int ret = pthread_mutex_unlock(
mutex);
207 if (pz_pthread_logging) {
211 std::cout <<
"pthread_mutex_unlock() ret : " << ret
212 <<
" : self thread " << (
int*) pthread_self() <<
" : at : " 213 <<
fn <<
" : " << file <<
" : " << line << std::endl;
224 #ifdef THREAD_COND_NOTES 226 int pz_pthread_cond_init(pthread_cond_t*
cond,
const pthread_condattr_t* attr,
227 const char*
fn,
const char* file,
unsigned line)
229 int ret = pthread_cond_init(
cond,attr);
231 if (pz_pthread_logging) {
235 std::cout <<
"pthread_cond_init() ret : " << ret
236 <<
" : self thread " << (
int*) pthread_self() <<
" : at : " 237 <<
fn <<
" : " << file <<
" : " << line << std::endl;
245 int pz_pthread_cond_destroy(pthread_cond_t *
cond,
246 const char*
fn,
const char* file,
unsigned line)
248 int ret = pthread_cond_destroy(
cond);
250 if (pz_pthread_logging) {
254 std::cout <<
"pthread_cond_destroy() ret : " << ret
255 <<
" : self thread " << (
int*) pthread_self() <<
" : at : " 256 <<
fn <<
" : " << file <<
" : " << line << std::endl;
264 int pz_pthread_cond_wait(pthread_cond_t*
cond, pthread_mutex_t*
mutex,
265 const char*
fn,
const char* file,
unsigned line)
267 int ret = pthread_cond_wait(
cond,
mutex);
269 if (pz_pthread_logging) {
273 std::cout <<
"pthread_cond_wait() ret : " << ret
274 <<
" : self thread " << (
int*) pthread_self() <<
" : at : " 275 <<
fn <<
" : " << file <<
" : " << line << std::endl;
283 int pz_pthread_cond_broadcast(pthread_cond_t *
cond,
284 const char*
fn,
const char* file,
unsigned line)
286 int ret = pthread_cond_broadcast(
cond);
288 if (pz_pthread_logging) {
292 std::cout <<
"pthread_cond_broadcast() ret : " << ret
293 <<
" : self thread " << (
int*) pthread_self() <<
" : at : " 294 <<
fn <<
" : " << file <<
" : " << line << std::endl;
302 int pz_pthread_cond_signal(pthread_cond_t *
cond,
303 const char*
fn,
const char* file,
unsigned line)
305 int ret = pthread_cond_signal(
cond);
307 if (pz_pthread_logging) {
311 std::cout <<
"pthread_cond_signal() ret : " << ret
312 <<
" : self thread " << (
int*) pthread_self() <<
" : at : " 313 <<
fn <<
" : " << file <<
" : " << line << std::endl;
321 #endif //THREAD_COND_NOTES pthread_mutex_t mutex
Semaphore which controls multiple threads.
void pz_pthread_log_stop()
void pz_pthread_log_report(std::ostream &o)
void pz_pthread_log_start()