blob: 831d5434cf8f3b4abf40f518ff36688df6fc51af [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,
48} ObjType;
barte7d58722008-02-28 19:08:04 +000049
50struct any
51{
52 Addr a1;
53 Addr a2;
54 ObjType type;
55 void (*cleanup)(union drd_clientobj*);
56};
57
58struct 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
bart28230a32008-02-29 17:27:03 +000070struct 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
81struct 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
93struct 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
barte7d58722008-02-28 19:08:04 +0000107typedef union drd_clientobj
108{
bart28230a32008-02-29 17:27:03 +0000109 struct any any;
110 struct mutex_info mutex;
111 struct cond_info cond;
112 struct semaphore_info semaphore;
113 struct barrier_info barrier;
barte7d58722008-02-28 19:08:04 +0000114} DrdClientobj;
115
116
117// Function declarations.
118
bart72b751c2008-03-01 13:44:24 +0000119void clientobj_set_trace(const Bool trace);
120void clientobj_init(void);
121void clientobj_cleanup(void);
122DrdClientobj* clientobj_get(const Addr addr, const ObjType t);
123Bool clientobj_present(const Addr a1, const Addr a2);
124DrdClientobj* clientobj_add(const Addr a1, const Addr a2, const ObjType t);
125Bool clientobj_remove(const Addr addr, const ObjType t);
126void clientobj_stop_using_mem(const Addr a1, const Addr a2);
127void clientobj_resetiter(void);
128DrdClientobj* clientobj_next(const ObjType t);
barte7d58722008-02-28 19:08:04 +0000129
130#endif /* __DRD_CLIENTOBJ_H */