sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | This file is part of drd, a data race detector. |
| 3 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2008 Bart Van Assche |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 5 | bart.vanassche@gmail.com |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU General Public License as |
| 9 | published by the Free Software Foundation; either version 2 of the |
| 10 | License, or (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, but |
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 20 | 02111-1307, USA. |
| 21 | |
| 22 | The GNU General Public License is contained in the file COPYING. |
| 23 | */ |
| 24 | |
| 25 | |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 26 | #include "drd_clientobj.h" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 27 | #include "drd_cond.h" |
| 28 | #include "drd_error.h" |
| 29 | #include "drd_mutex.h" |
| 30 | #include "drd_suppression.h" |
bart | 46b5fce | 2008-06-28 13:01:30 +0000 | [diff] [blame] | 31 | #include "pub_tool_errormgr.h" /* VG_(maybe_record_error)() */ |
| 32 | #include "pub_tool_libcassert.h" /* tl_assert() */ |
| 33 | #include "pub_tool_libcprint.h" /* VG_(printf)() */ |
| 34 | #include "pub_tool_machine.h" /* VG_(get_IP)() */ |
| 35 | #include "pub_tool_options.h" /* VG_(clo_backtrace_size) */ |
| 36 | #include "pub_tool_threadstate.h" /* VG_(get_running_tid)() */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 37 | |
| 38 | |
bart | 46b5fce | 2008-06-28 13:01:30 +0000 | [diff] [blame] | 39 | /* Local functions. */ |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 40 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 41 | static void DRD_(cond_cleanup)(struct cond_info* p); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 42 | |
| 43 | |
bart | 46b5fce | 2008-06-28 13:01:30 +0000 | [diff] [blame] | 44 | /* Local variables. */ |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 45 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 46 | static Bool DRD_(s_report_signal_unlocked) = True; |
| 47 | static Bool DRD_(s_trace_cond); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 48 | |
| 49 | |
bart | 46b5fce | 2008-06-28 13:01:30 +0000 | [diff] [blame] | 50 | /* Function definitions. */ |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 51 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 52 | void DRD_(cond_set_report_signal_unlocked)(const Bool r) |
bart | 764dea2 | 2009-02-15 13:16:52 +0000 | [diff] [blame] | 53 | { |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 54 | DRD_(s_report_signal_unlocked) = r; |
bart | 764dea2 | 2009-02-15 13:16:52 +0000 | [diff] [blame] | 55 | } |
| 56 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 57 | void DRD_(cond_set_trace)(const Bool trace_cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 58 | { |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 59 | DRD_(s_trace_cond) = trace_cond; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 63 | void DRD_(cond_initialize)(struct cond_info* const p, const Addr cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 64 | { |
| 65 | tl_assert(cond != 0); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 66 | tl_assert(p->a1 == cond); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 67 | tl_assert(p->type == ClientCondvar); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 68 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 69 | p->cleanup = (void(*)(DrdClientobj*))(DRD_(cond_cleanup)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 70 | p->waiter_count = 0; |
| 71 | p->mutex = 0; |
| 72 | } |
| 73 | |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 74 | /** |
| 75 | * Free the memory that was allocated by cond_initialize(). Called by |
| 76 | * DRD_(clientobj_remove)(). |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 77 | */ |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 78 | static void DRD_(cond_cleanup)(struct cond_info* p) |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 79 | { |
| 80 | tl_assert(p); |
| 81 | if (p->mutex) |
| 82 | { |
| 83 | struct mutex_info* q; |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 84 | q = &(DRD_(clientobj_get)(p->mutex, ClientMutex)->mutex); |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 85 | tl_assert(q); |
| 86 | { |
| 87 | CondDestrErrInfo cde = { p->a1, q->a1, q->owner }; |
| 88 | VG_(maybe_record_error)(VG_(get_running_tid)(), |
| 89 | CondDestrErr, |
| 90 | VG_(get_IP)(VG_(get_running_tid)()), |
| 91 | "Destroying condition variable that is being" |
| 92 | " waited upon", |
| 93 | &cde); |
| 94 | } |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 98 | static struct cond_info* DRD_(cond_get_or_allocate)(const Addr cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 99 | { |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 100 | struct cond_info *p; |
| 101 | |
| 102 | tl_assert(offsetof(DrdClientobj, cond) == 0); |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 103 | p = &(DRD_(clientobj_get)(cond, ClientCondvar)->cond); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 104 | if (p == 0) |
sewardj | 721ad7b | 2007-11-30 08:30:29 +0000 | [diff] [blame] | 105 | { |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 106 | p = &(DRD_(clientobj_add)(cond, ClientCondvar)->cond); |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 107 | DRD_(cond_initialize)(p, cond); |
sewardj | 721ad7b | 2007-11-30 08:30:29 +0000 | [diff] [blame] | 108 | } |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 109 | return p; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 110 | } |
| 111 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 112 | static struct cond_info* DRD_(cond_get)(const Addr cond) |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 113 | { |
| 114 | tl_assert(offsetof(DrdClientobj, cond) == 0); |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 115 | return &(DRD_(clientobj_get)(cond, ClientCondvar)->cond); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /** Called before pthread_cond_init(). */ |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 119 | void DRD_(cond_pre_init)(const Addr cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 120 | { |
bart | 72b751c | 2008-03-01 13:44:24 +0000 | [diff] [blame] | 121 | struct cond_info* p; |
| 122 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 123 | if (DRD_(s_trace_cond)) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 124 | { |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 125 | VG_(message)(Vg_UserMsg, |
bart | 4a975e1 | 2008-03-30 13:28:33 +0000 | [diff] [blame] | 126 | "[%d/%d] cond_init cond 0x%lx", |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 127 | VG_(get_running_tid)(), |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 128 | DRD_(thread_get_running_tid)(), |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 129 | cond); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 130 | } |
bart | 72b751c | 2008-03-01 13:44:24 +0000 | [diff] [blame] | 131 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 132 | p = DRD_(cond_get)(cond); |
bart | 72b751c | 2008-03-01 13:44:24 +0000 | [diff] [blame] | 133 | |
| 134 | if (p) |
| 135 | { |
| 136 | CondErrInfo cei = { .cond = cond }; |
| 137 | VG_(maybe_record_error)(VG_(get_running_tid)(), |
| 138 | CondErr, |
| 139 | VG_(get_IP)(VG_(get_running_tid)()), |
| 140 | "initialized twice", |
| 141 | &cei); |
| 142 | } |
| 143 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 144 | p = DRD_(cond_get_or_allocate)(cond); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 145 | } |
| 146 | |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 147 | /** Called after pthread_cond_destroy(). */ |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 148 | void DRD_(cond_post_destroy)(const Addr cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 149 | { |
bart | 72b751c | 2008-03-01 13:44:24 +0000 | [diff] [blame] | 150 | struct cond_info* p; |
| 151 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 152 | if (DRD_(s_trace_cond)) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 153 | { |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 154 | VG_(message)(Vg_UserMsg, |
bart | 4a975e1 | 2008-03-30 13:28:33 +0000 | [diff] [blame] | 155 | "[%d/%d] cond_destroy cond 0x%lx", |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 156 | VG_(get_running_tid)(), |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 157 | DRD_(thread_get_running_tid)(), |
bart | 72b751c | 2008-03-01 13:44:24 +0000 | [diff] [blame] | 158 | cond); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 159 | } |
| 160 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 161 | p = DRD_(cond_get)(cond); |
bart | 72b751c | 2008-03-01 13:44:24 +0000 | [diff] [blame] | 162 | if (p == 0) |
| 163 | { |
| 164 | CondErrInfo cei = { .cond = cond }; |
| 165 | VG_(maybe_record_error)(VG_(get_running_tid)(), |
| 166 | CondErr, |
| 167 | VG_(get_IP)(VG_(get_running_tid)()), |
| 168 | "not a condition variable", |
| 169 | &cei); |
| 170 | return; |
| 171 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 172 | |
bart | 72b751c | 2008-03-01 13:44:24 +0000 | [diff] [blame] | 173 | if (p->waiter_count != 0) |
| 174 | { |
| 175 | CondErrInfo cei = { .cond = cond }; |
| 176 | VG_(maybe_record_error)(VG_(get_running_tid)(), |
| 177 | CondErr, |
| 178 | VG_(get_IP)(VG_(get_running_tid)()), |
| 179 | "destruction of condition variable being waited" |
| 180 | " upon", |
| 181 | &cei); |
| 182 | } |
| 183 | |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 184 | DRD_(clientobj_remove)(p->a1, ClientCondvar); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 185 | } |
| 186 | |
bart | 08e6d6a | 2008-06-28 16:28:49 +0000 | [diff] [blame] | 187 | /** Called before pthread_cond_wait(). Note: before this function is called, |
| 188 | * mutex_unlock() has already been called from drd_clientreq.c. |
| 189 | */ |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 190 | int DRD_(cond_pre_wait)(const Addr cond, const Addr mutex) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 191 | { |
| 192 | struct cond_info* p; |
bart | 08e6d6a | 2008-06-28 16:28:49 +0000 | [diff] [blame] | 193 | struct mutex_info* q; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 194 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 195 | if (DRD_(s_trace_cond)) |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 196 | { |
| 197 | VG_(message)(Vg_UserMsg, |
bart | 4a975e1 | 2008-03-30 13:28:33 +0000 | [diff] [blame] | 198 | "[%d/%d] cond_pre_wait cond 0x%lx", |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 199 | VG_(get_running_tid)(), |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 200 | DRD_(thread_get_running_tid)(), |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 201 | cond); |
| 202 | } |
| 203 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 204 | p = DRD_(cond_get_or_allocate)(cond); |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 205 | tl_assert(p); |
| 206 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 207 | if (p->waiter_count == 0) |
| 208 | { |
| 209 | p->mutex = mutex; |
| 210 | } |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 211 | else if (p->mutex != mutex) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 212 | { |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 213 | CondWaitErrInfo cwei |
| 214 | = { .cond = cond, .mutex1 = p->mutex, .mutex2 = mutex }; |
| 215 | VG_(maybe_record_error)(VG_(get_running_tid)(), |
| 216 | CondWaitErr, |
| 217 | VG_(get_IP)(VG_(get_running_tid)()), |
| 218 | "Inconsistent association of condition variable" |
| 219 | " and mutex", |
| 220 | &cwei); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 221 | } |
bart | 08e6d6a | 2008-06-28 16:28:49 +0000 | [diff] [blame] | 222 | tl_assert(p->mutex); |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 223 | q = DRD_(mutex_get)(p->mutex); |
| 224 | if (q |
| 225 | && q->owner == DRD_(thread_get_running_tid)() && q->recursion_count > 0) |
bart | 08e6d6a | 2008-06-28 16:28:49 +0000 | [diff] [blame] | 226 | { |
| 227 | const ThreadId vg_tid = VG_(get_running_tid)(); |
| 228 | MutexErrInfo MEI = { q->a1, q->recursion_count, q->owner }; |
| 229 | VG_(maybe_record_error)(vg_tid, |
| 230 | MutexErr, |
| 231 | VG_(get_IP)(vg_tid), |
| 232 | "Mutex locked recursively", |
| 233 | &MEI); |
| 234 | } |
| 235 | else if (q == 0) |
| 236 | { |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 237 | DRD_(not_a_mutex)(p->mutex); |
bart | 08e6d6a | 2008-06-28 16:28:49 +0000 | [diff] [blame] | 238 | } |
| 239 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 240 | return ++p->waiter_count; |
| 241 | } |
| 242 | |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 243 | /** Called after pthread_cond_wait(). */ |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 244 | int DRD_(cond_post_wait)(const Addr cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 245 | { |
| 246 | struct cond_info* p; |
| 247 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 248 | if (DRD_(s_trace_cond)) |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 249 | { |
| 250 | VG_(message)(Vg_UserMsg, |
bart | 4a975e1 | 2008-03-30 13:28:33 +0000 | [diff] [blame] | 251 | "[%d/%d] cond_post_wait cond 0x%lx", |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 252 | VG_(get_running_tid)(), |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 253 | DRD_(thread_get_running_tid)(), |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 254 | cond); |
| 255 | } |
| 256 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 257 | p = DRD_(cond_get)(cond); |
bart | a9c5508 | 2008-06-28 16:55:35 +0000 | [diff] [blame] | 258 | if (p) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 259 | { |
bart | a9c5508 | 2008-06-28 16:55:35 +0000 | [diff] [blame] | 260 | if (p->waiter_count > 0) |
| 261 | { |
| 262 | --p->waiter_count; |
| 263 | if (p->waiter_count == 0) |
| 264 | { |
| 265 | p->mutex = 0; |
| 266 | } |
| 267 | } |
| 268 | return p->waiter_count; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 269 | } |
bart | a9c5508 | 2008-06-28 16:55:35 +0000 | [diff] [blame] | 270 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 271 | } |
| 272 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 273 | static void DRD_(cond_signal)(Addr const cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 274 | { |
| 275 | const ThreadId vg_tid = VG_(get_running_tid)(); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 276 | const DrdThreadId drd_tid = DRD_(VgThreadIdToDrdThreadId)(vg_tid); |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 277 | struct cond_info* const cond_p = DRD_(cond_get)(cond); |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 278 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 279 | if (cond_p && cond_p->waiter_count > 0) |
| 280 | { |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 281 | if (DRD_(s_report_signal_unlocked) |
| 282 | && ! DRD_(mutex_is_locked_by)(cond_p->mutex, drd_tid)) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 283 | { |
bart | 1160800 | 2008-03-13 17:47:01 +0000 | [diff] [blame] | 284 | /* A signal is sent while the associated mutex has not been locked. */ |
| 285 | /* This can indicate but is not necessarily a race condition. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 286 | CondRaceErrInfo cei; |
| 287 | cei.cond = cond; |
| 288 | cei.mutex = cond_p->mutex; |
| 289 | VG_(maybe_record_error)(vg_tid, |
| 290 | CondRaceErr, |
| 291 | VG_(get_IP)(vg_tid), |
| 292 | "CondErr", |
| 293 | &cei); |
| 294 | } |
| 295 | } |
| 296 | else |
| 297 | { |
| 298 | /* No other thread is waiting for the signal, hence the signal will be */ |
| 299 | /* lost. This is normal in a POSIX threads application. */ |
| 300 | } |
| 301 | } |
| 302 | |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 303 | /** Called before pthread_cond_signal(). */ |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 304 | void DRD_(cond_pre_signal)(Addr const cond) |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 305 | { |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 306 | if (DRD_(s_trace_cond)) |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 307 | { |
| 308 | VG_(message)(Vg_UserMsg, |
bart | 4a975e1 | 2008-03-30 13:28:33 +0000 | [diff] [blame] | 309 | "[%d/%d] cond_signal cond 0x%lx", |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 310 | VG_(get_running_tid)(), |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 311 | DRD_(thread_get_running_tid)(), |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 312 | cond); |
| 313 | } |
| 314 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 315 | DRD_(cond_signal)(cond); |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 316 | } |
| 317 | |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 318 | /** Called before pthread_cond_broadcast(). */ |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 319 | void DRD_(cond_pre_broadcast)(Addr const cond) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 320 | { |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 321 | if (DRD_(s_trace_cond)) |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 322 | { |
| 323 | VG_(message)(Vg_UserMsg, |
bart | 4a975e1 | 2008-03-30 13:28:33 +0000 | [diff] [blame] | 324 | "[%d/%d] cond_broadcast cond 0x%lx", |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 325 | VG_(get_running_tid)(), |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 326 | DRD_(thread_get_running_tid)(), |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 327 | cond); |
| 328 | } |
| 329 | |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 330 | DRD_(cond_signal)(cond); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 331 | } |
| 332 | |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 333 | /** Called after pthread_cond_destroy(). */ |
bart | dc1ef03 | 2009-02-15 14:18:02 +0000 | [diff] [blame^] | 334 | void DRD_(cond_thread_delete)(const DrdThreadId tid) |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 335 | { } |