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