Make use of the wait status field so it can be provided in Notify() and then
read out in the ConditionVariableEntry::WaitStatus(). That way you can notify with a specific status that can be read out on the other end. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33718 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ec39794897
commit
5ee1f125e5
|
@ -32,7 +32,9 @@ public:
|
||||||
status_t Wait(const void* object, uint32 flags = 0,
|
status_t Wait(const void* object, uint32 flags = 0,
|
||||||
bigtime_t timeout = 0);
|
bigtime_t timeout = 0);
|
||||||
|
|
||||||
inline ConditionVariable* Variable() const { return fVariable; }
|
inline status_t WaitStatus() const { return fWaitStatus; }
|
||||||
|
|
||||||
|
inline ConditionVariable* Variable() const { return fVariable; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void AddToVariable(ConditionVariable* variable);
|
inline void AddToVariable(ConditionVariable* variable);
|
||||||
|
@ -56,8 +58,10 @@ public:
|
||||||
const char* objectType);
|
const char* objectType);
|
||||||
void Unpublish(bool threadsLocked = false);
|
void Unpublish(bool threadsLocked = false);
|
||||||
|
|
||||||
inline void NotifyOne(bool threadsLocked = false);
|
inline void NotifyOne(bool threadsLocked = false,
|
||||||
inline void NotifyAll(bool threadsLocked = false);
|
status_t result = B_OK);
|
||||||
|
inline void NotifyAll(bool threadsLocked = false,
|
||||||
|
status_t result = B_OK);
|
||||||
|
|
||||||
void Add(ConditionVariableEntry* entry);
|
void Add(ConditionVariableEntry* entry);
|
||||||
|
|
||||||
|
@ -72,8 +76,9 @@ public:
|
||||||
void Dump() const;
|
void Dump() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _Notify(bool all, bool threadsLocked);
|
void _Notify(bool all, bool threadsLocked,
|
||||||
void _NotifyChecked(bool all, status_t result);
|
status_t result);
|
||||||
|
void _NotifyLocked(bool all, status_t result);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef DoublyLinkedList<ConditionVariableEntry> EntryList;
|
typedef DoublyLinkedList<ConditionVariableEntry> EntryList;
|
||||||
|
@ -109,16 +114,16 @@ ConditionVariableEntry::~ConditionVariableEntry()
|
||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
ConditionVariable::NotifyOne(bool threadsLocked)
|
ConditionVariable::NotifyOne(bool threadsLocked, status_t result)
|
||||||
{
|
{
|
||||||
_Notify(false, threadsLocked);
|
_Notify(false, threadsLocked, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
ConditionVariable::NotifyAll(bool threadsLocked)
|
ConditionVariable::NotifyAll(bool threadsLocked, status_t result)
|
||||||
{
|
{
|
||||||
_Notify(true, threadsLocked);
|
_Notify(true, threadsLocked, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -241,7 +241,7 @@ ConditionVariable::Unpublish(bool threadsLocked)
|
||||||
fObjectType = NULL;
|
fObjectType = NULL;
|
||||||
|
|
||||||
if (!fEntries.IsEmpty())
|
if (!fEntries.IsEmpty())
|
||||||
_NotifyChecked(true, B_ENTRY_NOT_FOUND);
|
_NotifyLocked(true, B_ENTRY_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -293,14 +293,20 @@ ConditionVariable::Dump() const
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ConditionVariable::_Notify(bool all, bool threadsLocked)
|
ConditionVariable::_Notify(bool all, bool threadsLocked, status_t result)
|
||||||
{
|
{
|
||||||
InterruptsLocker _;
|
InterruptsLocker _;
|
||||||
SpinLocker threadLocker(threadsLocked ? NULL : &gThreadSpinlock);
|
SpinLocker threadLocker(threadsLocked ? NULL : &gThreadSpinlock);
|
||||||
SpinLocker locker(sConditionVariablesLock);
|
SpinLocker locker(sConditionVariablesLock);
|
||||||
|
|
||||||
if (!fEntries.IsEmpty())
|
if (!fEntries.IsEmpty()) {
|
||||||
_NotifyChecked(all, B_OK);
|
if (result > B_OK) {
|
||||||
|
panic("tried to notify with invalid result %ld\n", result);
|
||||||
|
result = B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
_NotifyLocked(all, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -308,7 +314,7 @@ ConditionVariable::_Notify(bool all, bool threadsLocked)
|
||||||
thread lock held.
|
thread lock held.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ConditionVariable::_NotifyChecked(bool all, status_t result)
|
ConditionVariable::_NotifyLocked(bool all, status_t result)
|
||||||
{
|
{
|
||||||
// dequeue and wake up the blocked threads
|
// dequeue and wake up the blocked threads
|
||||||
while (ConditionVariableEntry* entry = fEntries.RemoveHead()) {
|
while (ConditionVariableEntry* entry = fEntries.RemoveHead()) {
|
||||||
|
|
Loading…
Reference in New Issue