40860b1f774a506d9a3e40a126fad14a2daeb9b1
[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         ret = pthread_mutex_initp(mutex, attr);
51
52         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, 
53                         SYNC_API_OTHER, "%p,%p", mutex, attr);
54
55         AFTER_PACK_ORIGINAL_SYNC(ret, mutex, SYNC_PTHREAD_MUTEX, 
56                         SYNC_API_OTHER, "pp", mutex, attr);
57
58         return ret;
59 }
60
61 int pthread_mutex_destroy(pthread_mutex_t *mutex) {
62         static int (*pthread_mutex_destroyp)(pthread_mutex_t *mutex);
63
64         BEFORE_ORIGINAL_SYNC(pthread_mutex_destroy, LIBPTHREAD);
65
66         ret = pthread_mutex_destroyp(mutex);
67
68         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, 
69                         SYNC_API_OTHER, "%p", mutex);
70
71         AFTER_PACK_ORIGINAL_SYNC(ret, mutex, SYNC_PTHREAD_MUTEX, 
72                         SYNC_API_OTHER, "p", mutex);
73
74         return ret;
75 }
76
77 int real_pthread_mutex_lock(pthread_mutex_t *mutex) {
78         static int (*pthread_mutex_lockp)(pthread_mutex_t *mutex);
79
80         GET_REAL_FUNC(pthread_mutex_lock, LIBPTHREAD);
81
82         return pthread_mutex_lockp(mutex);
83 }
84
85 int pthread_mutex_lock(pthread_mutex_t *mutex) {
86         static int (*pthread_mutex_lockp)(pthread_mutex_t *mutex);
87         
88         DECLARE_VARIABLE_STANDARD; log_t log;
89         GET_REAL_FUNC(pthread_mutex_lock, LIBPTHREAD);
90
91         PRE_PROBEBLOCK_BEGIN();
92         // send WAIT_START log
93         INIT_LOG;
94         APPEND_LOG_BASIC(LC_SYNC);
95         APPEND_LOG_INPUT("%p", mutex);
96         //ret,PCAddr,errno,InternalCall
97         log.length += sprintf(log.data + log.length, "`,`,0`,0`,%d", blockresult);
98         APPEND_LOG_CALLER();
99         log.length += sprintf(log.data + log.length, "`,%p`,%d`,%d", mutex,
100                         SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_START);
101         APPEND_LOG_NULL_CALLSTACK();
102         printLog(&log, MSG_LOG);
103
104         PREPARE_LOCAL_BUF();
105         PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "p", mutex);
106         PACK_COMMON_END(0, 0, blockresult);
107         PACK_SYNC(mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_START);
108         FLUSH_LOCAL_BUF();
109
110         PRE_PROBEBLOCK_END();
111
112         ret = pthread_mutex_lockp(mutex);
113
114         // send WAIT_END log
115         newerrno = errno;
116         if(postBlockBegin(blockresult)) {
117                 setProbePoint(&probeInfo);
118                 INIT_LOG;
119                 APPEND_LOG_BASIC(LC_SYNC);
120                 APPEND_LOG_INPUT("%p", mutex);
121                 APPEND_LOG_RESULT(VT_INT, ret);
122                 APPEND_LOG_CALLER();
123
124                 POST_PROBEBLOCK_MIDDLE_SYNCVAL(mutex, SYNC_PTHREAD_MUTEX, 
125                                 SYNC_API_ACQUIRE_WAIT_END);
126                 POST_PROBEBLOCK_CALLSTACK();
127                 printLog(&log, MSG_LOG);
128
129                 PREPARE_LOCAL_BUF();
130                 PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "p", mutex);
131                 PACK_COMMON_END(ret, errno, blockresult);
132                 PACK_SYNC(mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_END);
133                 FLUSH_LOCAL_BUF();
134
135                 postBlockEnd();
136         }
137
138         return ret;
139 }
140
141 int pthread_mutex_timedlock(pthread_mutex_t *mutex,
142                 const struct timespec *abs_timeout) {
143         static int (*pthread_mutex_timedlockp)(pthread_mutex_t *mutex,
144                         const struct timespec *abs_timeout);
145
146         DECLARE_VARIABLE_STANDARD; log_t log;
147         GET_REAL_FUNC(pthread_mutex_timedlock, LIBPTHREAD);
148
149         PRE_PROBEBLOCK_BEGIN();
150         // send WAIT_START log
151         INIT_LOG;
152         APPEND_LOG_BASIC(LC_SYNC);
153         APPEND_LOG_INPUT("%p,%p", mutex, abs_timeout);
154         //ret,PCAddr,errno,InternalCall
155         log.length += sprintf(log.data + log.length, "`,`,0`,0`,%d", blockresult);
156         APPEND_LOG_CALLER();
157         log.length += sprintf(log.data + log.length, "`,%p`,%d`,%d", mutex,
158                         SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_START);
159         APPEND_LOG_NULL_CALLSTACK();
160         printLog(&log, MSG_LOG);
161
162         PREPARE_LOCAL_BUF();
163         PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "pp", mutex, abs_timeout);
164         PACK_COMMON_END(0, 0, blockresult);
165         PACK_SYNC(mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_START);
166         FLUSH_LOCAL_BUF();
167
168         PRE_PROBEBLOCK_END();
169
170         ret = pthread_mutex_timedlockp(mutex, abs_timeout);
171
172         // send WAIT_END log
173         newerrno = errno;
174         if(postBlockBegin(blockresult)) {
175                 setProbePoint(&probeInfo);
176                 INIT_LOG;
177                 APPEND_LOG_BASIC(LC_SYNC);
178                 APPEND_LOG_INPUT("%p,%p", mutex, abs_timeout);
179                 APPEND_LOG_RESULT(VT_INT, ret);
180                 APPEND_LOG_CALLER();
181
182                 POST_PROBEBLOCK_MIDDLE_SYNCVAL(mutex, SYNC_PTHREAD_MUTEX, 
183                                 SYNC_API_ACQUIRE_WAIT_END);
184                 POST_PROBEBLOCK_CALLSTACK();
185                 printLog(&log, MSG_LOG);
186
187                 PREPARE_LOCAL_BUF();
188                 PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "pp", mutex, abs_timeout);
189                 PACK_COMMON_END(ret, errno, blockresult);
190                 PACK_SYNC(mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_END);
191                 FLUSH_LOCAL_BUF();
192
193                 postBlockEnd();
194         }
195         
196         return ret;
197 }
198
199 int pthread_mutex_trylock(pthread_mutex_t *mutex) {
200         static int (*pthread_mutex_trylockp)(pthread_mutex_t *mutex);
201
202         BEFORE_ORIGINAL_SYNC(pthread_mutex_trylock, LIBPTHREAD);
203
204         ret = pthread_mutex_trylockp(mutex);
205
206         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, 
207                         SYNC_API_TRY_ACQUIRE, "%p", mutex);
208
209         AFTER_PACK_ORIGINAL_SYNC(ret, mutex, SYNC_PTHREAD_MUTEX, 
210                         SYNC_API_TRY_ACQUIRE, "p", mutex);
211         
212         return ret;
213 }
214
215 int real_pthread_mutex_unlock(pthread_mutex_t *mutex) {
216         static int (*pthread_mutex_unlockp)(pthread_mutex_t *mutex);
217
218         GET_REAL_FUNC(pthread_mutex_unlock, LIBPTHREAD);
219
220         return pthread_mutex_unlockp(mutex);
221 }
222
223 int pthread_mutex_unlock(pthread_mutex_t *mutex) {
224         static int (*pthread_mutex_unlockp)(pthread_mutex_t *mutex);
225
226         BEFORE_ORIGINAL_SYNC(pthread_mutex_unlock, LIBPTHREAD);
227
228         ret = pthread_mutex_unlockp(mutex);
229
230         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, 
231                         SYNC_API_RELEASE, "%p", mutex);
232
233         AFTER_PACK_ORIGINAL_SYNC(ret, mutex, SYNC_PTHREAD_MUTEX, 
234                         SYNC_API_RELEASE, "p", mutex);
235         
236         return ret;
237 }
238
239 int pthread_mutexattr_init(pthread_mutexattr_t *attr) {
240         static int (*pthread_mutexattr_initp)(pthread_mutexattr_t *attr);
241
242         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_init, LIBPTHREAD);
243
244         ret = pthread_mutexattr_initp(attr);
245
246         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
247                         SYNC_API_OTHER, "%p", attr);
248
249         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
250                         SYNC_API_OTHER, "p", attr);
251
252         return ret;
253 }
254
255 int pthread_mutexattr_destroy(pthread_mutexattr_t *attr) {
256         static int (*pthread_mutexattr_destroyp)(pthread_mutexattr_t *attr);
257
258         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_destroy, LIBPTHREAD);
259
260         ret = pthread_mutexattr_destroyp(attr);
261
262         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
263                         SYNC_API_OTHER, "%p", attr);
264
265         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
266                         SYNC_API_OTHER, "p", attr);
267
268         return ret;
269 }
270
271 int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr,
272                 int *prioceiling) {
273         static int (*pthread_mutexattr_getprioceilingp)(
274                         const pthread_mutexattr_t *attr, int *prioceiling);
275
276         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_getprioceiling, LIBPTHREAD);
277
278         ret = pthread_mutexattr_getprioceilingp(attr, prioceiling);
279
280         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
281                         SYNC_API_OTHER, "%p,%p", attr, prioceiling);
282
283         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
284                         SYNC_API_OTHER, "pp", attr, prioceiling);
285
286         return ret;
287 }
288
289 int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, 
290                 int prioceiling) {
291         static int (*pthread_mutexattr_setprioceilingp)(
292                         pthread_mutexattr_t *attr, int prioceiling);
293
294         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_setprioceiling, LIBPTHREAD);
295
296         ret = pthread_mutexattr_setprioceilingp(attr, prioceiling);
297
298         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
299                         SYNC_API_OTHER, "%p,%d", attr, prioceiling);
300
301         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
302                         SYNC_API_OTHER, "pd", attr, prioceiling);
303
304         return ret;
305 }
306
307 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, 
308                 int *protocol) {
309         static int (*pthread_mutexattr_getprotocolp)(
310                         const pthread_mutexattr_t *attr, int *protocol);
311
312         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_getprotocol, LIBPTHREAD);
313
314         ret = pthread_mutexattr_getprotocolp(attr, protocol);
315
316         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
317                         SYNC_API_OTHER, "%p,%p", attr, protocol);
318
319         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
320                         SYNC_API_OTHER, "pp", attr, protocol);
321
322         return ret;
323 }
324
325 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, 
326                 int protocol) {
327         static int (*pthread_mutexattr_setprotocolp)(
328                         pthread_mutexattr_t *attr, int protocol);
329
330         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_setprotocol, LIBPTHREAD);
331
332         ret = pthread_mutexattr_setprotocolp(attr, protocol);
333
334         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
335                         SYNC_API_OTHER, "%p,%d", attr, protocol);
336
337         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
338                         SYNC_API_OTHER, "pd", attr, protocol);
339
340         return ret;
341 }
342
343 int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, 
344                 int *pshared) {
345         static int (*pthread_mutexattr_getpsharedp)(
346                         const pthread_mutexattr_t *attr, int *pshared);
347
348         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_getpshared, LIBPTHREAD);
349
350         ret = pthread_mutexattr_getpsharedp(attr, pshared);
351
352         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
353                         SYNC_API_OTHER, "%p,%p", attr, pshared);
354
355         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
356                         SYNC_API_OTHER, "pp", attr, pshared);
357
358         return ret;
359 }
360
361 int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, 
362                 int pshared) {
363         static int (*pthread_mutexattr_setpsharedp)(
364                         pthread_mutexattr_t *attr, int pshared);
365
366         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_setpshared, LIBPTHREAD);
367
368         ret = pthread_mutexattr_setpsharedp(attr, pshared);
369
370         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
371                         SYNC_API_OTHER, "%p,%d", attr, pshared);
372
373         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
374                         SYNC_API_OTHER, "pd", attr, pshared);
375
376         return ret;
377 }
378
379 int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type) {
380         static int (*pthread_mutexattr_gettypep)(
381                         const pthread_mutexattr_t *attr, int *type);
382
383         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_gettype, LIBPTHREAD);
384
385         ret = pthread_mutexattr_gettypep(attr, type);
386
387         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
388                         SYNC_API_OTHER, "%p,%p", attr, type);
389
390         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
391                         SYNC_API_OTHER, "pp", attr, type);
392
393         return ret;
394 }
395
396 int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) {
397         static int (*pthread_mutexattr_settypep)(
398                         pthread_mutexattr_t *attr, int type);
399
400         BEFORE_ORIGINAL_SYNC(pthread_mutexattr_settype, LIBPTHREAD);
401
402         ret = pthread_mutexattr_settypep(attr, type);
403
404         AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX,
405                         SYNC_API_OTHER, "%p,%d", attr, type);
406
407         AFTER_PACK_ORIGINAL_SYNC(ret, 0, SYNC_PTHREAD_MUTEX,
408                         SYNC_API_OTHER, "pd", attr, type);
409
410         return ret;
411 }
412
413 /*
414 int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex,
415                 int *prioceiling);
416 int pthread_mutex_setprioceiling(pthread_mutex_t *mutex,
417                 int prioceiling, int *old_ceiling);
418 */
419
420 int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) {
421         static int (*pthread_cond_initp)(pthread_cond_t *cond,
422                         const pthread_condattr_t *attr);
423
424         BEFORE_ORIGINAL_SYNC(pthread_cond_init, LIBPTHREAD);
425
426         ret = pthread_cond_initp(cond, attr);
427
428         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
429                         SYNC_API_OTHER, "%p,%p", cond, attr);
430
431         AFTER_PACK_ORIGINAL_SYNC(ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
432                         SYNC_API_OTHER, "pp", cond, attr);
433
434         return ret;
435 }
436
437 int pthread_cond_destroy(pthread_cond_t *cond) {
438         static int (*pthread_cond_destroyp)(pthread_cond_t *cond);
439
440         BEFORE_ORIGINAL_SYNC(pthread_cond_destroy, LIBPTHREAD);
441
442         ret = pthread_cond_destroyp(cond);
443
444         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
445                         SYNC_API_OTHER, "%p", cond);
446
447         AFTER_PACK_ORIGINAL_SYNC(ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
448                         SYNC_API_OTHER, "p", cond);
449
450         return ret;
451 }
452
453 int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) {
454         static int (*pthread_cond_waitp)(pthread_cond_t *cond,
455                         pthread_mutex_t *mutex);
456
457         DECLARE_VARIABLE_STANDARD; log_t log;
458         GET_REAL_FUNC(pthread_cond_wait, LIBPTHREAD);
459
460         PRE_PROBEBLOCK_BEGIN();
461         // send WAIT_START log
462         INIT_LOG;
463         APPEND_LOG_BASIC(LC_SYNC);
464         APPEND_LOG_INPUT("%p,%p", cond, mutex);
465         //ret,PCAddr,errno,InternalCall
466         log.length += sprintf(log.data + log.length, "`,`,0`,0`,%d", blockresult);
467         APPEND_LOG_CALLER();
468         log.length += sprintf(log.data + log.length, "`,%p`,%d`,%d", cond,
469                         SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_START);
470         APPEND_LOG_NULL_CALLSTACK();
471         printLog(&log, MSG_LOG);
472
473         PREPARE_LOCAL_BUF();
474         PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "pp", cond, mutex);
475         PACK_COMMON_END(0, 0, blockresult);
476         PACK_SYNC(cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_START);
477         FLUSH_LOCAL_BUF();
478
479         PRE_PROBEBLOCK_END();
480
481         ret = pthread_cond_waitp(cond, mutex);
482
483         // send WAIT_END log
484         newerrno = errno;
485         if(postBlockBegin(blockresult)) {
486                 setProbePoint(&probeInfo);
487                 INIT_LOG;
488                 APPEND_LOG_BASIC(LC_SYNC);
489                 APPEND_LOG_INPUT("%p,%p", cond, mutex);
490                 APPEND_LOG_RESULT(VT_INT, ret);
491                 APPEND_LOG_CALLER();
492
493                 POST_PROBEBLOCK_MIDDLE_SYNCVAL(cond, SYNC_PTHREAD_COND_VARIABLE, 
494                                 SYNC_API_COND_WAIT_END);
495                 POST_PROBEBLOCK_CALLSTACK();
496                 printLog(&log, MSG_LOG);
497
498                 PREPARE_LOCAL_BUF();
499                 PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "pp", cond, mutex);
500                 PACK_COMMON_END(ret, errno, blockresult);
501                 PACK_SYNC(cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_END);
502                 FLUSH_LOCAL_BUF();
503
504                 postBlockEnd();
505         }
506
507         return ret;
508 }
509
510 int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
511                 const struct timespec *abstime) {
512         static int (*pthread_cond_timedwaitp)(pthread_cond_t *cond,
513                                 pthread_mutex_t *mutex, const struct timespec *abstime);
514
515         DECLARE_VARIABLE_STANDARD; log_t log;
516         GET_REAL_FUNC(pthread_cond_timedwait, LIBPTHREAD);
517
518         PRE_PROBEBLOCK_BEGIN();
519         // send WAIT_START log
520         INIT_LOG;
521         APPEND_LOG_BASIC(LC_SYNC);
522         APPEND_LOG_INPUT("%p,%p,%p", cond, mutex, abstime);
523         //ret,PCAddr,errno,InternalCall
524         log.length += sprintf(log.data + log.length, "`,`,0`,0`,%d", blockresult);
525         APPEND_LOG_CALLER();
526         log.length += sprintf(log.data + log.length, "`,%p`,%d`,%d", cond,
527                         SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_START);
528         APPEND_LOG_NULL_CALLSTACK();
529         printLog(&log, MSG_LOG);
530
531         PREPARE_LOCAL_BUF();
532         PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "ppp", cond, mutex, abstime);
533         PACK_COMMON_END(0, 0, blockresult);
534         PACK_SYNC(cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_START);
535         FLUSH_LOCAL_BUF();
536
537         PRE_PROBEBLOCK_END();
538
539         ret = pthread_cond_timedwaitp(cond, mutex, abstime);
540
541         // send WAIT_END log
542         newerrno = errno;
543         if(postBlockBegin(blockresult)) {
544                 setProbePoint(&probeInfo);
545                 INIT_LOG;
546                 APPEND_LOG_BASIC(LC_SYNC);
547                 APPEND_LOG_INPUT("%p,%p,%p", cond, mutex, abstime);
548                 APPEND_LOG_RESULT(VT_INT, ret);
549                 APPEND_LOG_CALLER();
550
551                 POST_PROBEBLOCK_MIDDLE_SYNCVAL(cond, SYNC_PTHREAD_COND_VARIABLE, 
552                                 SYNC_API_COND_WAIT_END);
553                 POST_PROBEBLOCK_CALLSTACK();
554                 printLog(&log, MSG_LOG);
555
556                 PREPARE_LOCAL_BUF();
557                 PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, "ppp", cond, mutex, abstime);
558                 PACK_COMMON_END(ret, errno, blockresult);
559                 PACK_SYNC(cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_END);
560                 FLUSH_LOCAL_BUF();
561
562                 postBlockEnd();
563         }
564
565         return ret;
566 }
567
568 int pthread_cond_signal(pthread_cond_t *cond) {
569         static int (*pthread_cond_signalp)(pthread_cond_t *cond);
570
571         BEFORE_ORIGINAL_SYNC(pthread_cond_signal, LIBPTHREAD);
572
573         ret = pthread_cond_signalp(cond);
574
575         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
576                         SYNC_API_NOTIFY, "%p", cond);
577
578         AFTER_PACK_ORIGINAL_SYNC(ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
579                         SYNC_API_NOTIFY, "p", cond);
580         
581         return ret;
582 }
583
584 int pthread_cond_broadcast(pthread_cond_t *cond) {
585         static int (*pthread_cond_broadcastp)(pthread_cond_t *cond);
586
587         BEFORE_ORIGINAL_SYNC(pthread_cond_broadcast, LIBPTHREAD);
588
589         ret = pthread_cond_broadcastp(cond);
590
591         AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
592                         SYNC_API_NOTIFY_ALL, "%p", cond);
593
594         AFTER_PACK_ORIGINAL_SYNC(ret, cond, SYNC_PTHREAD_COND_VARIABLE, 
595                         SYNC_API_NOTIFY_ALL, "p", cond);
596         
597         return ret;
598 }
599
600 /*
601 int pthread_condattr_init(pthread_condattr_t *attr);
602 int pthread_condattr_destroy(pthread_condattr_t *attr);
603 int pthread_condattr_getclock(const pthread_condattr_t *attr,
604                 clockid_t *clock_id);
605 int pthread_condattr_setclock(pthread_condattr_t *attr,
606                 clockid_t clock_id);
607 int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared);
608 int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
609 */
610
611 /*
612 int pthread_rwlock_init(pthread_rwlock_t *rwlock,
613                 const pthread_rwlockattr_t *attr);
614 int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
615 int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); 
616 int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
617 int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
618                 const struct timespec *abs_timeout);
619 int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
620                 const struct timespec *abs_timeout);
621 int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
622 int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
623 int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
624 int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
625 int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
626 int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr,
627                 int *pshared);
628 int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr,
629                 int pshared);
630
631 int pthread_spin_init(pthread_spinlock_t *lock, int pshared);
632 int pthread_spin_destroy(pthread_spinlock_t *lock);
633 int pthread_spin_lock(pthread_spinlock_t *lock);
634 int pthread_spin_trylock(pthread_spinlock_t *lock);
635 int pthread_spin_unlock(pthread_spinlock_t *lock);
636
637 int pthread_barrier_init(pthread_barrier_t *barrier,
638                 const pthread_barrierattr_t *attr, unsigned int count);
639 int pthread_barrier_destroy(pthread_barrier_t *barrier);
640 int pthread_barrier_wait(pthread_barrier_t *barrier);
641 int pthread_barrierattr_init(pthread_barrierattr_t *attr);
642 int pthread_barrierattr_destroy(pthread_barrierattr_t *attr);
643 int pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, 
644                 int *pshared);
645 int pthread_barrierattr_setpshared(pthread_barrierattr_t, 
646                 int pshared);
647 */
648