Notify*() and Unpublish() acquire the threads lock. So they need to know

whether the lock is already being held.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22087 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2007-08-28 02:25:14 +00:00
parent be8990115c
commit c9e5503e5e
2 changed files with 22 additions and 19 deletions

View File

@ -59,11 +59,12 @@ public:
protected:
void Publish(const void* object,
const char* objectType);
void Unpublish();
void Notify(bool all);
void Unpublish(bool threadsLocked);
void Notify(bool all, bool threadsLocked);
private:
void _Notify(bool all, status_t result);
void _Notify(bool all, bool threadsLocked,
status_t result);
protected:
const void* fObject;
@ -81,9 +82,9 @@ public:
inline void Publish(const Type* object,
const char* objectType);
inline void Unpublish();
inline void NotifyOne();
inline void NotifyAll();
inline void Unpublish(bool threadsLocked = false);
inline void NotifyOne(bool threadsLocked = false);
inline void NotifyAll(bool threadsLocked = false);
};
@ -108,25 +109,25 @@ ConditionVariable<Type>::Publish(const Type* object, const char* objectType)
template<typename Type>
inline void
ConditionVariable<Type>::Unpublish()
ConditionVariable<Type>::Unpublish(bool threadsLocked)
{
PrivateConditionVariable::Unpublish();
PrivateConditionVariable::Unpublish(threadsLocked);
}
template<typename Type>
inline void
ConditionVariable<Type>::NotifyOne()
ConditionVariable<Type>::NotifyOne(bool threadsLocked)
{
PrivateConditionVariable::Notify(false);
PrivateConditionVariable::Notify(false, threadsLocked);
}
template<typename Type>
inline void
ConditionVariable<Type>::NotifyAll()
ConditionVariable<Type>::NotifyAll(bool threadsLocked)
{
PrivateConditionVariable::Notify(true);
PrivateConditionVariable::Notify(true, threadsLocked);
}

View File

@ -280,7 +280,7 @@ PrivateConditionVariable::Publish(const void* object, const char* objectType)
void
PrivateConditionVariable::Unpublish()
PrivateConditionVariable::Unpublish(bool threadsLocked)
{
ASSERT(fObject != NULL);
@ -300,12 +300,12 @@ PrivateConditionVariable::Unpublish()
fObjectType = NULL;
if (fEntries)
_Notify(true, B_ENTRY_NOT_FOUND);
_Notify(true, threadsLocked, B_ENTRY_NOT_FOUND);
}
void
PrivateConditionVariable::Notify(bool all)
PrivateConditionVariable::Notify(bool all, bool threadsLocked)
{
ASSERT(fObject != NULL);
@ -321,16 +321,17 @@ PrivateConditionVariable::Notify(bool all)
#endif
if (fEntries)
_Notify(all, B_OK);
_Notify(all, threadsLocked, B_OK);
}
//! Called with interrupts disabled and the condition variable spinlock held.
void
PrivateConditionVariable::_Notify(bool all, status_t result)
PrivateConditionVariable::_Notify(bool all, bool threadsLocked, status_t result)
{
// dequeue and wake up the blocked threads
GRAB_THREAD_LOCK();
if (!threadsLocked)
GRAB_THREAD_LOCK();
while (PrivateConditionVariableEntry* entry = fEntries) {
fEntries = entry->fVariableNext;
@ -366,7 +367,8 @@ PrivateConditionVariable::_Notify(bool all, status_t result)
break;
}
RELEASE_THREAD_LOCK();
if (!threadsLocked)
RELEASE_THREAD_LOCK();
}