bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 1 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 2 | This file is part of drd, a thread error detector. |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 3 | |
sewardj | b3a1e4b | 2015-08-21 11:32:26 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2015 Bart Van Assche <bvanassche@acm.org>. |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU General Public License as |
| 8 | published by the Free Software Foundation; either version 2 of the |
| 9 | License, or (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 19 | 02111-1307, USA. |
| 20 | |
| 21 | The GNU General Public License is contained in the file COPYING. |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #ifndef __DRD_CLIENTOBJ_H |
| 26 | #define __DRD_CLIENTOBJ_H |
| 27 | |
| 28 | |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 29 | #include "drd_basics.h" /* DrdThreadId */ |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 30 | #include "drd_clientreq.h" /* MutexT */ |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 31 | #include "pub_tool_basics.h" |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 32 | #include "pub_tool_execontext.h" /* ExeContext */ |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 33 | #include "pub_tool_oset.h" |
bart | 3e017fa | 2008-12-17 19:20:13 +0000 | [diff] [blame] | 34 | #include "pub_tool_xarray.h" |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 35 | |
| 36 | |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 37 | /* Forward declarations. */ |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 38 | |
| 39 | union drd_clientobj; |
| 40 | |
| 41 | |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 42 | /* Type definitions. */ |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 43 | |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 44 | typedef enum { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 45 | ClientMutex = 1, |
| 46 | ClientCondvar = 2, |
bart | 62cc232 | 2010-03-07 10:54:21 +0000 | [diff] [blame] | 47 | ClientHbvar = 3, |
| 48 | ClientSemaphore = 4, |
| 49 | ClientBarrier = 5, |
| 50 | ClientRwlock = 6, |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 51 | } ObjType; |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 52 | |
| 53 | struct any |
| 54 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 55 | Addr a1; |
| 56 | ObjType type; |
| 57 | void (*cleanup)(union drd_clientobj*); |
| 58 | void (*delete_thread)(union drd_clientobj*, DrdThreadId); |
| 59 | ExeContext* first_observed_at; |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | struct mutex_info |
| 63 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 64 | Addr a1; |
| 65 | ObjType type; |
| 66 | void (*cleanup)(union drd_clientobj*); |
| 67 | void (*delete_thread)(union drd_clientobj*, DrdThreadId); |
| 68 | ExeContext* first_observed_at; |
| 69 | MutexT mutex_type; // pthread_mutex_t or pthread_spinlock_t. |
| 70 | int recursion_count; // 0 if free, >= 1 if locked. |
bart | 3cc2620 | 2014-06-09 09:19:26 +0000 | [diff] [blame] | 71 | Bool ignore_ordering; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 72 | DrdThreadId owner; // owner if locked, last owner if free. |
| 73 | struct segment* last_locked_segment; |
| 74 | ULong acquiry_time_ms; |
| 75 | ExeContext* acquired_at; |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 78 | struct cond_info |
| 79 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 80 | Addr a1; |
| 81 | ObjType type; |
| 82 | void (*cleanup)(union drd_clientobj*); |
| 83 | void (*delete_thread)(union drd_clientobj*, DrdThreadId); |
| 84 | ExeContext* first_observed_at; |
| 85 | int waiter_count; |
| 86 | Addr mutex; // Client mutex specified in pthread_cond_wait() call, and |
bart | 62cc232 | 2010-03-07 10:54:21 +0000 | [diff] [blame] | 87 | // null if no client threads are currently waiting on this cond.var. |
| 88 | }; |
| 89 | |
| 90 | struct hb_info |
| 91 | { |
| 92 | Addr a1; |
| 93 | ObjType type; |
| 94 | void (*cleanup)(union drd_clientobj*); |
| 95 | void (*delete_thread)(union drd_clientobj*, DrdThreadId); |
| 96 | ExeContext* first_observed_at; |
| 97 | OSet* oset; // Per-thread order annotation information. |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | struct semaphore_info |
| 101 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 102 | Addr a1; |
| 103 | ObjType type; |
| 104 | void (*cleanup)(union drd_clientobj*); |
| 105 | void (*delete_thread)(union drd_clientobj*, DrdThreadId); |
| 106 | ExeContext* first_observed_at; |
| 107 | UInt waits_to_skip; // Number of sem_wait() calls to skip |
| 108 | // (due to the value assigned by sem_init()). |
| 109 | UInt value; // Semaphore value. |
| 110 | UWord waiters; // Number of threads inside sem_wait(). |
| 111 | DrdThreadId last_sem_post_tid; // Thread ID associated with last sem_post(). |
| 112 | XArray* last_sem_post_seg; // array of Segment*, used as a stack. |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | struct barrier_info |
| 116 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 117 | Addr a1; |
| 118 | ObjType type; |
| 119 | void (*cleanup)(union drd_clientobj*); |
| 120 | void (*delete_thread)(union drd_clientobj*, DrdThreadId); |
| 121 | ExeContext* first_observed_at; |
| 122 | BarrierT barrier_type; // pthread_barrier or gomp_barrier. |
| 123 | Word count; // Participant count in a barrier wait. |
| 124 | Word pre_iteration; // pre barrier completion count modulo two. |
| 125 | Word post_iteration; // post barrier completion count modulo two. |
| 126 | Word pre_waiters_left; // number of waiters left for a complete barrier. |
| 127 | Word post_waiters_left; // number of waiters left for a complete barrier. |
bart | d61580e | 2011-07-29 12:39:44 +0000 | [diff] [blame] | 128 | OSet* oset[2]; // Per-thread barrier information for the latest |
| 129 | // two barrier iterations. |
bart | 777f7fe | 2008-03-02 17:43:18 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | struct rwlock_info |
| 133 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 134 | Addr a1; |
| 135 | ObjType type; |
| 136 | void (*cleanup)(union drd_clientobj*); |
| 137 | void (*delete_thread)(union drd_clientobj*, DrdThreadId); |
| 138 | ExeContext* first_observed_at; |
bart | c844150 | 2009-07-27 16:03:51 +0000 | [diff] [blame] | 139 | RwLockT rwlock_type; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 140 | OSet* thread_info; |
| 141 | ULong acquiry_time_ms; |
| 142 | ExeContext* acquired_at; |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 145 | typedef union drd_clientobj |
| 146 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 147 | struct any any; |
| 148 | struct mutex_info mutex; |
| 149 | struct cond_info cond; |
bart | 62cc232 | 2010-03-07 10:54:21 +0000 | [diff] [blame] | 150 | struct hb_info hb; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 151 | struct semaphore_info semaphore; |
| 152 | struct barrier_info barrier; |
| 153 | struct rwlock_info rwlock; |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 154 | } DrdClientobj; |
| 155 | |
| 156 | |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 157 | /* Function declarations. */ |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 158 | |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 159 | void DRD_(clientobj_set_trace)(const Bool trace); |
| 160 | void DRD_(clientobj_init)(void); |
| 161 | void DRD_(clientobj_cleanup)(void); |
| 162 | DrdClientobj* DRD_(clientobj_get_any)(const Addr addr); |
| 163 | DrdClientobj* DRD_(clientobj_get)(const Addr addr, const ObjType t); |
| 164 | Bool DRD_(clientobj_present)(const Addr a1, const Addr a2); |
| 165 | DrdClientobj* DRD_(clientobj_add)(const Addr a1, const ObjType t); |
| 166 | Bool DRD_(clientobj_remove)(const Addr addr, const ObjType t); |
| 167 | void DRD_(clientobj_stop_using_mem)(const Addr a1, const Addr a2); |
bart | d2c5eae | 2009-02-21 15:27:04 +0000 | [diff] [blame] | 168 | void DRD_(clientobj_delete_thread)(const DrdThreadId tid); |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 169 | const HChar* DRD_(clientobj_type_name)(const ObjType t); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 170 | |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 171 | |
| 172 | #endif /* __DRD_CLIENTOBJ_H */ |