CACAO
lockword.cpp
Go to the documentation of this file.
1 /* src/threads/lockword.cpp - lockword implementation
2 
3  Copyright (C) 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 #include "threads/lockword.hpp"
27 
28 #include <assert.h>
29 
30 #include "threads/lock.hpp"
31 #include "threads/thread.hpp"
32 
33 
34 /**
35  * Inflate the lock of the given object. This may only be called by
36  * the owner of the monitor of the object.
37  *
38  * PRE-CONDITION: The current thread must be the owner of this
39  * object's monitor AND of the lock record's lock!
40  *
41  * @param lr The lock-record to install. The current thread must own
42  * the lock of this lock record!
43  */
45 {
46  if (is_fat_lock()) {
47  // Sanity check.
48  assert(get_fat_lock() == lr);
49  return;
50  }
51 
52  // Sanity check.
53  assert(get_thin_lock_without_count() == thread_get_current()->thinlock);
54 
55  // Copy the count from the thinlock.
56  lr->count = get_thin_lock_count();
57 
58 // DEBUGLOCKS(("[lock_inflate : lr=%p, t=%p, o=%p, o->lockword=%lx, count=%d]",
59 // lr, thread_get_current(), o, get_thin_lock(), lr->count));
60 
61  // Install the lock-record in the lockword.
62  set(lr);
63 }
64 
65 
66 /*
67  * These are local overrides for various environment variables in Emacs.
68  * Please do not remove this and leave it at the end of the file, where
69  * Emacs will automagically detect them.
70  * ---------------------------------------------------------------------
71  * Local variables:
72  * mode: c++
73  * indent-tabs-mode: t
74  * c-basic-offset: 4
75  * tab-width: 4
76  * End:
77  * vim:noexpandtab:sw=4:ts=4:
78  */
void set(uintptr_t lockword)
Definition: lockword.hpp:180
#define lr
Definition: md-asm.hpp:80
int32_t get_thin_lock_count() const
Definition: lockword.hpp:162
uintptr_t get_thin_lock_without_count() const
Definition: lockword.hpp:156
static threadobject * thread_get_current()
Return the threadobject for the current thread.
Definition: thread-none.hpp:56
bool is_fat_lock() const
Definition: lockword.hpp:108
void inflate(struct lock_record_t *lr)
Inflate the lock of the given object.
Definition: lockword.cpp:44
struct lock_record_t * get_fat_lock() const
Definition: lockword.hpp:174