blob: abc92f5e6632b1b3dc9afdb27dd88ecf977138a0 [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;
barte7d58722008-02-28 19:08:04 +000054 ObjType type;
55 void (*cleanup)(union drd_clientobj*);
56};
57
58struct mutex_info
59{
60 Addr a1;
barte7d58722008-02-28 19:08:04 +000061 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.
barta2b6e1b2008-03-17 18:32:39 +000066 Segment* last_locked_segment;
barte7d58722008-02-28 19:08:04 +000067};
68
bart28230a32008-02-29 17:27:03 +000069struct cond_info
70{
71 Addr a1;
bart28230a32008-02-29 17:27:03 +000072 ObjType type;
73 void (*cleanup)(union drd_clientobj*);
74 int waiter_count;
barta2b6e1b2008-03-17 18:32:39 +000075 Addr mutex; //Client mutex specified in pthread_cond_wait() call, and null
76 //if no client threads are currently waiting on this cond.var.
bart28230a32008-02-29 17:27:03 +000077};
78
79struct semaphore_info
80{
81 Addr a1;
bart28230a32008-02-29 17:27:03 +000082 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().
barta2b6e1b2008-03-17 18:32:39 +000087 Segment* last_sem_post_segment;
bart28230a32008-02-29 17:27:03 +000088};
89
90struct barrier_info
91{
92 Addr a1;
bart28230a32008-02-29 17:27:03 +000093 ObjType type;
94 void (*cleanup)(union drd_clientobj*);
bart306527d2008-03-12 17:23:07 +000095 BarrierT barrier_type; // pthread_barrier or gomp_barrier.
bart777f7fe2008-03-02 17:43:18 +000096 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
104struct rwlock_info
105{
106 Addr a1;
bart777f7fe2008-03-02 17:43:18 +0000107 ObjType type;
108 void (*cleanup)(union drd_clientobj*);
109 OSet* thread_info;
bart28230a32008-02-29 17:27:03 +0000110};
111
barte7d58722008-02-28 19:08:04 +0000112typedef union drd_clientobj
113{
bart28230a32008-02-29 17:27:03 +0000114 struct any any;
115 struct mutex_info mutex;
116 struct cond_info cond;
117 struct semaphore_info semaphore;
118 struct barrier_info barrier;
bart777f7fe2008-03-02 17:43:18 +0000119 struct rwlock_info rwlock;
barte7d58722008-02-28 19:08:04 +0000120} DrdClientobj;
121
122
123// Function declarations.
124
bart72b751c2008-03-01 13:44:24 +0000125void clientobj_set_trace(const Bool trace);
126void clientobj_init(void);
127void clientobj_cleanup(void);
128DrdClientobj* clientobj_get(const Addr addr, const ObjType t);
129Bool clientobj_present(const Addr a1, const Addr a2);
bart0268dfa2008-03-11 20:10:21 +0000130DrdClientobj* clientobj_add(const Addr a1, const ObjType t);
bart72b751c2008-03-01 13:44:24 +0000131Bool clientobj_remove(const Addr addr, const ObjType t);
132void clientobj_stop_using_mem(const Addr a1, const Addr a2);
133void clientobj_resetiter(void);
134DrdClientobj* clientobj_next(const ObjType t);
barte7d58722008-02-28 19:08:04 +0000135
136#endif /* __DRD_CLIENTOBJ_H */