Fixes in BLooper and its tests.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@84 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+27
-11
@@ -97,7 +97,7 @@ struct _loop_data_
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BLooper::BLooper(const char* name, int32 priority, int32 port_capacity)
|
BLooper::BLooper(const char* name, int32 priority, int32 port_capacity)
|
||||||
: BHandler(name), fMsgPort(-1)
|
: BHandler(name)
|
||||||
{
|
{
|
||||||
InitData(name, priority, port_capacity);
|
InitData(name, priority, port_capacity);
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ bool BLooper::IsMessageWaiting() const
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
count = port_buffer_size_etc(fMsgPort, B_TIMEOUT, 0);
|
count = port_buffer_size_etc(fMsgPort, B_TIMEOUT, 0);
|
||||||
} while (count == B_WOULD_BLOCK);
|
} while (count == B_INTERRUPTED);
|
||||||
|
|
||||||
return count > 0;
|
return count > 0;
|
||||||
}
|
}
|
||||||
@@ -302,7 +302,9 @@ void BLooper::AddHandler(BHandler* handler)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
bool BLooper::RemoveHandler(BHandler* handler)
|
bool BLooper::RemoveHandler(BHandler* handler)
|
||||||
{
|
{
|
||||||
AssertLocked();
|
// BeBook says looper must be locked for calls to this, but testing shows that
|
||||||
|
// just ain't so.
|
||||||
|
// AssertLocked();
|
||||||
|
|
||||||
// TODO: test
|
// TODO: test
|
||||||
// Need to ensure this algo reflects what actually happens
|
// Need to ensure this algo reflects what actually happens
|
||||||
@@ -633,7 +635,6 @@ bool BLooper::RemoveCommonFilter(BMessageFilter* filter)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BLooper::SetCommonFilterList(BList* filters)
|
void BLooper::SetCommonFilterList(BList* filters)
|
||||||
{
|
{
|
||||||
AssertLocked();
|
|
||||||
if (fCommonFilters)
|
if (fCommonFilters)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < fCommonFilters->CountItems(); ++i)
|
for (int32 i = 0; i < fCommonFilters->CountItems(); ++i)
|
||||||
@@ -885,6 +886,7 @@ void BLooper::InitData()
|
|||||||
fPreferred = NULL;
|
fPreferred = NULL;
|
||||||
fTaskID = B_ERROR;
|
fTaskID = B_ERROR;
|
||||||
fTerminating = false;
|
fTerminating = false;
|
||||||
|
fMsgPort = -1;
|
||||||
|
|
||||||
if (sTeamID == -1)
|
if (sTeamID == -1)
|
||||||
{
|
{
|
||||||
@@ -893,22 +895,26 @@ void BLooper::InitData()
|
|||||||
sTeamID = info.team;
|
sTeamID = info.team;
|
||||||
}
|
}
|
||||||
|
|
||||||
BAutolock ListLock(sLooperListLock);
|
|
||||||
AddLooper(this);
|
|
||||||
Lock();
|
|
||||||
AddHandler(this);
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BLooper::InitData(const char* name, int32 priority, int32 port_capacity)
|
void BLooper::InitData(const char* name, int32 priority, int32 port_capacity)
|
||||||
{
|
{
|
||||||
|
InitData();
|
||||||
|
|
||||||
fLockSem = create_sem(1, name);
|
fLockSem = create_sem(1, name);
|
||||||
|
|
||||||
if (fMsgPort <= 0)
|
if (port_capacity <= 0)
|
||||||
{
|
{
|
||||||
fMsgPort = create_port(port_capacity, name ? name : "LooperPort");
|
port_capacity = B_LOOPER_PORT_DEFAULT_CAPACITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
InitData();
|
fMsgPort = create_port(port_capacity, name ? name : "LooperPort");
|
||||||
|
|
||||||
|
fInitPriority = priority;
|
||||||
|
|
||||||
|
BAutolock ListLock(sLooperListLock);
|
||||||
|
AddLooper(this);
|
||||||
|
AddHandler(this);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BLooper::AddMessage(BMessage* msg)
|
void BLooper::AddMessage(BMessage* msg)
|
||||||
@@ -1275,8 +1281,18 @@ DBG(OUT("BLooper::AddLooper(): looper added at %ld\n", looperCount));
|
|||||||
result->looper = loop;
|
result->looper = loop;
|
||||||
result->thread = loop->fTaskID;
|
result->thread = loop->fTaskID;
|
||||||
++looperCount;
|
++looperCount;
|
||||||
|
|
||||||
|
// Moved this here from InitData() because it occured to me that the
|
||||||
|
// looper could potentially get removed from the list between now
|
||||||
|
// and when we locked it in InitData(). By doing it here, while the
|
||||||
|
// the looper list is locked, we can be certain this won't happen.
|
||||||
|
loop->Lock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debugger("sLooperList is not locked!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
bool BLooper::IsLooperValid(const BLooper* l)
|
bool BLooper::IsLooperValid(const BLooper* l)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
// System Includes -------------------------------------------------------------
|
||||||
#include <Looper.h>
|
#include <Looper.h>
|
||||||
@@ -17,13 +18,18 @@
|
|||||||
// Local Defines ---------------------------------------------------------------
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
// Globals ---------------------------------------------------------------------
|
// Globals ---------------------------------------------------------------------
|
||||||
|
port_id _get_looper_port_(const BLooper* looper);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
//case 1: looper is unlocked and queue is empty
|
//case 1: looper is unlocked and queue is empty
|
||||||
void TIsMessageWaitingTest::IsMessageWaiting1()
|
void TIsMessageWaitingTest::IsMessageWaiting1()
|
||||||
{
|
{
|
||||||
BLooper Looper;
|
BLooper Looper;
|
||||||
|
#ifndef TEST_R5
|
||||||
assert(!Looper.IsMessageWaiting());
|
assert(!Looper.IsMessageWaiting());
|
||||||
|
#else
|
||||||
|
assert(Looper.IsMessageWaiting());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
//case 2: looper is unlocked and queue is filled
|
//case 2: looper is unlocked and queue is filled
|
||||||
@@ -39,7 +45,11 @@ void TIsMessageWaitingTest::IsMessageWaiting3()
|
|||||||
{
|
{
|
||||||
BLooper Looper;
|
BLooper Looper;
|
||||||
Looper.Lock();
|
Looper.Lock();
|
||||||
|
#ifndef TEST_R5
|
||||||
assert(!Looper.IsMessageWaiting());
|
assert(!Looper.IsMessageWaiting());
|
||||||
|
#else
|
||||||
|
assert(Looper.IsMessageWaiting());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
//case 4: looper is locked and queue is filled
|
//case 4: looper is locked and queue is filled
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ void TRemoveHandlerTest::RemoveHandler1()
|
|||||||
Handler.AddFilter(MessageFilter);
|
Handler.AddFilter(MessageFilter);
|
||||||
Looper.AddHandler(&Handler);
|
Looper.AddHandler(&Handler);
|
||||||
Looper.RemoveHandler(&Handler);
|
Looper.RemoveHandler(&Handler);
|
||||||
assert(Handler.FilterList() == NULL);
|
assert(Handler.FilterList());
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
Test* TRemoveHandlerTest::Suite()
|
Test* TRemoveHandlerTest::Suite()
|
||||||
|
|||||||
Reference in New Issue
Block a user