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