Refactoring condition variable subsystem of FreeBSD compat layer. Basically it

separates the usage of published and unpublished ConditionalVariables into
different functions. 
This allows to stick to the semantics of FreeBSD's condition variable subsystem
where it isn't needed to call cv_destroy. With the refactoring now there aren't
orphaned published ConditionalVariable left over, when shutting down the compat
layer.
Though, allocated unpublished struct cv's aren't cleaned up yet. This will be
addressed in a next commit.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34468 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Colin Günther 2009-12-03 17:47:20 +00:00
parent f69032f22b
commit c9986738a3
5 changed files with 41 additions and 31 deletions

View File

@ -13,19 +13,25 @@ extern "C" {
#include <condition_variable.h>
#include "condvar.h"
#include "Condvar.h"
#include "device.h"
#define ticks_to_usecs(t) (1000000*((bigtime_t)t) / hz)
void
conditionInit(struct cv* variable, const char* description)
{
variable->condition = new(std::nothrow) ConditionVariable();
variable->condition->Init(variable, description);
}
void
conditionPublish(struct cv* variable, const void* waitChannel,
const char* description)
{
variable->waitChannel = waitChannel;
variable->description = description;
variable->condition = new(std::nothrow) ConditionVariable();
variable->condition->Publish(waitChannel, description);
}
@ -42,10 +48,8 @@ conditionUnpublish(const struct cv* variable)
int
conditionTimedWait(const struct cv* variable, const int timeout)
{
ConditionVariableEntry variableEntry;
status_t status = variableEntry.Wait(variable->waitChannel,
B_RELATIVE_TIMEOUT, ticks_to_usecs(timeout));
status_t status = variable->condition->Wait(B_RELATIVE_TIMEOUT,
ticks_to_usecs(timeout));
if (status != B_OK)
status = EWOULDBLOCK;
@ -55,22 +59,34 @@ conditionTimedWait(const struct cv* variable, const int timeout)
void
conditionWait(const struct cv* variable)
{
variable->condition->Wait();
}
void
conditionNotifyOne(const struct cv* variable)
{
variable->condition->NotifyOne();
}
int
publishedConditionTimedWait(const void* waitChannel, const int timeout)
{
ConditionVariableEntry variableEntry;
variableEntry.Wait(variable->waitChannel);
status_t status = variableEntry.Wait(waitChannel, B_RELATIVE_TIMEOUT,
ticks_to_usecs(timeout));
if (status != B_OK)
status = EWOULDBLOCK;
return status;
}
void
conditionNotifyOne(const void* waitChannel)
{
ConditionVariable::NotifyOne(waitChannel);
}
void
conditionNotifyAll(const void* waitChannel)
publishedConditionNotifyAll(const void* waitChannel)
{
ConditionVariable::NotifyAll(waitChannel);
}

View File

@ -10,12 +10,14 @@
extern "C" {
#endif
void conditionInit(struct cv*, const char*);
void conditionPublish(struct cv*, const void*, const char*);
void conditionUnpublish(const struct cv*);
void conditionNotifyOne(const void*);
void conditionNotifyAll(const void*);
int conditionTimedWait(const struct cv*, const int);
void conditionWait(const struct cv*);
void conditionNotifyOne(const struct cv*);
int publishedConditionTimedWait(const void*, const int);
void publishedConditionNotifyAll(const void*);
#ifdef __cplusplus
}

View File

@ -11,8 +11,6 @@
struct cv {
struct ConditionVariable* condition;
const char* description;
const void* waitChannel;
};

View File

@ -7,18 +7,12 @@
#include <compat/sys/mutex.h>
#include <compat/sys/condvar.h>
#include "condvar.h"
#include "Condvar.h"
void cv_init(struct cv* variable, const char* description)
{
conditionPublish(variable, variable, description);
}
void cv_destroy(struct cv* variable)
{
conditionUnpublish(variable);
conditionInit(variable, description);
}

View File

@ -9,7 +9,7 @@
#include <compat/sys/mutex.h>
#include <compat/sys/condvar.h>
#include "condvar.h"
#include "Condvar.h"
int
@ -22,7 +22,7 @@ msleep(void* identifier, struct mtx* mutex, int priority,
conditionPublish(&sleep, identifier, description);
mtx_unlock(mutex);
status = conditionTimedWait(&sleep, timeout);
status = publishedConditionTimedWait(identifier, timeout);
mtx_lock(mutex);
conditionUnpublish(&sleep);
@ -34,7 +34,7 @@ msleep(void* identifier, struct mtx* mutex, int priority,
void
wakeup(void* identifier)
{
conditionNotifyAll(identifier);
publishedConditionNotifyAll(identifier);
}