2 * Copyright 2009, Michael Lotz, mmlr@mlotz.ch.
3 * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
5 * Distributed under the terms of the MIT License.
7 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
8 * Distributed under the terms of the NewOS License.
17 // #pragma mark - recursive lock
21 __recursive_lock_get_recursion(recursive_lock
*lock
)
23 if (lock
->holder
== find_thread(NULL
))
24 return lock
->recursion
;
31 __recursive_lock_init(recursive_lock
*lock
, const char *name
)
33 recursive_lock_init_etc(lock
, name
, 0);
38 __recursive_lock_init_etc(recursive_lock
*lock
, const char *name
, uint32 flags
)
42 mutex_init_etc(&lock
->lock
, name
, flags
);
47 __recursive_lock_destroy(recursive_lock
*lock
)
52 mutex_destroy(&lock
->lock
);
57 __recursive_lock_lock(recursive_lock
*lock
)
59 thread_id thread
= find_thread(NULL
);
61 if (thread
!= lock
->holder
) {
62 mutex_lock(&lock
->lock
);
63 lock
->holder
= thread
;
72 __recursive_lock_unlock(recursive_lock
*lock
)
74 if (find_thread(NULL
) != lock
->holder
) {
75 debugger("recursive_lock unlocked by non-holder thread!\n");
79 if (--lock
->recursion
== 0) {
81 mutex_unlock(&lock
->lock
);