GCS  0.2.3
gu_lock_step.h
1 /*
2  * Copyright (C) 2009 Codership Oy <info@codership.com>
3  *
4  * $Id: gu_lock_step.h 3515 2014-03-26 16:10:56Z yan $
5  */
6 
7 // This is a small class to facilitate lock-stepping in multithreaded unit tests
8 
9 #ifndef _gu_lock_step_h_
10 #define _gu_lock_step_h_
11 
12 #include <stdbool.h>
13 
14 #include "gu_mutex.h"
15 
16 typedef struct gu_lock_step
17 {
18  gu_mutex_t mtx;
19  gu_cond_t cond;
20  long wait;
21  long cont;
22  bool enabled;
23 }
25 
26 extern void
27 gu_lock_step_init (gu_lock_step_t* ls);
28 
29 /* enable or disable lock-stepping */
30 extern void
31 gu_lock_step_enable (gu_lock_step_t* ls, bool enable);
32 
33 extern void
34 gu_lock_step_wait (gu_lock_step_t* ls);
35 
36 /* returns how many waiters there were,
37  * waits for timeout_ms milliseconds if no waiters, if timeout_ms < 0 waits forever,
38  * if 0 - no wait at all */
39 extern long
40 gu_lock_step_cont (gu_lock_step_t* ls, long timeout_ms);
41 
42 extern void
43 gu_lock_step_destroy (gu_lock_step_t* ls);
44 
45 #endif /* _gu_lock_step_h_ */
Definition: gu_lock_step.h:16