NeoPZ
pz_pthread.h
Go to the documentation of this file.
1 #ifndef PZ_PTHREAD_H
2 #define PZ_PTHREAD_H
3 
4 #include<pthread.h>
5 #include<iostream> // cout, ostream
6 #include <pz_config.h>
7 
8 //#define THREAD_NOTES
9 //#define THREAD_MUTEX_NOTES
10 //#define THREAD_COND_NOTES
11 
12 #ifdef THREAD_NOTES
13 
14 #pragma message ( "warning: Thread notes are on... (see pz_pthread.h)" )
15 
16 int pz_pthread_create(pthread_t *thread, const pthread_attr_t *attr, void
17  *(*start_routine)(void *), void *arg, const char* fn,
18  const char* file, unsigned line);
19 
20 int pz_pthread_join(pthread_t thread, void **value_ptr,
21  const char* fn, const char* file, unsigned line);
22 
23 #define PZ_PTHREAD_CREATE(thread,attr,routine,args,fn) \
24  pz_pthread_create(thread,attr,routine,args,fn,__FILE__,__LINE__)
25 
26 #define PZ_PTHREAD_JOIN(thread,val,fn) \
27  pz_pthread_join(thread,val,fn,__FILE__,__LINE__)
28 
29 #else
30 
31 #define PZ_PTHREAD_CREATE(thread,attr,routine,args,fn) \
32  pthread_create(thread,attr,routine,args)
33 
34 #define PZ_PTHREAD_JOIN(thread,val,fn) \
35  pthread_join(thread,val)
36 
37 #endif
38 
39 #ifdef THREAD_MUTEX_NOTES
40 
41 #pragma message ( "warning: Thread mutex notes are on... (see pz_pthread.h)" )
42 
43 int pz_pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attr,
44  const char* fn, const char* file, unsigned line);
45 int pz_pthread_mutex_destroy(pthread_mutex_t *mutex,
46  const char* fn, const char* file, unsigned line);
47 int pz_pthread_mutex_lock(pthread_mutex_t *mutex,
48  const char* fn, const char* file, unsigned line);
49 int pz_pthread_mutex_unlock(pthread_mutex_t *mutex,
50  const char* fn, const char* file, unsigned line);
51 // 11 thread_mutex_destroy
52 // 13 thread_mutex_init
53 // 49 thread_mutex_lock
54 // 51 thread_mutex_unlock
55 
56 #define PZ_PTHREAD_MUTEX_INIT(mutex,attr,fn) \
57  pz_pthread_mutex_init(mutex,attr,fn,__FILE__,__LINE__)
58 
59 #define PZ_PTHREAD_MUTEX_DESTROY(mutex,fn) \
60  pz_pthread_mutex_destroy(mutex,fn,__FILE__,__LINE__)
61 
62 #define PZ_PTHREAD_MUTEX_LOCK(mutex,fn) \
63  pz_pthread_mutex_lock(mutex,fn,__FILE__,__LINE__)
64 
65 #define PZ_PTHREAD_MUTEX_UNLOCK(mutex,fn) \
66  pz_pthread_mutex_unlock(mutex,fn,__FILE__,__LINE__)
67 
68 #else
69 
70 #define PZ_PTHREAD_MUTEX_INIT(mutex,attr,fn) \
71  pthread_mutex_init(mutex,attr)
72 
73 #define PZ_PTHREAD_MUTEX_DESTROY(mutex,fn) \
74  pthread_mutex_destroy(mutex)
75 
76 #define PZ_PTHREAD_MUTEX_LOCK(mutex,fn) \
77  pthread_mutex_lock(mutex)
78 
79 #define PZ_PTHREAD_MUTEX_UNLOCK(mutex,fn) \
80  pthread_mutex_unlock(mutex)
81 
82 #endif
83 
84 
85 #ifdef THREAD_COND_NOTES
86 
87 #pragma message ( "warning: Thread cond notes are on... (see pz_pthread.h)" )
88 
89 int pz_pthread_cond_init(pthread_cond_t* cond, const pthread_condattr_t* attr,
90  const char* fn, const char* file, unsigned line);
91 
92 int pz_pthread_cond_destroy(pthread_cond_t *cond,
93  const char* fn, const char* file, unsigned line);
94 
95 int pz_pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex,
96  const char* fn, const char* file, unsigned line);
97 
98 int pz_pthread_cond_broadcast(pthread_cond_t *cond,
99  const char* fn, const char* file, unsigned line);
100 
101 int pz_pthread_cond_signal(pthread_cond_t *cond,
102  const char* fn, const char* file, unsigned line);
103 
104 #define PZ_PTHREAD_COND_INIT(cond,attr,fn) \
105  pz_pthread_cond_init(cond,attr,fn,__FILE__,__LINE__)
106 
107 #define PZ_PTHREAD_COND_DESTROY(cond,fn) \
108  pz_pthread_cond_destroy(cond,fn,__FILE__,__LINE__)
109 
110 #define PZ_PTHREAD_COND_WAIT(cond,mutex,fn) \
111  pz_pthread_cond_wait(cond,mutex,fn,__FILE__,__LINE__)
112 
113 #define PZ_PTHREAD_COND_SIGNAL(cond,fn) \
114  pz_pthread_cond_signal(cond,fn,__FILE__,__LINE__)
115 
116 #define PZ_PTHREAD_COND_BROADCAST(cond,fn) \
117  pz_pthread_cond_broadcast(cond,fn,__FILE__,__LINE__)
118 
119 #else
120 
121 #define PZ_PTHREAD_COND_INIT(cond,attr,fn) \
122  pthread_cond_init(cond,attr)
123 
124 #define PZ_PTHREAD_COND_DESTROY(cond,fn) \
125  pthread_cond_destroy(cond)
126 
127 #define PZ_PTHREAD_COND_WAIT(cond,mutex,fn) \
128  pthread_cond_wait(cond,mutex)
129 
130 #define PZ_PTHREAD_COND_SIGNAL(cond,fn) \
131  pthread_cond_signal(cond)
132 
133 #define PZ_PTHREAD_COND_BROADCAST(cond,fn) \
134  pthread_cond_broadcast(cond)
135 
136 #endif
137 
138 
139 void pz_pthread_log_start();
140 void pz_pthread_log_stop();
141 void pz_pthread_log_report(std::ostream& o);
142 
143 #endif // PZ_PTHREAD_H
pthread_mutex_t mutex
Semaphore which controls multiple threads.
void pz_pthread_log_stop()
Definition: pz_pthread.cpp:82
fn
Definition: test.py:253
void pz_pthread_log_report(std::ostream &o)
Definition: pz_pthread.cpp:84
void pz_pthread_log_start()
Definition: pz_pthread.cpp:83
pthread_cond_t cond
Definition: numatst.cpp:318