ConditionVariable: add classical wait interface with lockable
Change-Id: Id18264e786dba818138caf3908c7a89b18e2a1dd Reviewed-on: https://review.haiku-os.org/c/haiku/+/4921 Tested-by: Commit checker robot <[email protected]> Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
#include <util/OpenHashTable.h>
|
#include <util/OpenHashTable.h>
|
||||||
|
|
||||||
|
|
||||||
|
struct mutex;
|
||||||
|
struct recursive_lock;
|
||||||
struct ConditionVariable;
|
struct ConditionVariable;
|
||||||
|
|
||||||
|
|
||||||
@@ -72,6 +74,9 @@ public:
|
|||||||
status_t Wait(uint32 flags = 0, bigtime_t timeout = 0);
|
status_t Wait(uint32 flags = 0, bigtime_t timeout = 0);
|
||||||
// all-in one, i.e. doesn't need a
|
// all-in one, i.e. doesn't need a
|
||||||
// ConditionVariableEntry
|
// ConditionVariableEntry
|
||||||
|
status_t Wait(mutex* lock, uint32 flags = 0, bigtime_t timeout = 0);
|
||||||
|
status_t Wait(recursive_lock* lock, uint32 flags = 0, bigtime_t timeout = 0);
|
||||||
|
status_t Wait(spinlock* lock, uint32 flags = 0, bigtime_t timeout = 0);
|
||||||
|
|
||||||
const void* Object() const { return fObject; }
|
const void* Object() const { return fObject; }
|
||||||
const char* ObjectType() const { return fObjectType; }
|
const char* ObjectType() const { return fObjectType; }
|
||||||
|
|||||||
@@ -333,6 +333,49 @@ ConditionVariable::Wait(uint32 flags, bigtime_t timeout)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
ConditionVariable::Wait(mutex* lock, uint32 flags, bigtime_t timeout)
|
||||||
|
{
|
||||||
|
ConditionVariableEntry entry;
|
||||||
|
Add(&entry);
|
||||||
|
mutex_unlock(lock);
|
||||||
|
status_t res = entry.Wait(flags, timeout);
|
||||||
|
mutex_lock(lock);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
ConditionVariable::Wait(recursive_lock* lock, uint32 flags, bigtime_t timeout)
|
||||||
|
{
|
||||||
|
ConditionVariableEntry entry;
|
||||||
|
Add(&entry);
|
||||||
|
int32 recursion = recursive_lock_get_recursion(lock);
|
||||||
|
|
||||||
|
for (int32 i = 0; i < recursion; i++)
|
||||||
|
recursive_lock_unlock(lock);
|
||||||
|
|
||||||
|
status_t res = entry.Wait(flags, timeout);
|
||||||
|
|
||||||
|
for (int32 i = 0; i < recursion; i++)
|
||||||
|
recursive_lock_lock(lock);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
ConditionVariable::Wait(spinlock* lock, uint32 flags, bigtime_t timeout)
|
||||||
|
{
|
||||||
|
ConditionVariableEntry entry;
|
||||||
|
Add(&entry);
|
||||||
|
release_spinlock(lock);
|
||||||
|
status_t res = entry.Wait(flags, timeout);
|
||||||
|
acquire_spinlock(lock);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*static*/ void
|
/*static*/ void
|
||||||
ConditionVariable::NotifyOne(const void* object, status_t result)
|
ConditionVariable::NotifyOne(const void* object, status_t result)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user