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 | |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame^] | 4 | Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>. |
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 { |
| 45 | ClientMutex = 1, |
| 46 | ClientCondvar = 2, |
| 47 | ClientSemaphore = 3, |
| 48 | ClientBarrier = 4, |
bart | 777f7fe | 2008-03-02 17:43:18 +0000 | [diff] [blame] | 49 | ClientRwlock = 5, |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 50 | } ObjType; |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 51 | |
| 52 | struct any |
| 53 | { |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 54 | Addr a1; |
| 55 | ObjType type; |
| 56 | void (*cleanup)(union drd_clientobj*); |
| 57 | ExeContext* first_observed_at; |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | struct mutex_info |
| 61 | { |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 62 | Addr a1; |
| 63 | ObjType type; |
| 64 | void (*cleanup)(union drd_clientobj*); |
| 65 | ExeContext* first_observed_at; |
| 66 | MutexT mutex_type; // pthread_mutex_t or pthread_spinlock_t. |
| 67 | int recursion_count; // 0 if free, >= 1 if locked. |
| 68 | DrdThreadId owner; // owner if locked, last owner if free. |
| 69 | struct segment* last_locked_segment; |
| 70 | ULong acquiry_time_ms; |
| 71 | ExeContext* acquired_at; |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 74 | struct cond_info |
| 75 | { |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 76 | Addr a1; |
| 77 | ObjType type; |
| 78 | void (*cleanup)(union drd_clientobj*); |
| 79 | ExeContext* first_observed_at; |
| 80 | int waiter_count; |
| 81 | Addr mutex; // Client mutex specified in pthread_cond_wait() call, and |
| 82 | // null if no client threads are currently waiting on this cond.var. |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | struct semaphore_info |
| 86 | { |
| 87 | Addr a1; |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 88 | ObjType type; |
| 89 | void (*cleanup)(union drd_clientobj*); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 90 | ExeContext* first_observed_at; |
bart | c8914e9 | 2008-12-24 09:45:41 +0000 | [diff] [blame] | 91 | UInt waits_to_skip; // Number of sem_wait() calls to skip |
| 92 | // (due to the value assigned by sem_init()). |
bart | afb42b7 | 2008-12-17 07:32:09 +0000 | [diff] [blame] | 93 | UInt value; // Semaphore value. |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 94 | UWord waiters; // Number of threads inside sem_wait(). |
| 95 | DrdThreadId last_sem_post_tid; // Thread ID associated with last sem_post(). |
bart | 3e017fa | 2008-12-17 19:20:13 +0000 | [diff] [blame] | 96 | XArray* last_sem_post_seg; // array of Segment*, used as a stack. |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | struct barrier_info |
| 100 | { |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 101 | Addr a1; |
| 102 | ObjType type; |
| 103 | void (*cleanup)(union drd_clientobj*); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 104 | ExeContext* first_observed_at; |
bart | 306527d | 2008-03-12 17:23:07 +0000 | [diff] [blame] | 105 | BarrierT barrier_type; // pthread_barrier or gomp_barrier. |
bart | 777f7fe | 2008-03-02 17:43:18 +0000 | [diff] [blame] | 106 | Word count; // Participant count in a barrier wait. |
| 107 | Word pre_iteration; // pthread_barrier_wait() call count modulo two. |
| 108 | Word post_iteration; // pthread_barrier_wait() call count modulo two. |
| 109 | Word pre_waiters_left; // number of waiters left for a complete barrier. |
| 110 | Word post_waiters_left; // number of waiters left for a complete barrier. |
| 111 | OSet* oset; // Thread-specific barrier information. |
| 112 | }; |
| 113 | |
| 114 | struct rwlock_info |
| 115 | { |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 116 | Addr a1; |
| 117 | ObjType type; |
| 118 | void (*cleanup)(union drd_clientobj*); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 119 | ExeContext* first_observed_at; |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 120 | OSet* thread_info; |
| 121 | ULong acquiry_time_ms; |
| 122 | ExeContext* acquired_at; |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 125 | typedef union drd_clientobj |
| 126 | { |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 127 | struct any any; |
| 128 | struct mutex_info mutex; |
| 129 | struct cond_info cond; |
| 130 | struct semaphore_info semaphore; |
| 131 | struct barrier_info barrier; |
bart | 777f7fe | 2008-03-02 17:43:18 +0000 | [diff] [blame] | 132 | struct rwlock_info rwlock; |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 133 | } DrdClientobj; |
| 134 | |
| 135 | |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 136 | /* Function declarations. */ |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 137 | |
bart | 195e41f | 2009-02-15 11:34:57 +0000 | [diff] [blame] | 138 | void DRD_(clientobj_set_trace)(const Bool trace); |
| 139 | void DRD_(clientobj_init)(void); |
| 140 | void DRD_(clientobj_cleanup)(void); |
| 141 | DrdClientobj* DRD_(clientobj_get_any)(const Addr addr); |
| 142 | DrdClientobj* DRD_(clientobj_get)(const Addr addr, const ObjType t); |
| 143 | Bool DRD_(clientobj_present)(const Addr a1, const Addr a2); |
| 144 | DrdClientobj* DRD_(clientobj_add)(const Addr a1, const ObjType t); |
| 145 | Bool DRD_(clientobj_remove)(const Addr addr, const ObjType t); |
| 146 | void DRD_(clientobj_stop_using_mem)(const Addr a1, const Addr a2); |
| 147 | void DRD_(clientobj_resetiter)(void); |
| 148 | DrdClientobj* DRD_(clientobj_next)(const ObjType t); |
| 149 | const char* DRD_(clientobj_type_name)(const ObjType t); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 150 | |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 151 | |
| 152 | #endif /* __DRD_CLIENTOBJ_H */ |