1 /* src/threads/lock.hpp - 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
31 #include "native/llni.h"
33 #include "threads/mutex.hpp"
35 #include "toolbox/list.h"
37 #include "vm/global.h"
40 /* only define the following stuff with thread enabled ************************/
42 #if defined(ENABLE_THREADS)
44 /* typedefs *******************************************************************/
46 typedef struct lock_record_t lock_record_t;
47 typedef struct lock_waiter_t lock_waiter_t;
48 typedef struct lock_hashtable_t lock_hashtable_t;
51 /* lock_waiter_t ***************************************************************
53 List node for storing a waiting thread.
55 *******************************************************************************/
57 struct lock_waiter_t {
58 struct threadobject *thread; /* the waiting thread */
63 /* lock_record_t ***************************************************************
65 Lock record struct representing an inflated ("fat") lock.
67 *******************************************************************************/
69 struct lock_record_t {
70 java_object_t *object; /* object for which this lock is */
71 struct threadobject *owner; /* current owner of this monitor */
72 s4 count; /* recursive lock count */
73 Mutex* mutex; /* mutex for synchronizing */
74 list_t *waiters; /* list of threads waiting */
75 lock_record_t *hashlink; /* next record in hash chain */
79 /* lock_hashtable_t ************************************************************
81 The global hashtable mapping objects to lock records.
83 *******************************************************************************/
85 struct lock_hashtable_t {
86 Mutex* mutex; /* mutex for synch. access to the table */
87 u4 size; /* number of slots */
88 u4 entries; /* current number of entries */
89 lock_record_t **ptr; /* the table of slots, uses ext. chain. */
93 /* functions ******************************************************************/
101 void lock_init_object_lock(java_object_t *);
103 ptrint lock_pre_compute_thinlock(s4 index);
105 bool lock_monitor_enter(java_handle_t *);
106 bool lock_monitor_exit(java_handle_t *);
108 #define LOCK_monitor_enter (functionptr) lock_monitor_enter
109 #define LOCK_monitor_exit (functionptr) lock_monitor_exit
111 bool lock_is_held_by_current_thread(java_handle_t *o);
113 void lock_wait_for_object(java_handle_t *o, s8 millis, s4 nanos);
114 void lock_notify_object(java_handle_t *o);
115 void lock_notify_all_object(java_handle_t *o);
122 /* defines ********************************************************************/
124 #define LOCK_INIT_OBJECT_LOCK(o) lock_init_object_lock((java_object_t *) (o))
126 #define LOCK_MONITOR_ENTER(o) lock_monitor_enter((java_handle_t *) LLNI_QUICKWRAP(o))
127 #define LOCK_MONITOR_EXIT(o) lock_monitor_exit((java_handle_t *) LLNI_QUICKWRAP(o))
135 * These are local overrides for various environment variables in Emacs.
136 * Please do not remove this and leave it at the end of the file, where
137 * Emacs will automagically detect them.
138 * ---------------------------------------------------------------------
141 * indent-tabs-mode: t
145 * vim:noexpandtab:sw=4:ts=4: