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:
@@ -59,11 +59,12 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void Publish(const void* object,
|
void Publish(const void* object,
|
||||||
const char* objectType);
|
const char* objectType);
|
||||||
void Unpublish();
|
void Unpublish(bool threadsLocked);
|
||||||
void Notify(bool all);
|
void Notify(bool all, bool threadsLocked);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _Notify(bool all, status_t result);
|
void _Notify(bool all, bool threadsLocked,
|
||||||
|
status_t result);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const void* fObject;
|
const void* fObject;
|
||||||
@@ -81,9 +82,9 @@ public:
|
|||||||
inline void Publish(const Type* object,
|
inline void Publish(const Type* object,
|
||||||
const char* objectType);
|
const char* objectType);
|
||||||
|
|
||||||
inline void Unpublish();
|
inline void Unpublish(bool threadsLocked = false);
|
||||||
inline void NotifyOne();
|
inline void NotifyOne(bool threadsLocked = false);
|
||||||
inline void NotifyAll();
|
inline void NotifyAll(bool threadsLocked = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -108,25 +109,25 @@ ConditionVariable<Type>::Publish(const Type* object, const char* objectType)
|
|||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
inline void
|
inline void
|
||||||
ConditionVariable<Type>::Unpublish()
|
ConditionVariable<Type>::Unpublish(bool threadsLocked)
|
||||||
{
|
{
|
||||||
PrivateConditionVariable::Unpublish();
|
PrivateConditionVariable::Unpublish(threadsLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
inline void
|
inline void
|
||||||
ConditionVariable<Type>::NotifyOne()
|
ConditionVariable<Type>::NotifyOne(bool threadsLocked)
|
||||||
{
|
{
|
||||||
PrivateConditionVariable::Notify(false);
|
PrivateConditionVariable::Notify(false, threadsLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
inline void
|
inline void
|
||||||
ConditionVariable<Type>::NotifyAll()
|
ConditionVariable<Type>::NotifyAll(bool threadsLocked)
|
||||||
{
|
{
|
||||||
PrivateConditionVariable::Notify(true);
|
PrivateConditionVariable::Notify(true, threadsLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ PrivateConditionVariable::Publish(const void* object, const char* objectType)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PrivateConditionVariable::Unpublish()
|
PrivateConditionVariable::Unpublish(bool threadsLocked)
|
||||||
{
|
{
|
||||||
ASSERT(fObject != NULL);
|
ASSERT(fObject != NULL);
|
||||||
|
|
||||||
@@ -300,12 +300,12 @@ PrivateConditionVariable::Unpublish()
|
|||||||
fObjectType = NULL;
|
fObjectType = NULL;
|
||||||
|
|
||||||
if (fEntries)
|
if (fEntries)
|
||||||
_Notify(true, B_ENTRY_NOT_FOUND);
|
_Notify(true, threadsLocked, B_ENTRY_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PrivateConditionVariable::Notify(bool all)
|
PrivateConditionVariable::Notify(bool all, bool threadsLocked)
|
||||||
{
|
{
|
||||||
ASSERT(fObject != NULL);
|
ASSERT(fObject != NULL);
|
||||||
|
|
||||||
@@ -321,16 +321,17 @@ PrivateConditionVariable::Notify(bool all)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fEntries)
|
if (fEntries)
|
||||||
_Notify(all, B_OK);
|
_Notify(all, threadsLocked, B_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Called with interrupts disabled and the condition variable spinlock held.
|
//! Called with interrupts disabled and the condition variable spinlock held.
|
||||||
void
|
void
|
||||||
PrivateConditionVariable::_Notify(bool all, status_t result)
|
PrivateConditionVariable::_Notify(bool all, bool threadsLocked, status_t result)
|
||||||
{
|
{
|
||||||
// dequeue and wake up the blocked threads
|
// dequeue and wake up the blocked threads
|
||||||
GRAB_THREAD_LOCK();
|
if (!threadsLocked)
|
||||||
|
GRAB_THREAD_LOCK();
|
||||||
|
|
||||||
while (PrivateConditionVariableEntry* entry = fEntries) {
|
while (PrivateConditionVariableEntry* entry = fEntries) {
|
||||||
fEntries = entry->fVariableNext;
|
fEntries = entry->fVariableNext;
|
||||||
@@ -366,7 +367,8 @@ PrivateConditionVariable::_Notify(bool all, status_t result)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
RELEASE_THREAD_LOCK();
|
if (!threadsLocked)
|
||||||
|
RELEASE_THREAD_LOCK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user