b6cf995cafa606d19ffc862ff3d2ad96c968866d
[cacao.git] / src / threads / native / lock.h
1 /* src/threads/native/lock.h - lock implementation
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: lock.h 8295 2007-08-11 17:57:24Z michi $
26
27 */
28
29
30 #ifndef _LOCK_H
31 #define _LOCK_H
32
33 #include "config.h"
34
35 #include <pthread.h>
36
37 #include "vm/types.h"
38
39 #include "vm/global.h"
40
41
42
43 /* typedefs *******************************************************************/
44
45 typedef struct lock_record_t             lock_record_t;
46 typedef struct lock_waiter_t             lock_waiter_t;
47 typedef struct lock_hashtable_t          lock_hashtable_t;
48
49
50 /* lock_waiter_t ***************************************************************
51
52    List node for storing a waiting thread.
53
54 *******************************************************************************/
55
56 struct lock_waiter_t {
57         struct threadobject *waiter;         /* the waiting thread                */
58         lock_waiter_t       *next;           /* next in list                      */
59 };
60
61
62 /* lock_record_t ***************************************************************
63
64    Lock record struct representing an inflated ("fat") lock.
65
66 *******************************************************************************/
67
68 struct lock_record_t {
69         java_object_t       *object;             /* object for which this lock is */
70         struct threadobject *owner;              /* current owner of this monitor */
71         s4                   count;              /* recursive lock count          */
72         pthread_mutex_t      mutex;              /* mutex for synchronizing       */
73         lock_waiter_t       *waiters;            /* list of threads waiting       */
74         lock_record_t       *hashlink;           /* next record in hash chain     */
75 };
76
77
78 /* lock_hashtable_t ************************************************************
79  
80    The global hashtable mapping objects to lock records.
81
82 *******************************************************************************/
83
84 struct lock_hashtable_t {
85         pthread_mutex_t      mutex;       /* mutex for synch. access to the table */
86         u4                   size;        /* number of slots                      */
87         u4                   entries;     /* current number of entries            */
88         lock_record_t      **ptr;         /* the table of slots, uses ext. chain. */
89 };
90
91
92 /* defines ********************************************************************/
93
94 #define LOCK_INIT_OBJECT_LOCK(o) lock_init_object_lock((java_object_t *) (o))
95
96 #define LOCK_MONITOR_ENTER(o)    lock_monitor_enter((java_object_t *) (o))
97 #define LOCK_MONITOR_EXIT(o)     lock_monitor_exit((java_object_t *) (o))
98
99 #endif /* _LOCK_H */
100
101
102 /*
103  * These are local overrides for various environment variables in Emacs.
104  * Please do not remove this and leave it at the end of the file, where
105  * Emacs will automagically detect them.
106  * ---------------------------------------------------------------------
107  * Local variables:
108  * mode: c
109  * indent-tabs-mode: t
110  * c-basic-offset: 4
111  * tab-width: 4
112  * End:
113  * vim:noexpandtab:sw=4:ts=4:
114  */