blob: ffd13ca738760f8a6de707e035b7e4bb67eae328 [file] [log] [blame]
barte7d58722008-02-28 19:08:04 +00001/*
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"
bart28230a32008-02-29 17:27:03 +000033#include "pub_tool_oset.h"
barte7d58722008-02-28 19:08:04 +000034
35
36// Forward declarations.
37
38union drd_clientobj;
39
40
41// Type definitions.
42
bart28230a32008-02-29 17:27:03 +000043typedef enum {
44 ClientMutex = 1,
45 ClientCondvar = 2,
46 ClientSemaphore = 3,
47 ClientBarrier = 4,
bart777f7fe2008-03-02 17:43:18 +000048 ClientRwlock = 5,
bart28230a32008-02-29 17:27:03 +000049} ObjType;
barte7d58722008-02-28 19:08:04 +000050
51struct any
52{
53 Addr a1;
54 Addr a2;
55 ObjType type;
56 void (*cleanup)(union drd_clientobj*);
57};
58
59struct mutex_info
60{
61 Addr a1;
62 Addr a2;
63 ObjType type;
64 void (*cleanup)(union drd_clientobj*);
65 MutexT mutex_type; // pthread_mutex_t or pthread_spinlock_t.
66 int recursion_count; // 0 if free, >= 1 if locked.
67 DrdThreadId owner; // owner if locked, last owner if free.
68 VectorClock vc; // vector clock associated with last unlock.
69};
70
bart28230a32008-02-29 17:27:03 +000071struct cond_info
72{
73 Addr a1;
74 Addr a2;
75 ObjType type;
76 void (*cleanup)(union drd_clientobj*);
77 int waiter_count;
78 Addr mutex; // Client mutex specified in pthread_cond_wait() call, and null
79 // if no client threads are currently waiting on this cond.var.
80};
81
82struct semaphore_info
83{
84 Addr a1;
85 Addr a2;
86 ObjType type;
87 void (*cleanup)(union drd_clientobj*);
88 UWord value; // Semaphore value.
89 UWord waiters; // Number of threads inside sem_wait().
90 DrdThreadId last_sem_post_tid; // Thread ID associated with last sem_post().
91 VectorClock vc; // Vector clock of last sem_post() call.
92};
93
94struct barrier_info
95{
96 Addr a1;
97 Addr a2;
98 ObjType type;
99 void (*cleanup)(union drd_clientobj*);
bart777f7fe2008-03-02 17:43:18 +0000100 Word count; // Participant count in a barrier wait.
101 Word pre_iteration; // pthread_barrier_wait() call count modulo two.
102 Word post_iteration; // pthread_barrier_wait() call count modulo two.
103 Word pre_waiters_left; // number of waiters left for a complete barrier.
104 Word post_waiters_left; // number of waiters left for a complete barrier.
105 OSet* oset; // Thread-specific barrier information.
106};
107
108struct rwlock_info
109{
110 Addr a1;
111 Addr a2;
112 ObjType type;
113 void (*cleanup)(union drd_clientobj*);
114 OSet* thread_info;
bart28230a32008-02-29 17:27:03 +0000115};
116
barte7d58722008-02-28 19:08:04 +0000117typedef union drd_clientobj
118{
bart28230a32008-02-29 17:27:03 +0000119 struct any any;
120 struct mutex_info mutex;
121 struct cond_info cond;
122 struct semaphore_info semaphore;
123 struct barrier_info barrier;
bart777f7fe2008-03-02 17:43:18 +0000124 struct rwlock_info rwlock;
barte7d58722008-02-28 19:08:04 +0000125} DrdClientobj;
126
127
128// Function declarations.
129
bart72b751c2008-03-01 13:44:24 +0000130void clientobj_set_trace(const Bool trace);
131void clientobj_init(void);
132void clientobj_cleanup(void);
133DrdClientobj* clientobj_get(const Addr addr, const ObjType t);
134Bool clientobj_present(const Addr a1, const Addr a2);
135DrdClientobj* clientobj_add(const Addr a1, const Addr a2, const ObjType t);
136Bool clientobj_remove(const Addr addr, const ObjType t);
137void clientobj_stop_using_mem(const Addr a1, const Addr a2);
138void clientobj_resetiter(void);
139DrdClientobj* clientobj_next(const ObjType t);
barte7d58722008-02-28 19:08:04 +0000140
141#endif /* __DRD_CLIENTOBJ_H */