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" |
| 33 | |
| 34 | |
| 35 | // Forward declarations. |
| 36 | |
| 37 | union drd_clientobj; |
| 38 | |
| 39 | |
| 40 | // Type definitions. |
| 41 | |
| 42 | typedef enum { ClientMutex, } ObjType; |
| 43 | |
| 44 | struct any |
| 45 | { |
| 46 | Addr a1; |
| 47 | Addr a2; |
| 48 | ObjType type; |
| 49 | void (*cleanup)(union drd_clientobj*); |
| 50 | }; |
| 51 | |
| 52 | struct mutex_info |
| 53 | { |
| 54 | Addr a1; |
| 55 | Addr a2; |
| 56 | ObjType type; |
| 57 | void (*cleanup)(union drd_clientobj*); |
| 58 | MutexT mutex_type; // pthread_mutex_t or pthread_spinlock_t. |
| 59 | int recursion_count; // 0 if free, >= 1 if locked. |
| 60 | DrdThreadId owner; // owner if locked, last owner if free. |
| 61 | VectorClock vc; // vector clock associated with last unlock. |
| 62 | }; |
| 63 | |
| 64 | typedef union drd_clientobj |
| 65 | { |
| 66 | struct any any; |
| 67 | struct mutex_info mutex; |
| 68 | } DrdClientobj; |
| 69 | |
| 70 | |
| 71 | // Function declarations. |
| 72 | |
| 73 | void drd_clientobj_init(void); |
| 74 | void drd_clientobj_cleanup(void); |
| 75 | DrdClientobj* drd_clientobj_get(const Addr addr, const ObjType t); |
| 76 | Bool drd_clientobj_present(const Addr a1, const Addr a2); |
| 77 | DrdClientobj* drd_clientobj_add(const Addr a1, const Addr a2, const ObjType t); |
| 78 | Bool drd_clientobj_remove(const Addr addr); |
| 79 | void drd_clientobj_stop_using_mem(const Addr a1, const Addr a2); |
| 80 | void drd_clientobj_resetiter(void); |
| 81 | DrdClientobj* drd_clientobj_next(const ObjType t); |
| 82 | |
| 83 | #endif /* __DRD_CLIENTOBJ_H */ |