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, |
| 48 | } ObjType; |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 49 | |
| 50 | struct any |
| 51 | { |
| 52 | Addr a1; |
| 53 | Addr a2; |
| 54 | ObjType type; |
| 55 | void (*cleanup)(union drd_clientobj*); |
| 56 | }; |
| 57 | |
| 58 | struct mutex_info |
| 59 | { |
| 60 | Addr a1; |
| 61 | Addr a2; |
| 62 | ObjType type; |
| 63 | void (*cleanup)(union drd_clientobj*); |
| 64 | MutexT mutex_type; // pthread_mutex_t or pthread_spinlock_t. |
| 65 | int recursion_count; // 0 if free, >= 1 if locked. |
| 66 | DrdThreadId owner; // owner if locked, last owner if free. |
| 67 | VectorClock vc; // vector clock associated with last unlock. |
| 68 | }; |
| 69 | |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame^] | 70 | struct cond_info |
| 71 | { |
| 72 | Addr a1; |
| 73 | Addr a2; |
| 74 | ObjType type; |
| 75 | void (*cleanup)(union drd_clientobj*); |
| 76 | int waiter_count; |
| 77 | Addr mutex; // Client mutex specified in pthread_cond_wait() call, and null |
| 78 | // if no client threads are currently waiting on this cond.var. |
| 79 | }; |
| 80 | |
| 81 | struct semaphore_info |
| 82 | { |
| 83 | Addr a1; |
| 84 | Addr a2; |
| 85 | ObjType type; |
| 86 | void (*cleanup)(union drd_clientobj*); |
| 87 | UWord value; // Semaphore value. |
| 88 | UWord waiters; // Number of threads inside sem_wait(). |
| 89 | DrdThreadId last_sem_post_tid; // Thread ID associated with last sem_post(). |
| 90 | VectorClock vc; // Vector clock of last sem_post() call. |
| 91 | }; |
| 92 | |
| 93 | struct barrier_info |
| 94 | { |
| 95 | Addr a1; |
| 96 | Addr a2; |
| 97 | ObjType type; |
| 98 | void (*cleanup)(union drd_clientobj*); |
| 99 | Word count; // Participant count in a barrier wait. |
| 100 | Word pre_iteration; // pthread_barrier_wait() call count modulo two. |
| 101 | Word post_iteration; // pthread_barrier_wait() call count modulo two. |
| 102 | Word pre_waiters_left; // number of waiters left for a complete barrier. |
| 103 | Word post_waiters_left; // number of waiters left for a complete barrier. |
| 104 | OSet* oset; // Thread-specific barrier information. |
| 105 | }; |
| 106 | |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 107 | typedef union drd_clientobj |
| 108 | { |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame^] | 109 | struct any any; |
| 110 | struct mutex_info mutex; |
| 111 | struct cond_info cond; |
| 112 | struct semaphore_info semaphore; |
| 113 | struct barrier_info barrier; |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 114 | } DrdClientobj; |
| 115 | |
| 116 | |
| 117 | // Function declarations. |
| 118 | |
| 119 | void drd_clientobj_init(void); |
| 120 | void drd_clientobj_cleanup(void); |
| 121 | DrdClientobj* drd_clientobj_get(const Addr addr, const ObjType t); |
| 122 | Bool drd_clientobj_present(const Addr a1, const Addr a2); |
| 123 | DrdClientobj* drd_clientobj_add(const Addr a1, const Addr a2, const ObjType t); |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame^] | 124 | Bool drd_clientobj_remove(const Addr addr, const ObjType t); |
bart | e7d5872 | 2008-02-28 19:08:04 +0000 | [diff] [blame] | 125 | void drd_clientobj_stop_using_mem(const Addr a1, const Addr a2); |
| 126 | void drd_clientobj_resetiter(void); |
| 127 | DrdClientobj* drd_clientobj_next(const ObjType t); |
| 128 | |
| 129 | #endif /* __DRD_CLIENTOBJ_H */ |