History log of /haiku/headers/private/kernel/lock.h
Revision Date Author Comments
# 30fda09a 19-Jun-2023 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Rewrite KDEBUG_RW_LOCK_DEBUG.

Previously this just turned the rw_lock into the equivalent of a
recursive_lock, which meant that reader vs. writer assertions
were of no use.

Now, we have a per-thread static array which stores the held read
locks, allowing ASSERT_READ_LOCKED_RW_LOCK to work properly,
and allowing multiple readers to be active at a time.

This probably should still remain disabled even on nightly builds,
but at least it's much more useful as a debugging tool than it was
beforehand.

Change-Id: I386b2bc2ada8df42f4ab11a05563ef22af58e77f


# 2555f335 14-May-2020 Michael Lotz <mmlr@mlotz.ch>

Cleanup: Various comment and whitespace fixes.

Change-Id: I37c3e3346813efc595df651421b7e8ff4fbf3339
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2845
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 57656b93 14-May-2020 Michael Lotz <mmlr@mlotz.ch>

kernel/locks: Implement lock switching for recursive_lock.

This allows switching from another recursive_lock, mutex or read-locked
rw_lock analogous to the switching possibilities already in mutex.

With this, recursive_locks can be used in more complex situations where
previously only mutexes would work.

Also add debugger command to dump a recursive_lock.

Change-Id: Ibeeae1b42c543d925dec61a3b257e1f3df7f8934
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2834
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# e54b2d7c 16-May-2020 Augustin Cavalier <waddlesplash@gmail.com>

kernel/lock: Fix build under non-KDEBUG.

I forgot to change MUTEX_INITIALIZER following removal of the
unused field.

Change-Id: I011c023ae00bb4576c8bcecf83546892fef3a77e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2719
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# fd161d7b 16-May-2020 Augustin Cavalier <waddlesplash@gmail.com>

kernel/locks: Remove ignore_unlock_count and fix races in lock timeout.

As far as I can tell, there is no reason to ignore unlocks, ever;
if no threads are waiting, then mutex_unlock() will act appropriately.
So all we need to do is increment the lock's count here,
as we are relinquishing our request for locking.

On the other hand, if we did not find our structure in the lock,
that means we own the lock; so to return with an error from here
without changing the count would result in a deadlock, as the lock
would then be ours, despite our error code implying otherwise.

Additionally, take care of part of the case where we have woken up
by mutex_destroy(), by setting thread to NULL and checking for it
in that case. There is still a race here, however.

May fix #16044, as it appears there is a case where ACPICA
calls this with a timeout of 0 (we should make this be
a mutex_trylock, anyway.)

Change-Id: I98215df218514c70ac1922bc3a6f10e01087e44b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2716
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# cf344027 13-Sep-2019 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Add padding in mutex fields for equivalent KDEBUG/non-KDEBUG sizing.

Non-KDEBUG kernels and kernel add-ons use atomic operations to acquire
and release the locks inline, so non-KDEBUG kernels/addons are only
compatible with other non-KDEBUG kernels/addons.

Following this change, though, KDEBUG kernels/addons should be able
to run under non-KDEBUG kernels/addons, too, since they always call
into the actual kernel functions and do not inline anything of
consequence.


# 4d0fd41d 14-Jun-2019 Augustin Cavalier <waddlesplash@gmail.com>

kernel/lock.h: Reorder function declarations so the comment is correct.


# c2cbf958 02-May-2019 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Add and fix ownership checks in mutex_destroy and mutex_transfer.

* mutex_destroy() only checked wether or not there were waiters,
not if the lock itself was presently held by another thread.
Now we do, which should make #15015 panic much earlier instead
of trying to use freed memory.
* mutex_transfer_lock() and recursive_lock_transfer_lock() did
not check that the calling thread actually owned the lock.
Now it does, which should trigger asserts if anyone tries
to do this.


# 86c12bf0 09-Dec-2018 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Initialize all fields of rw_lock in RW_LOCK_INITIALIZER.

Spotted by Clang.


# 8cf8e537 05-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

kernel/x86: Inline atomic functions and memory barriers


# 73ad2473 05-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

Remove remaining unnecessary 'volatile' qualifiers


# 31a75d40 23-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Protect lock internals with per-lock spinlock


# fd8b9d43 30-Mar-2012 Axel Dörfler <axeld@pinc-software.de>

Added a recursive_lock_transfer() function.


# 24df6592 11-Jun-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged signals-merge branch into trunk with the following changes:
* Reorganized the kernel locking related to threads and teams.
* We now discriminate correctly between process and thread signals. Signal
handlers have been moved to teams. Fixes #5679.
* Implemented real-time signal support, including signal queuing, SA_SIGINFO
support, sigqueue(), sigwaitinfo(), sigtimedwait(), waitid(), and the addition
of the real-time signal range. Closes #1935 and #2695.
* Gave SIGBUS a separate signal number. Fixes #6704.
* Implemented <time.h> clock and timer support, and fixed/completed alarm() and
[set]itimer(). Closes #5682.
* Implemented support for thread cancellation. Closes #5686.
* Moved send_signal() from <signal.h> to <OS.h>. Fixes #7554.
* Lots over smaller more or less related changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42116 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4e08fb85 22-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Added rw_lock_read_lock_with_timeout().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37680 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c4f98312 07-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Added new mutex_switch_from_read_lock() for unlocking a read lock and
starting to lock a mutex in an atomic operation.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34935 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2ea2527f 31-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

R/W lock implementation:
* Changed the rw_lock_{read,write}_unlock() return values to void. They
returned a value != B_OK only in case of user error and no-one checked them
anyway.
* Optimized rw_lock_read_[un]lock(). They are inline now and as long as
there's no contending write locker, they will only perform an atomic_add().
* Changed the semantics of nested locking after acquiring a write lock: Read
and write locks are counted separately, so read locks no longer implicitly
become write locks. This does e.g. make degrading a write lock to a read
lock by way of read_lock + write_unlock (as used in the VM) actually work.

These changes speed up the -j8 Haiku image build on my machine by a few
percent, but more interestingly they reduce the total kernel time by 25 %.
Apparently we get more contention on other locks, now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34830 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e182b46d 01-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Since there were no further complaints: Added mutex_lock_with_timeout().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34403 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 39e3058e 18-Oct-2009 Axel Dörfler <axeld@pinc-software.de>

* Reverted r33643 - while it doubled the performance for my test case (with
high contention of the read lock (I experimented with the VM page mapping
lock)), it actually hurt the compile performance pretty obviously.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33647 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 22ea0884 18-Oct-2009 Axel Dörfler <axeld@pinc-software.de>

* The rw_lock is now using a mutex to protect its reader/writer counts. This
makes the reader case a lot less expensive, and should relieve the thread
spinlock contention a bit.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33643 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3066f3db 15-Oct-2009 Axel Dörfler <axeld@pinc-software.de>

* Reverted r33547, this closes bug #4782 - this is obviously a regression in
GCC4.
* Adapted code accordingly.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33592 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4baa8659 12-Oct-2009 Axel Dörfler <axeld@pinc-software.de>

* Added casts to the *_INITIALIZER macros, so that they can also be used in
a member constructor list.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33547 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a7edf1f7 05-Mar-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Moved RECURSIVE_LOCK_HOLDER() macro to the header and fixed it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29407 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1894a0a9 20-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Consistently use KDEBUG. It is always defined and therefore must be
checked with "#if".


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28247 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 37de5a0d 30-Jul-2008 Axel Dörfler <axeld@pinc-software.de>

* The rw_lock now behaves just like a recursive locker if KDEBUG_RW_LOCK_DEBUG
is defined to 1; this allows asserting the read lock case, too.
* Added ASSERT_{READ|WRITE}_LOCKED_RW_LOCK() macros. The read assertion is only
working when KDEBUG_RW_LOCK_DEBUG is defined to 1, the write assertion works
always.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26686 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5c99d639 22-Jul-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged branch haiku/branches/developer/bonefish/vm into trunk. This
introduces the following relevant changes:
* VMCache:
- Renamed vm_cache to VMCache, merged it with vm_store and made it a
C++ class with virtual methods (replacing the store operations).
Turned the different store implementations into subclasses.
- Introduced MergeStore() callback, changed semantics of Commit().
- Changed locking and referencing semantics. A reference can only be
acquired/released with the cache locked. An unreferenced cache is
deleted and a mergeable cache merged when it is unlocked. This
removes the "busy" state of a cache and simplifies the page fault
code.
* Added VMAnonymousCache, which will implement swap support (work by
Zhao Shuai). It is not integrated and used yet, though.
* Enabled the mutex/recursive lock holder asserts.
* Fixed DoublyLinkedList::Swap().
* Generalized the low memory handler to a low resource handler. And made
semaphores and reserved memory handled resources. Made
vm_try_resource_memory() optionally wait (with timeout), and used that
feature to reserve memory for areas.
...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26572 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 78b32dd0 08-Jul-2008 Axel Dörfler <axeld@pinc-software.de>

* The rw_lock is now able to nest read/write locks when you have a write lock.
It follows the semantics of the BFS R/W lock, though, that is, if you unlock
your write lock before the read locks, the read locks effectively become
write locks, too.
* Added a mutex_transfer_lock() function that will allow you to unlock a mutex
in a different thread than the one which locked it (only matters if KDEBUG
is enabled, though).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26316 a95241bf-73f2-0310-859d-f6bbb57e9c96


# af370c70 07-Jul-2008 Axel Dörfler <axeld@pinc-software.de>

* Added a recursive_lock_trylock() function.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26297 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2daa4194 28-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added macros for static initialization of mutexes, recursive locks, and
R/W locks.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25691 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2b07b8e0 28-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Replaced all instances of benaphores in the kernel code by mutexes.
* Removed kernel benaphores.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25690 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1c18a5df 28-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Replaced R/W lock implementation. Should have a little less overhead
than a semaphore, and can already be used in the early boot process.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25689 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b0f5179a 28-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed recursive_lock to use a mutex instead of a semaphore.
* Adjusted code using recursive locks respectively. The initialization
cannot fail anymore, and it is possible to use recursive locks in the
early boot process (even uninitialized, if in BSS), which simplifies
things a little.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25687 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0c615a01 01-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Removed old mutex implementation and renamed cutex to mutex.
* Trivial adjustments of code using mutexes. Mostly removing the
mutex_init() return value check.
* Added mutex_lock_threads_locked(), which is called with the threads
spinlock being held. The spinlock is released while waiting, of
course. This function is useful in cases where the existence of the
mutex object is ensured by holding the threads spinlock.
* Changed the two instances in the VFS code where an IO context of
another team needs to be locked to use mutex_lock_threads_locked().
Before it required a semaphore-based mutex implementation.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25283 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ee96aa8f 01-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Replaced cutex::release_count by flags field. It is only one thread
that can unlock the mutex, so one bit is sufficient.
* Added cutex_init_etc() which has an additional "flags" parameter.
The only specifyable flag is CUTEX_FLAG_CLONE_NAME, which causes the
function to strdup() the given name and free() its copy in
cutex_destroy().
* cutex_destroy() does now unblock waiting threads.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25280 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8562499f 30-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Introduced a new locking primitive I called "cutex" (sorry for the
name, couldn't resist :-P). It's semantically equivalent to a mutex,
but doesn't need a semaphore (it uses thread blocking and a simple
queue instead). Initialization can't fail. In fact it is ready to use
without initialization when living in the bss segment, also in the
early boot process. It's as fast as a benaphore in cases of low lock
contention, and faster otherwise. Only disadvantage is the higher
immediate memory footprint of 16 bytes.
* Changed how the "thread" and "threads" debugger commands list the
objects they are waiting for. Cutexes are also included.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25276 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c0b5962c 29-Apr-2008 Axel Dörfler <axeld@pinc-software.de>

* Removed unused function benaphore_lock_etc(). A timeout is not really a
good idea for a benaphore.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25257 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ea2fe149 01-Feb-2008 Bruno G. Albuquerque <bga@bug-br.org.br>

It is a good idea to return a value. :)



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23821 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5ccd9956 01-Feb-2008 Axel Dörfler <axeld@pinc-software.de>

Benaphores are nice and fast, but they aren't useful for debugging at
all.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23820 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2b14cdd1 25-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* Added a mutex_trylock() function.
* Replaced release_sem() with release_sem_etc() for future addition of the
B_DO_NOT_RESCHEDULE flag.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22308 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c9788912 20-Jun-2007 Travis Geiselbrecht <geist@foobox.com>

re-enable kernel asserts.
Disabled by default, but all kernel devs are *highly* recommended to turn them on for your builds and see if it trips anything, and then fix it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21477 a95241bf-73f2-0310-859d-f6bbb57e9c96


# aa547f5f 07-Feb-2007 Axel Dörfler <axeld@pinc-software.de>

* mutex_lock() and recursive_lock_lock() now return a status_t and report failure.
* recursive_lock_unlock() now returns a void to mirror it's counterpart better;
use recursive_lock_get_recursion() if you're interested in the lock depth.
* switch_sem(), and release_sem() now don't do anything anymore in kernel startup
mode.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20099 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 74b043d9 17-Mar-2005 Axel Dörfler <axeld@pinc-software.de>

Removed execute property that was set accidently (since CVS days).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@11896 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 97dda329 13-Dec-2004 Axel Dörfler <axeld@pinc-software.de>

Some header work to reduce dependencies. Also fixes the debug build.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10434 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 814291de 18-May-2004 Axel Dörfler <axeld@pinc-software.de>

No need to include <kernel.h>.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7607 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f8a4dcfa 19-Aug-2003 Axel Dörfler <axeld@pinc-software.de>

Forgot about B_ANY_KERNEL_BLOCK_ADDRESS.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4326 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 749df8aa 27-Jun-2003 Axel Dörfler <axeld@pinc-software.de>

Added a benaphore_lock_etc() for a timeout possibility.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3690 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0281fb7b 26-Jun-2003 Axel Dörfler <axeld@pinc-software.de>

Removed the old benaphore/rw-lock definitions, added some preliminary new
ones (but real functions/inlines this time).
Renamed recursive_lock_create() to recursive_lock_init() for consistency,
and added a "name" parameter.
Changed "int" return to status_t where appropriate.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3676 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e96a8449 04-Oct-2002 Axel Dörfler <axeld@pinc-software.de>

Removed some type definitions from ktypes.h that are now located in OS.h.
Changed lock.h to like those changes.
Moved the create_sem_etc() from the public OS.h to the private kernel only
sem.h, cleaned it up a bit.
gcc doesn't seem to like the "extern inlines" with -O0 -g, so I replaced
an inline function in thread.h with "static inline" (which it does always
like).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1376 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bc934681 18-Jul-2002 Axel Dörfler <axeld@pinc-software.de>

Implemented geist's recent change to mutexes - they are now no longer
benaphores; benaphores aren't that beneficial in kernel land, the benaphores
are a way to reduce the number of kernel calls.
They can now only be released by the same thread who originally acquired it.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@312 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 52a38012 08-Jul-2002 ejakowatz <ejakowatz@nowhere.fake>

It is accomplished ...


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8cf8e537740789b1b103f0aa0736dbfcf55359c2 05-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

kernel/x86: Inline atomic functions and memory barriers


# 73ad2473e7874b3702cf5b0fdf4c81b747812ed9 05-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

Remove remaining unnecessary 'volatile' qualifiers


# 31a75d402f761a1087c449e44926a6bec0c31009 23-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Protect lock internals with per-lock spinlock


# fd8b9d4326f093222e23e2a33f53b0d03857443a 30-Mar-2012 Axel Dörfler <axeld@pinc-software.de>

Added a recursive_lock_transfer() function.


# 24df65921befcd0ad0c5c7866118f922da61cb96 11-Jun-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged signals-merge branch into trunk with the following changes:
* Reorganized the kernel locking related to threads and teams.
* We now discriminate correctly between process and thread signals. Signal
handlers have been moved to teams. Fixes #5679.
* Implemented real-time signal support, including signal queuing, SA_SIGINFO
support, sigqueue(), sigwaitinfo(), sigtimedwait(), waitid(), and the addition
of the real-time signal range. Closes #1935 and #2695.
* Gave SIGBUS a separate signal number. Fixes #6704.
* Implemented <time.h> clock and timer support, and fixed/completed alarm() and
[set]itimer(). Closes #5682.
* Implemented support for thread cancellation. Closes #5686.
* Moved send_signal() from <signal.h> to <OS.h>. Fixes #7554.
* Lots over smaller more or less related changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42116 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4e08fb85894083c9e677a17405834bbb4d41d575 22-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Added rw_lock_read_lock_with_timeout().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37680 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c4f983129280004a89041232f8420cac1548577c 07-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Added new mutex_switch_from_read_lock() for unlocking a read lock and
starting to lock a mutex in an atomic operation.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34935 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2ea2527fe423046558f682ebabede8f959a875e3 31-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

R/W lock implementation:
* Changed the rw_lock_{read,write}_unlock() return values to void. They
returned a value != B_OK only in case of user error and no-one checked them
anyway.
* Optimized rw_lock_read_[un]lock(). They are inline now and as long as
there's no contending write locker, they will only perform an atomic_add().
* Changed the semantics of nested locking after acquiring a write lock: Read
and write locks are counted separately, so read locks no longer implicitly
become write locks. This does e.g. make degrading a write lock to a read
lock by way of read_lock + write_unlock (as used in the VM) actually work.

These changes speed up the -j8 Haiku image build on my machine by a few
percent, but more interestingly they reduce the total kernel time by 25 %.
Apparently we get more contention on other locks, now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34830 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e182b46db679ad105a0dbc16cd8d569067f674c1 01-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Since there were no further complaints: Added mutex_lock_with_timeout().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34403 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 39e3058e5bdbb72a42a1cc26a6c4f30f9bec37c2 18-Oct-2009 Axel Dörfler <axeld@pinc-software.de>

* Reverted r33643 - while it doubled the performance for my test case (with
high contention of the read lock (I experimented with the VM page mapping
lock)), it actually hurt the compile performance pretty obviously.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33647 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 22ea08849837b37e4017f21c5f979cf5dd278b54 18-Oct-2009 Axel Dörfler <axeld@pinc-software.de>

* The rw_lock is now using a mutex to protect its reader/writer counts. This
makes the reader case a lot less expensive, and should relieve the thread
spinlock contention a bit.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33643 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3066f3dbf87e3b5a9ea12f7e81ded55f6d6f2bd9 15-Oct-2009 Axel Dörfler <axeld@pinc-software.de>

* Reverted r33547, this closes bug #4782 - this is obviously a regression in
GCC4.
* Adapted code accordingly.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33592 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4baa865937ae75ed5ec29c1d8858468d1e76ae8a 12-Oct-2009 Axel Dörfler <axeld@pinc-software.de>

* Added casts to the *_INITIALIZER macros, so that they can also be used in
a member constructor list.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33547 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a7edf1f7c029a4b48a79e7f56a51bf4767b7875e 05-Mar-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Moved RECURSIVE_LOCK_HOLDER() macro to the header and fixed it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29407 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1894a0a98b5b2102f83c00b7273ba7654334f469 20-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Consistently use KDEBUG. It is always defined and therefore must be
checked with "#if".


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28247 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 37de5a0d83bb1e9f862cc99af935fcfb246b8605 30-Jul-2008 Axel Dörfler <axeld@pinc-software.de>

* The rw_lock now behaves just like a recursive locker if KDEBUG_RW_LOCK_DEBUG
is defined to 1; this allows asserting the read lock case, too.
* Added ASSERT_{READ|WRITE}_LOCKED_RW_LOCK() macros. The read assertion is only
working when KDEBUG_RW_LOCK_DEBUG is defined to 1, the write assertion works
always.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26686 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5c99d639708df9b4e2cc847b38d510149d19ec78 22-Jul-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged branch haiku/branches/developer/bonefish/vm into trunk. This
introduces the following relevant changes:
* VMCache:
- Renamed vm_cache to VMCache, merged it with vm_store and made it a
C++ class with virtual methods (replacing the store operations).
Turned the different store implementations into subclasses.
- Introduced MergeStore() callback, changed semantics of Commit().
- Changed locking and referencing semantics. A reference can only be
acquired/released with the cache locked. An unreferenced cache is
deleted and a mergeable cache merged when it is unlocked. This
removes the "busy" state of a cache and simplifies the page fault
code.
* Added VMAnonymousCache, which will implement swap support (work by
Zhao Shuai). It is not integrated and used yet, though.
* Enabled the mutex/recursive lock holder asserts.
* Fixed DoublyLinkedList::Swap().
* Generalized the low memory handler to a low resource handler. And made
semaphores and reserved memory handled resources. Made
vm_try_resource_memory() optionally wait (with timeout), and used that
feature to reserve memory for areas.
...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26572 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 78b32dd026c23138d8102e48885f829e1acb5153 08-Jul-2008 Axel Dörfler <axeld@pinc-software.de>

* The rw_lock is now able to nest read/write locks when you have a write lock.
It follows the semantics of the BFS R/W lock, though, that is, if you unlock
your write lock before the read locks, the read locks effectively become
write locks, too.
* Added a mutex_transfer_lock() function that will allow you to unlock a mutex
in a different thread than the one which locked it (only matters if KDEBUG
is enabled, though).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26316 a95241bf-73f2-0310-859d-f6bbb57e9c96


# af370c702a1374fd8997cedd5f2ce5d5f153dcb3 07-Jul-2008 Axel Dörfler <axeld@pinc-software.de>

* Added a recursive_lock_trylock() function.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26297 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2daa4194d49584a2cb9fe2df6c3400081f44f5a9 28-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added macros for static initialization of mutexes, recursive locks, and
R/W locks.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25691 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2b07b8e0f1a7f1e76f31db24a21a42cbb01d7b9c 28-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Replaced all instances of benaphores in the kernel code by mutexes.
* Removed kernel benaphores.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25690 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1c18a5df87bf4fad865bcb55c286e8aef11d2d7f 28-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Replaced R/W lock implementation. Should have a little less overhead
than a semaphore, and can already be used in the early boot process.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25689 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b0f5179aa51eb680cdeea656a8b11fdbc6b56d63 28-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed recursive_lock to use a mutex instead of a semaphore.
* Adjusted code using recursive locks respectively. The initialization
cannot fail anymore, and it is possible to use recursive locks in the
early boot process (even uninitialized, if in BSS), which simplifies
things a little.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25687 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0c615a01ae49634aaf59fbe35b3d55b3bb8890df 01-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Removed old mutex implementation and renamed cutex to mutex.
* Trivial adjustments of code using mutexes. Mostly removing the
mutex_init() return value check.
* Added mutex_lock_threads_locked(), which is called with the threads
spinlock being held. The spinlock is released while waiting, of
course. This function is useful in cases where the existence of the
mutex object is ensured by holding the threads spinlock.
* Changed the two instances in the VFS code where an IO context of
another team needs to be locked to use mutex_lock_threads_locked().
Before it required a semaphore-based mutex implementation.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25283 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ee96aa8f6ef0f12cb28f0732a221e1f513cbde43 01-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Replaced cutex::release_count by flags field. It is only one thread
that can unlock the mutex, so one bit is sufficient.
* Added cutex_init_etc() which has an additional "flags" parameter.
The only specifyable flag is CUTEX_FLAG_CLONE_NAME, which causes the
function to strdup() the given name and free() its copy in
cutex_destroy().
* cutex_destroy() does now unblock waiting threads.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25280 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8562499f441ac23a80dd89310dbf2016b681fef9 30-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Introduced a new locking primitive I called "cutex" (sorry for the
name, couldn't resist :-P). It's semantically equivalent to a mutex,
but doesn't need a semaphore (it uses thread blocking and a simple
queue instead). Initialization can't fail. In fact it is ready to use
without initialization when living in the bss segment, also in the
early boot process. It's as fast as a benaphore in cases of low lock
contention, and faster otherwise. Only disadvantage is the higher
immediate memory footprint of 16 bytes.
* Changed how the "thread" and "threads" debugger commands list the
objects they are waiting for. Cutexes are also included.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25276 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c0b5962cd61a7838dbdd6bbd6c4ab4fc01f01dc8 29-Apr-2008 Axel Dörfler <axeld@pinc-software.de>

* Removed unused function benaphore_lock_etc(). A timeout is not really a
good idea for a benaphore.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25257 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ea2fe1498f48303ab17911142476242456edc54a 01-Feb-2008 Bruno G. Albuquerque <bga@bug-br.org.br>

It is a good idea to return a value. :)



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23821 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5ccd99565daf4d93a2ae72c9a8431d5088643417 01-Feb-2008 Axel Dörfler <axeld@pinc-software.de>

Benaphores are nice and fast, but they aren't useful for debugging at
all.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23820 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2b14cdd11c11de04514d1a92a3681abf8d284cfd 25-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* Added a mutex_trylock() function.
* Replaced release_sem() with release_sem_etc() for future addition of the
B_DO_NOT_RESCHEDULE flag.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22308 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c9788912f06232a93e07eae4483f8da39ea155c7 20-Jun-2007 Travis Geiselbrecht <geist@foobox.com>

re-enable kernel asserts.
Disabled by default, but all kernel devs are *highly* recommended to turn them on for your builds and see if it trips anything, and then fix it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21477 a95241bf-73f2-0310-859d-f6bbb57e9c96


# aa547f5fbbd3c9128651650f76264a3ec9695c87 07-Feb-2007 Axel Dörfler <axeld@pinc-software.de>

* mutex_lock() and recursive_lock_lock() now return a status_t and report failure.
* recursive_lock_unlock() now returns a void to mirror it's counterpart better;
use recursive_lock_get_recursion() if you're interested in the lock depth.
* switch_sem(), and release_sem() now don't do anything anymore in kernel startup
mode.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20099 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 74b043d98d35652a6892fc430537a02f5f9d9f76 17-Mar-2005 Axel Dörfler <axeld@pinc-software.de>

Removed execute property that was set accidently (since CVS days).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@11896 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 97dda329edce2caf11004390ff9dce1a5b1a86d1 13-Dec-2004 Axel Dörfler <axeld@pinc-software.de>

Some header work to reduce dependencies. Also fixes the debug build.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10434 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 814291ded8a91b1f9a1dcc11e1c0e153c7c896b8 18-May-2004 Axel Dörfler <axeld@pinc-software.de>

No need to include <kernel.h>.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7607 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f8a4dcfa28d71f5ed5bcec399846186b5bd95253 19-Aug-2003 Axel Dörfler <axeld@pinc-software.de>

Forgot about B_ANY_KERNEL_BLOCK_ADDRESS.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4326 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 749df8aa6b57d818f9906392b7c3dd7f1f6bb5e7 27-Jun-2003 Axel Dörfler <axeld@pinc-software.de>

Added a benaphore_lock_etc() for a timeout possibility.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3690 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0281fb7b323b465e45bc41a60761c786582a689e 26-Jun-2003 Axel Dörfler <axeld@pinc-software.de>

Removed the old benaphore/rw-lock definitions, added some preliminary new
ones (but real functions/inlines this time).
Renamed recursive_lock_create() to recursive_lock_init() for consistency,
and added a "name" parameter.
Changed "int" return to status_t where appropriate.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3676 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e96a844909dac884bab3c194f73b158e428e7481 04-Oct-2002 Axel Dörfler <axeld@pinc-software.de>

Removed some type definitions from ktypes.h that are now located in OS.h.
Changed lock.h to like those changes.
Moved the create_sem_etc() from the public OS.h to the private kernel only
sem.h, cleaned it up a bit.
gcc doesn't seem to like the "extern inlines" with -O0 -g, so I replaced
an inline function in thread.h with "static inline" (which it does always
like).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1376 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bc934681badb0da7e86d8de48c4ba0157765b5a0 18-Jul-2002 Axel Dörfler <axeld@pinc-software.de>

Implemented geist's recent change to mutexes - they are now no longer
benaphores; benaphores aren't that beneficial in kernel land, the benaphores
are a way to reduce the number of kernel calls.
They can now only be released by the same thread who originally acquired it.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@312 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 52a380120846174213ccce9c4aab0dda17c72083 08-Jul-2002 ejakowatz <ejakowatz@nowhere.fake>

It is accomplished ...


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10 a95241bf-73f2-0310-859d-f6bbb57e9c96