add the rest sync probes in libdasync.c
[platform/core/system/swap-probe.git] / probe_thread / libdasync.c
1 /*
2  *  DA probe
3  *
4  * Copyright 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Woojin Jung <woojin2.jung@samsung.com>
9  * Jaewon Lim <jaewon81.lim@samsung.com>
10  * Juyoung Kim <j0.kim@samsung.com>
11  *
12  * This library is free software; you can redistribute it and/or modify it under
13  * the terms of the GNU Lesser General Public License as published by the
14  * Free Software Foundation; either version 2.1 of the License, or (at your option)
15  * any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20  * License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this library; if not, write to the Free Software Foundation, Inc., 51
24  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  *
26  * Contributors:
27  * - S-Core Co., Ltd
28  *
29  */
30
31 #include <pthread.h>
32 #include <time.h>
33 #include <errno.h>
34 #include "daprobe.h"
35 #include "probeinfo.h"
36 #include "dahelper.h"
37 #include "da_sync.h"
38
39 #include "binproto.h"
40
41 static enum DaOptions _sopt = OPT_THREAD;
42
43 int pthread_mutex_init(pthread_mutex_t *mutex, 
44                 const pthread_mutexattr_t *attr) {
45         static int (*pthread_mutex_initp)(pthread_mutex_t *mutex,
46                         const pthread_mutexattr_t *attr);
47
48         BEFORE_ORIGINAL_SYNC(pthread_mutex_init, LIBPTHREAD);
49
50         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutex_init, LIBPTHREAD);
51
52         ret = pthread_mutex_initp(mutex, attr);
53
54         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, 
55                         SYNC_API_OTHER, "%p,%p", mutex, attr);
56
57         AFTER_PACK_ORIGINAL_SYNC(ret, mutex, SYNC_PTHREAD_MUTEX, 
58                         SYNC_API_OTHER, "pp", mutex, attr);
59
60         return ret;
61 }
62
63 int pthread_mutex_destroy(pthread_mutex_t *mutex) {
64         static int (*pthread_mutex_destroyp)(pthread_mutex_t *mutex);
65
66         BEFORE_ORIGINAL_SYNC(pthread_mutex_destroy, LIBPTHREAD);
67
68         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutex_destroy, LIBPTHREAD);
69
70         ret = pthread_mutex_destroyp(mutex);
71
72         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, 
73                         SYNC_API_OTHER, "%p", mutex);
74
75         AFTER_PACK_ORIGINAL_SYNC(ret, mutex, SYNC_PTHREAD_MUTEX, 
76                         SYNC_API_OTHER, "p", mutex);
77
78         return ret;
79 }
80
81 int real_pthread_mutex_lock(pthread_mutex_t *mutex) {
82         static int (*pthread_mutex_lockp)(pthread_mutex_t *mutex);
83
84         GET_REAL_FUNC(pthread_mutex_lock, LIBPTHREAD);
85
86         return pthread_mutex_lockp(mutex);
87 }
88
89 int pthread_mutex_lock(pthread_mutex_t *mutex) {
90         static int (*pthread_mutex_lockp)(pthread_mutex_t *mutex);
91         
92         DECLARE_VARIABLE_STANDARD;
93         GET_REAL_FUNC(pthread_mutex_lock, LIBPTHREAD);
94
95         PRE_PROBEBLOCK_BEGIN();
96         // send WAIT_START log
97         INIT_LOG;
98         APPEND_LOG_BASIC(LC_SYNC);
99         APPEND_LOG_INPUT("%p", mutex);
100         //ret,PCAddr,errno,InternalCall
101         log.length += sprintf(log.data + log.length, "`,`,0`,0`,%d", blockresult);
102         APPEND_LOG_CALLER();
103         log.length += sprintf(log.data + log.length, "`,%p`,%d`,%d", mutex,
104                         SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_START);
105         APPEND_LOG_NULL_CALLSTACK();
106         printLog(&log, MSG_LOG);
107
108         PREPARE_LOCAL_BUF();
109         PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "p", mutex);
110         PACK_COMMON_END(0, 0, blockresult);
111         PACK_SYNC(mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_START);
112         FLUSH_LOCAL_BUF();
113
114         PRE_PROBEBLOCK_END();
115
116         ret = pthread_mutex_lockp(mutex);
117
118         // send WAIT_END log
119         newerrno = errno;
120         if(postBlockBegin(blockresult)) {
121                 setProbePoint(&probeInfo);
122                 INIT_LOG;
123                 APPEND_LOG_BASIC(LC_SYNC);
124                 APPEND_LOG_INPUT("%p", mutex);
125                 APPEND_LOG_RESULT(VT_INT, ret);
126                 APPEND_LOG_CALLER();
127
128                 POST_PROBEBLOCK_MIDDLE_SYNCVAL(mutex, SYNC_PTHREAD_MUTEX, 
129                                 SYNC_API_ACQUIRE_WAIT_END);
130                 POST_PROBEBLOCK_CALLSTACK();
131                 printLog(&log, MSG_LOG);
132
133                 PREPARE_LOCAL_BUF();
134                 PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "p", mutex);
135                 PACK_COMMON_END(ret, errno, blockresult);
136                 PACK_SYNC(mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_END);
137                 FLUSH_LOCAL_BUF();
138
139                 postBlockEnd();
140         }
141
142         return ret;
143 }
144
145 int pthread_mutex_timedlock(pthread_mutex_t *mutex,
146                 const struct timespec *abs_timeout) {
147         static int (*pthread_mutex_timedlockp)(pthread_mutex_t *mutex,
148                         const struct timespec *abs_timeout);
149
150         DECLARE_VARIABLE_STANDARD;
151         GET_REAL_FUNC(pthread_mutex_timedlock, LIBPTHREAD);
152
153         PRE_PROBEBLOCK_BEGIN();
154         // send WAIT_START log
155         INIT_LOG;
156         APPEND_LOG_BASIC(LC_SYNC);
157         APPEND_LOG_INPUT("%p,%p", mutex, abs_timeout);
158         //ret,PCAddr,errno,InternalCall
159         log.length += sprintf(log.data + log.length, "`,`,0`,0`,%d", blockresult);
160         APPEND_LOG_CALLER();
161         log.length += sprintf(log.data + log.length, "`,%p`,%d`,%d", mutex,
162                         SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_START);
163         APPEND_LOG_NULL_CALLSTACK();
164         printLog(&log, MSG_LOG);
165
166         PREPARE_LOCAL_BUF();
167         PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "pp", mutex, abs_timeout);
168         PACK_COMMON_END(0, 0, blockresult);
169         PACK_SYNC(mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_START);
170         FLUSH_LOCAL_BUF();
171
172         PRE_PROBEBLOCK_END();
173
174         ret = pthread_mutex_timedlockp(mutex, abs_timeout);
175
176         // send WAIT_END log
177         newerrno = errno;
178         if(postBlockBegin(blockresult)) {
179                 setProbePoint(&probeInfo);
180                 INIT_LOG;
181                 APPEND_LOG_BASIC(LC_SYNC);
182                 APPEND_LOG_INPUT("%p,%p", mutex, abs_timeout);
183                 APPEND_LOG_RESULT(VT_INT, ret);
184                 APPEND_LOG_CALLER();
185
186                 POST_PROBEBLOCK_MIDDLE_SYNCVAL(mutex, SYNC_PTHREAD_MUTEX, 
187                                 SYNC_API_ACQUIRE_WAIT_END);
188                 POST_PROBEBLOCK_CALLSTACK();
189                 printLog(&log, MSG_LOG);
190
191                 PREPARE_LOCAL_BUF();
192                 PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "pp", mutex, abs_timeout);
193                 PACK_COMMON_END(ret, errno, blockresult);
194                 PACK_SYNC(mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_END);
195                 FLUSH_LOCAL_BUF();
196
197                 postBlockEnd();
198         }
199         
200         return ret;
201 }
202
203 int pthread_mutex_trylock(pthread_mutex_t *mutex) {
204         static int (*pthread_mutex_trylockp)(pthread_mutex_t *mutex);
205
206         BEFORE_ORIGINAL_SYNC(pthread_mutex_trylock, LIBPTHREAD);
207
208         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutex_trylock, LIBPTHREAD);
209
210         ret = pthread_mutex_trylockp(mutex);
211
212         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, 
213                         SYNC_API_TRY_ACQUIRE, "%p", mutex);
214
215         AFTER_PACK_ORIGINAL_SYNC(ret, mutex, SYNC_PTHREAD_MUTEX, 
216                         SYNC_API_TRY_ACQUIRE, "p", mutex);
217         
218         return ret;
219 }
220
221 int real_pthread_mutex_unlock(pthread_mutex_t *mutex) {
222         static int (*pthread_mutex_unlockp)(pthread_mutex_t *mutex);
223
224         GET_REAL_FUNC(pthread_mutex_unlock, LIBPTHREAD);
225
226         return pthread_mutex_unlockp(mutex);
227 }
228
229 int pthread_mutex_unlock(pthread_mutex_t *mutex) {
230         static int (*pthread_mutex_unlockp)(pthread_mutex_t *mutex);
231
232         BEFORE_ORIGINAL_SYNC(pthread_mutex_unlock, LIBPTHREAD);
233
234         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutex_unlock, LIBPTHREAD);
235
236         ret = pthread_mutex_unlockp(mutex);
237
238         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, 
239                         SYNC_API_RELEASE, "%p", mutex);
240
241         AFTER_PACK_ORIGINAL_SYNC(ret, mutex, SYNC_PTHREAD_MUTEX, 
242                         SYNC_API_RELEASE, "p", mutex);
243         
244         return ret;
245 }
246
247 int pthread_mutexattr_init(pthread_mutexattr_t *attr) {
248         static int (*pthread_mutexattr_initp)(pthread_mutexattr_t *attr);
249
250         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_init, LIBPTHREAD);
251
252         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutexattr_init, LIBPTHREAD);
253
254         ret = pthread_mutexattr_initp(attr);
255
256         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
257                         SYNC_API_OTHER, "%p", attr);
258
259         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
260                         SYNC_API_OTHER, "p", attr);
261
262         return ret;
263 }
264
265 int pthread_mutexattr_destroy(pthread_mutexattr_t *attr) {
266         static int (*pthread_mutexattr_destroyp)(pthread_mutexattr_t *attr);
267
268         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_destroy, LIBPTHREAD);
269
270         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutexattr_destroy, LIBPTHREAD);
271
272         ret = pthread_mutexattr_destroyp(attr);
273
274         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
275                         SYNC_API_OTHER, "%p", attr);
276
277         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
278                         SYNC_API_OTHER, "p", attr);
279
280         return ret;
281 }
282
283 int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr,
284                 int *prioceiling) {
285         static int (*pthread_mutexattr_getprioceilingp)(
286                         const pthread_mutexattr_t *attr, int *prioceiling);
287
288         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_getprioceiling, LIBPTHREAD);
289
290         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutexattr_getprioceiling, LIBPTHREAD);
291
292         ret = pthread_mutexattr_getprioceilingp(attr, prioceiling);
293
294         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
295                         SYNC_API_OTHER, "%p,%p", attr, prioceiling);
296
297         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
298                         SYNC_API_OTHER, "pp", attr, prioceiling);
299
300         return ret;
301 }
302
303 int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, 
304                 int prioceiling) {
305         static int (*pthread_mutexattr_setprioceilingp)(
306                         pthread_mutexattr_t *attr, int prioceiling);
307
308         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_setprioceiling, LIBPTHREAD);
309
310         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutexattr_setprioceiling, LIBPTHREAD);
311
312         ret = pthread_mutexattr_setprioceilingp(attr, prioceiling);
313
314         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
315                         SYNC_API_OTHER, "%p,%d", attr, prioceiling);
316
317         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
318                         SYNC_API_OTHER, "pd", attr, prioceiling);
319
320         return ret;
321 }
322
323 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, 
324                 int *protocol) {
325         static int (*pthread_mutexattr_getprotocolp)(
326                         const pthread_mutexattr_t *attr, int *protocol);
327
328         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_getprotocol, LIBPTHREAD);
329
330         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutexattr_getprotocol, LIBPTHREAD);
331
332         ret = pthread_mutexattr_getprotocolp(attr, protocol);
333
334         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
335                         SYNC_API_OTHER, "%p,%p", attr, protocol);
336
337         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
338                         SYNC_API_OTHER, "pp", attr, protocol);
339
340         return ret;
341 }
342
343 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, 
344                 int protocol) {
345         static int (*pthread_mutexattr_setprotocolp)(
346                         pthread_mutexattr_t *attr, int protocol);
347
348         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_setprotocol, LIBPTHREAD);
349
350         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutexattr_setprotocol, LIBPTHREAD);
351
352         ret = pthread_mutexattr_setprotocolp(attr, protocol);
353
354         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
355                         SYNC_API_OTHER, "%p,%d", attr, protocol);
356
357         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
358                         SYNC_API_OTHER, "pd", attr, protocol);
359
360         return ret;
361 }
362
363 int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, 
364                 int *pshared) {
365         static int (*pthread_mutexattr_getpsharedp)(
366                         const pthread_mutexattr_t *attr, int *pshared);
367
368         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_getpshared, LIBPTHREAD);
369
370         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutexattr_getpshared, LIBPTHREAD);
371
372         ret = pthread_mutexattr_getpsharedp(attr, pshared);
373
374         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
375                         SYNC_API_OTHER, "%p,%p", attr, pshared);
376
377         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
378                         SYNC_API_OTHER, "pp", attr, pshared);
379
380         return ret;
381 }
382
383 int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, 
384                 int pshared) {
385         static int (*pthread_mutexattr_setpsharedp)(
386                         pthread_mutexattr_t *attr, int pshared);
387
388         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_setpshared, LIBPTHREAD);
389
390         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutexattr_setpshared, LIBPTHREAD);
391
392         ret = pthread_mutexattr_setpsharedp(attr, pshared);
393
394         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
395                         SYNC_API_OTHER, "%p,%d", attr, pshared);
396
397         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
398                         SYNC_API_OTHER, "pd", attr, pshared);
399
400         return ret;
401 }
402
403 int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type) {
404         static int (*pthread_mutexattr_gettypep)(
405                         const pthread_mutexattr_t *attr, int *type);
406
407         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_gettype, LIBPTHREAD);
408
409         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutexattr_gettype, LIBPTHREAD);
410
411         ret = pthread_mutexattr_gettypep(attr, type);
412
413         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
414                         SYNC_API_OTHER, "%p,%p", attr, type);
415
416         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
417                         SYNC_API_OTHER, "pp", attr, type);
418
419         return ret;
420 }
421
422 int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) {
423         static int (*pthread_mutexattr_settypep)(
424                         pthread_mutexattr_t *attr, int type);
425
426         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_settype, LIBPTHREAD);
427
428         BEFORE_PACK_ORIGINAL_SYNC(pthread_mutexattr_settype, LIBPTHREAD);
429
430         ret = pthread_mutexattr_settypep(attr, type);
431
432         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
433                         SYNC_API_OTHER, "%p,%d", attr, type);
434
435         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
436                         SYNC_API_OTHER, "pd", attr, type);
437
438         return ret;
439 }
440
441 /*
442 int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex,
443                 int *prioceiling);
444 int pthread_mutex_setprioceiling(pthread_mutex_t *mutex,
445                 int prioceiling, int *old_ceiling);
446 */
447
448 int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) {
449         static int (*pthread_cond_initp)(pthread_cond_t *cond,
450                         const pthread_condattr_t *attr);
451
452         BEFORE_ORIGINAL_SYNC(pthread_cond_init, LIBPTHREAD);
453
454         BEFORE_PACK_ORIGINAL_SYNC(pthread_cond_init, LIBPTHREAD);
455
456         ret = pthread_cond_initp(cond, attr);
457
458         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
459                         SYNC_API_OTHER, "%p,%p", cond, attr);
460
461         AFTER_PACK_ORIGINAL_SYNC(ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
462                         SYNC_API_OTHER, "pp", cond, attr);
463
464         return ret;
465 }
466
467 int pthread_cond_destroy(pthread_cond_t *cond) {
468         static int (*pthread_cond_destroyp)(pthread_cond_t *cond);
469
470         BEFORE_ORIGINAL_SYNC(pthread_cond_destroy, LIBPTHREAD);
471
472         BEFORE_PACK_ORIGINAL_SYNC(pthread_cond_destroy, LIBPTHREAD);
473
474         ret = pthread_cond_destroyp(cond);
475
476         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
477                         SYNC_API_OTHER, "%p", cond);
478
479         AFTER_PACK_ORIGINAL_SYNC(ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
480                         SYNC_API_OTHER, "p", cond);
481
482         return ret;
483 }
484
485 int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) {
486         static int (*pthread_cond_waitp)(pthread_cond_t *cond,
487                         pthread_mutex_t *mutex);
488
489         DECLARE_VARIABLE_STANDARD;
490         GET_REAL_FUNC(pthread_cond_wait, LIBPTHREAD);
491
492         PRE_PROBEBLOCK_BEGIN();
493         // send WAIT_START log
494         INIT_LOG;
495         APPEND_LOG_BASIC(LC_SYNC);
496         APPEND_LOG_INPUT("%p,%p", cond, mutex);
497         //ret,PCAddr,errno,InternalCall
498         log.length += sprintf(log.data + log.length, "`,`,0`,0`,%d", blockresult);
499         APPEND_LOG_CALLER();
500         log.length += sprintf(log.data + log.length, "`,%p`,%d`,%d", cond,
501                         SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_START);
502         APPEND_LOG_NULL_CALLSTACK();
503         printLog(&log, MSG_LOG);
504
505         PREPARE_LOCAL_BUF();
506         PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "pp", cond, mutex);
507         PACK_COMMON_END(0, 0, blockresult);
508         PACK_SYNC(cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_START);
509         FLUSH_LOCAL_BUF();
510
511         PRE_PROBEBLOCK_END();
512
513         ret = pthread_cond_waitp(cond, mutex);
514
515         // send WAIT_END log
516         newerrno = errno;
517         if(postBlockBegin(blockresult)) {
518                 setProbePoint(&probeInfo);
519                 INIT_LOG;
520                 APPEND_LOG_BASIC(LC_SYNC);
521                 APPEND_LOG_INPUT("%p,%p", cond, mutex);
522                 APPEND_LOG_RESULT(VT_INT, ret);
523                 APPEND_LOG_CALLER();
524
525                 POST_PROBEBLOCK_MIDDLE_SYNCVAL(cond, SYNC_PTHREAD_COND_VARIABLE, 
526                                 SYNC_API_COND_WAIT_END);
527                 POST_PROBEBLOCK_CALLSTACK();
528                 printLog(&log, MSG_LOG);
529
530                 PREPARE_LOCAL_BUF();
531                 PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "pp", cond, mutex);
532                 PACK_COMMON_END(ret, errno, blockresult);
533                 PACK_SYNC(cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_END);
534                 FLUSH_LOCAL_BUF();
535
536                 postBlockEnd();
537         }
538
539         return ret;
540 }
541
542 int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
543                 const struct timespec *abstime) {
544         static int (*pthread_cond_timedwaitp)(pthread_cond_t *cond,
545                                 pthread_mutex_t *mutex, const struct timespec *abstime);
546
547         DECLARE_VARIABLE_STANDARD;
548         GET_REAL_FUNC(pthread_cond_timedwait, LIBPTHREAD);
549
550         PRE_PROBEBLOCK_BEGIN();
551         // send WAIT_START log
552         INIT_LOG;
553         APPEND_LOG_BASIC(LC_SYNC);
554         APPEND_LOG_INPUT("%p,%p,%p", cond, mutex, abstime);
555         //ret,PCAddr,errno,InternalCall
556         log.length += sprintf(log.data + log.length, "`,`,0`,0`,%d", blockresult);
557         APPEND_LOG_CALLER();
558         log.length += sprintf(log.data + log.length, "`,%p`,%d`,%d", cond,
559                         SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_START);
560         APPEND_LOG_NULL_CALLSTACK();
561         printLog(&log, MSG_LOG);
562
563         PREPARE_LOCAL_BUF();
564         PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "ppp", cond, mutex, abstime);
565         PACK_COMMON_END(0, 0, blockresult);
566         PACK_SYNC(cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_START);
567         FLUSH_LOCAL_BUF();
568
569         PRE_PROBEBLOCK_END();
570
571         ret = pthread_cond_timedwaitp(cond, mutex, abstime);
572
573         // send WAIT_END log
574         newerrno = errno;
575         if(postBlockBegin(blockresult)) {
576                 setProbePoint(&probeInfo);
577                 INIT_LOG;
578                 APPEND_LOG_BASIC(LC_SYNC);
579                 APPEND_LOG_INPUT("%p,%p,%p", cond, mutex, abstime);
580                 APPEND_LOG_RESULT(VT_INT, ret);
581                 APPEND_LOG_CALLER();
582
583                 POST_PROBEBLOCK_MIDDLE_SYNCVAL(cond, SYNC_PTHREAD_COND_VARIABLE, 
584                                 SYNC_API_COND_WAIT_END);
585                 POST_PROBEBLOCK_CALLSTACK();
586                 printLog(&log, MSG_LOG);
587
588                 PREPARE_LOCAL_BUF();
589                 PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "ppp", cond, mutex, abstime);
590                 PACK_COMMON_END(ret, errno, blockresult);
591                 PACK_SYNC(cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_END);
592                 FLUSH_LOCAL_BUF();
593
594                 postBlockEnd();
595         }
596
597         return ret;
598 }
599
600 int pthread_cond_signal(pthread_cond_t *cond) {
601         static int (*pthread_cond_signalp)(pthread_cond_t *cond);
602
603         BEFORE_ORIGINAL_SYNC(pthread_cond_signal, LIBPTHREAD);
604
605         BEFORE_PACK_ORIGINAL_SYNC(pthread_cond_signal, LIBPTHREAD);
606
607         ret = pthread_cond_signalp(cond);
608
609         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
610                         SYNC_API_NOTIFY, "%p", cond);
611
612         AFTER_PACK_ORIGINAL_SYNC(ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
613                         SYNC_API_NOTIFY, "p", cond);
614         
615         return ret;
616 }
617
618 int pthread_cond_broadcast(pthread_cond_t *cond) {
619         static int (*pthread_cond_broadcastp)(pthread_cond_t *cond);
620
621         BEFORE_ORIGINAL_SYNC(pthread_cond_broadcast, LIBPTHREAD);
622
623         BEFORE_PACK_ORIGINAL_SYNC(pthread_cond_broadcast, LIBPTHREAD);
624
625         ret = pthread_cond_broadcastp(cond);
626
627         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
628                         SYNC_API_NOTIFY_ALL, "%p", cond);
629
630         AFTER_PACK_ORIGINAL_SYNC(ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
631                         SYNC_API_NOTIFY_ALL, "p", cond);
632         
633         return ret;
634 }
635
636 /*
637 int pthread_condattr_init(pthread_condattr_t *attr);
638 int pthread_condattr_destroy(pthread_condattr_t *attr);
639 int pthread_condattr_getclock(const pthread_condattr_t *attr,
640                 clockid_t *clock_id);
641 int pthread_condattr_setclock(pthread_condattr_t *attr,
642                 clockid_t clock_id);
643 int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared);
644 int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
645 */
646
647 /*
648 int pthread_rwlock_init(pthread_rwlock_t *rwlock,
649                 const pthread_rwlockattr_t *attr);
650 int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
651 int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); 
652 int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
653 int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
654                 const struct timespec *abs_timeout);
655 int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
656                 const struct timespec *abs_timeout);
657 int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
658 int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
659 int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
660 int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
661 int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
662 int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr,
663                 int *pshared);
664 int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr,
665                 int pshared);
666
667 int pthread_spin_init(pthread_spinlock_t *lock, int pshared);
668 int pthread_spin_destroy(pthread_spinlock_t *lock);
669 int pthread_spin_lock(pthread_spinlock_t *lock);
670 int pthread_spin_trylock(pthread_spinlock_t *lock);
671 int pthread_spin_unlock(pthread_spinlock_t *lock);
672
673 int pthread_barrier_init(pthread_barrier_t *barrier,
674                 const pthread_barrierattr_t *attr, unsigned int count);
675 int pthread_barrier_destroy(pthread_barrier_t *barrier);
676 int pthread_barrier_wait(pthread_barrier_t *barrier);
677 int pthread_barrierattr_init(pthread_barrierattr_t *attr);
678 int pthread_barrierattr_destroy(pthread_barrierattr_t *attr);
679 int pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, 
680                 int *pshared);
681 int pthread_barrierattr_setpshared(pthread_barrierattr_t, 
682                 int pshared);
683 */
684