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