1 /* src/threads/posix/lock.h - lock implementation
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
35 #include "native/llni.h"
37 #include "threads/mutex.h"
39 #include "toolbox/list.h"
41 #include "vm/global.h"
45 /* typedefs *******************************************************************/
47 typedef struct lock_record_t lock_record_t;
48 typedef struct lock_waiter_t lock_waiter_t;
49 typedef struct lock_hashtable_t lock_hashtable_t;
52 /* lock_waiter_t ***************************************************************
54 List node for storing a waiting thread.
56 *******************************************************************************/
58 struct lock_waiter_t {
59 struct threadobject *thread; /* the waiting thread */
64 /* lock_record_t ***************************************************************
66 Lock record struct representing an inflated ("fat") lock.
68 *******************************************************************************/
70 struct lock_record_t {
71 java_object_t *object; /* object for which this lock is */
72 struct threadobject *owner; /* current owner of this monitor */
73 s4 count; /* recursive lock count */
74 mutex_t mutex; /* mutex for synchronizing */
75 list_t *waiters; /* list of threads waiting */
76 lock_record_t *hashlink; /* next record in hash chain */
80 /* lock_hashtable_t ************************************************************
82 The global hashtable mapping objects to lock records.
84 *******************************************************************************/
86 struct lock_hashtable_t {
87 mutex_t mutex; /* mutex for synch. access to the table */
88 u4 size; /* number of slots */
89 u4 entries; /* current number of entries */
90 lock_record_t **ptr; /* the table of slots, uses ext. chain. */
94 /* defines ********************************************************************/
96 #define LOCK_INIT_OBJECT_LOCK(o) lock_init_object_lock((java_object_t *) (o))
98 #define LOCK_MONITOR_ENTER(o) lock_monitor_enter((java_handle_t *) LLNI_QUICKWRAP(o))
99 #define LOCK_MONITOR_EXIT(o) lock_monitor_exit((java_handle_t *) LLNI_QUICKWRAP(o))
101 #define LOCK_WAIT_FOREVER(o) lock_wait_for_object((java_handle_t *) LLNI_QUICKWRAP(o), 0, 0)
102 #define LOCK_NOTIFY(o) lock_notify_object((java_handle_t *) LLNI_QUICKWRAP(o))
108 * These are local overrides for various environment variables in Emacs.
109 * Please do not remove this and leave it at the end of the file, where
110 * Emacs will automagically detect them.
111 * ---------------------------------------------------------------------
114 * indent-tabs-mode: t
118 * vim:noexpandtab:sw=4:ts=4: