From 752c497115c3496af9dad28de8c27276e3382a7a Mon Sep 17 00:00:00 2001 From: ejakowatz Date: Sun, 4 Aug 2002 17:16:56 +0000 Subject: [PATCH] The last remnants of the Old Repub ... er, static looper list data has been removed. The old static BLooper functions for managing the looper list are still there, but they are officially deprecated. The approved interface for this information is BPrivate::BLooperList, accessible via the global BPrivate::gLooperList variable. Being as it lives in BPrivate, it is for API-internal use *ONLY*. User apps use it to their own risk. Also added a small test to make sure that the size of BLooper stays the same. I will probably add this to other classes as well; doesn't hurt to be safe. =) git-svn-id: file:///srv/svn/repos/haiku/trunk/current@572 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/app/Looper.h | 5 +- src/kits/app/Application.cpp | 5 +- src/kits/app/Looper.cpp | 215 ------------------ src/tests/kits/app/Jamfile | 1 + src/tests/kits/app/blooper/LooperSizeTest.cpp | 42 ++++ src/tests/kits/app/blooper/LooperSizeTest.h | 41 ++++ src/tests/kits/app/blooper/LooperTest.cpp | 2 + 7 files changed, 91 insertions(+), 220 deletions(-) create mode 100644 src/tests/kits/app/blooper/LooperSizeTest.cpp create mode 100644 src/tests/kits/app/blooper/LooperSizeTest.h diff --git a/headers/os/app/Looper.h b/headers/os/app/Looper.h index 792857fd46..5d038ae645 100644 --- a/headers/os/app/Looper.h +++ b/headers/os/app/Looper.h @@ -193,12 +193,9 @@ virtual void task_looper(); void UnlockFully(); static uint32 sLooperID; -static uint32 sLooperListSize; -static uint32 sLooperCount; -static _loop_data_* sLooperList; -static BLocker sLooperListLock; static team_id sTeamID; +// DEPRECATED static void AddLooper(BLooper* l); static bool IsLooperValid(const BLooper* l); static void RemoveLooper(BLooper* l); diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp index 3c8f060581..af5844cf0d 100644 --- a/src/kits/app/Application.cpp +++ b/src/kits/app/Application.cpp @@ -160,6 +160,9 @@ property_info gApplicationPropInfo[] = extern const int __libc_argc; extern const char * const *__libc_argv; +class BMenuWindow : public BWindow +{ +}; //------------------------------------------------------------------------------ // debugging @@ -829,7 +832,7 @@ BWindow* BApplication::window_at(uint32 index, bool incl_menus) const { if (count == index) { - Window = Looper; + Window = dynamic_cast(Looper); } else { diff --git a/src/kits/app/Looper.cpp b/src/kits/app/Looper.cpp index 65cbd27dd0..84e3ee3aff 100644 --- a/src/kits/app/Looper.cpp +++ b/src/kits/app/Looper.cpp @@ -69,25 +69,11 @@ using BPrivate::gLooperList; using BPrivate::BObjectLocker; using BPrivate::BLooperList; -typedef bool (*find_loop_pred)(_loop_data_* data, void* data); -_loop_data_* find_loop_data(_loop_data_* begin, _loop_data_* end, - find_loop_pred, void* data); -bool looper_by_port_pred(_loop_data_* looper, void* data); -bool looper_by_tid_pred(_loop_data_* looper, void* data); -bool looper_by_name_pred(_loop_data_* looper, void* data); -bool looper_pred(_loop_data_* looper, void* data); -bool empty_slot_pred(_loop_data_* looper, void* data); -bool copy_list_pred(_loop_data_* looper, void* data); - port_id _get_looper_port_(const BLooper* looper); bool _use_preferred_target_(BMessage* msg) { return msg->fPreferred; } int32 _get_message_target_(BMessage* msg) { return msg->fTarget; } uint32 BLooper::sLooperID = B_ERROR; -uint32 BLooper::sLooperListSize = 0; -uint32 BLooper::sLooperCount = 0; -_loop_data_* BLooper::sLooperList = NULL; -BLocker BLooper::sLooperListLock; team_id BLooper::sTeamID = B_ERROR; static property_info gLooperPropInfo[] = @@ -154,9 +140,6 @@ BLooper::~BLooper() SetCommonFilterList(NULL); BObjectLocker ListLock(gLooperList); -#if 0 - BAutolock ListLock(sLooperListLock); -#endif RemoveHandler(this); RemoveLooper(this); @@ -599,9 +582,6 @@ bool BLooper::IsLocked() const // We have to lock the list for the call to IsLooperValid(). Has the side // effect of not letting the looper get deleted while we're here. BObjectLocker ListLock(gLooperList); -#if 0 - BAutolock ListLock(sLooperListLock); -#endif if (!ListLock.IsLocked()) { @@ -641,19 +621,6 @@ BLooper* BLooper::LooperForThread(thread_id tid) { return gLooperList.LooperForThread(tid); } -#if 0 - BAutolock ListLock(sLooperListLock); - if (ListLock.IsLocked()) - { - _loop_data_* result = find_loop_data(sLooperList, - sLooperList + sLooperCount, - looper_by_tid_pred, (void*)tid); - if (result) - { - return result->looper; - } - } -#endif return NULL; } @@ -872,9 +839,6 @@ status_t BLooper::_PostMessage(BMessage* msg, BHandler* handler, BHandler* reply_to) { BObjectLocker ListLock(gLooperList); -#if 0 - BAutolock ListLock(sLooperListLock); -#endif if (!ListLock.IsLocked()) { return B_BAD_VALUE; @@ -948,9 +912,6 @@ DBG(OUT("BLooper::_Lock() done 1\n")); */ { BObjectLocker ListLock(gLooperList); -#if 0 - BAutolock ListLock(sLooperListLock); -#endif if (!ListLock.IsLocked()) { // If we can't lock, the semaphore is probably @@ -1076,9 +1037,6 @@ void BLooper::InitData(const char* name, int32 priority, int32 port_capacity) fInitPriority = priority; BObjectLocker ListLock(gLooperList); -#if 0 - BAutolock ListLock(sLooperListLock); -#endif AddLooper(this); AddHandler(this); } @@ -1419,64 +1377,6 @@ void BLooper::AddLooper(BLooper* loop) { gLooperList.AddLooper(loop); } -#if 0 - if (sLooperListLock.IsLocked()) - { -#if defined(CHECK_ADD_LOOPER) - // First see if it's already been added - if (!IsLooperValid(loop)) -#endif - { - _loop_data_* result = find_loop_data(sLooperList, - sLooperList + sLooperCount, - empty_slot_pred, NULL); - - uint32& looperCount = sLooperCount; // hokey debugging aids - uint32& looperListSize = sLooperListSize; - if (!result) - { - // No empty slots; time to expand - if (looperCount == looperListSize) - { - // Allocate the expanded list - _loop_data_* temp = - new _loop_data_[looperListSize + DATA_BLOCK_SIZE]; - if (!temp) - { - // Not good - debugger("unable to allocate looper list"); - return; - } - - // Transfer the existing data - memcpy(temp, sLooperList, - sizeof (_loop_data_*) * looperListSize); - delete[] sLooperList; - sLooperList = temp; - looperListSize += DATA_BLOCK_SIZE; - } - - // Whether we expanded or not, the "new" one will be at the end -DBG(OUT("BLooper::AddLooper(): looper added at %ld\n", looperCount)); - result = &sLooperList[looperCount]; - } - - result->looper = loop; - result->thread = loop->fTaskID; - ++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!"); - } -#endif } //------------------------------------------------------------------------------ bool BLooper::IsLooperValid(const BLooper* l) @@ -1485,13 +1385,6 @@ bool BLooper::IsLooperValid(const BLooper* l) { return gLooperList.IsLooperValid(l); } -#if 0 - if (sLooperListLock.IsLocked()) - { - return find_loop_data(sLooperList, sLooperList + sLooperCount, - looper_pred, (void*)l); - } -#endif return false; } @@ -1502,27 +1395,6 @@ void BLooper::RemoveLooper(BLooper* l) { gLooperList.RemoveLooper(l); } -#if 0 - if (sLooperListLock.IsLocked()) - { - _loop_data_* result = find_loop_data(sLooperList, - sLooperList + sLooperCount, - looper_pred, l); - if (result) - { - result->looper = NULL; - --sLooperCount; - } - - // Nothing left? Clean up; the app is probably exiting anyway - if (sLooperCount == 0) - { - delete[] sLooperList; - sLooperList = NULL; - sLooperListSize = 0; - } - } -#endif } //------------------------------------------------------------------------------ void BLooper::GetLooperList(BList* list) @@ -1532,14 +1404,6 @@ void BLooper::GetLooperList(BList* list) { gLooperList.GetLooperList(list); } -#if 0 - BAutolock ListLock(sLooperListLock); - if (ListLock.IsLocked()) - { - find_loop_data(sLooperList, sLooperList + sLooperCount, - copy_list_pred, (void*)list); - } -#endif } //------------------------------------------------------------------------------ BLooper* BLooper::LooperForName(const char* name) @@ -1548,18 +1412,6 @@ BLooper* BLooper::LooperForName(const char* name) { return gLooperList.LooperForName(name); } -#if 0 - if (sLooperListLock.IsLocked()) - { - _loop_data_* result = find_loop_data(sLooperList, - sLooperList + sLooperCount, - looper_by_name_pred, (void*)name); - if (result) - { - return result->looper; - } - } -#endif return NULL; } @@ -1570,79 +1422,12 @@ BLooper* BLooper::LooperForPort(port_id port) { return gLooperList.LooperForPort(port); } -#if 0 - if (sLooperListLock.IsLocked()) - { - _loop_data_* result = find_loop_data(sLooperList, - sLooperList + sLooperCount, - looper_by_port_pred, (void*)port); - if (result) - { - return result->looper; - } - } -#endif return NULL; } //------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ -_loop_data_* find_loop_data(_loop_data_* begin, _loop_data_* end, - find_loop_pred predicate, void* data) -{ - while (begin && begin != end) - { - if (begin->looper) - { - if (predicate(begin, data)) - { - return begin; - } - } - ++begin; - } - - return NULL; -} -//------------------------------------------------------------------------------ -bool looper_by_port_pred(_loop_data_* looper, void *data) -{ - return _get_looper_port_(looper->looper) == (port_id)data; -} -//------------------------------------------------------------------------------ -bool looper_by_tid_pred(_loop_data_* looper, void *data) -{ - return looper->thread == (thread_id)data; -} -//------------------------------------------------------------------------------ -bool looper_by_name_pred(_loop_data_* looper, void *data) -{ - return strcmp(looper->looper->Name(), (const char*)data) == 0; -} -//------------------------------------------------------------------------------ -bool looper_pred(_loop_data_* looper, void *data) -{ - return looper->looper == (BLooper*)data; -} -//------------------------------------------------------------------------------ -bool empty_slot_pred(_loop_data_* looper, void*) -{ - return looper->looper == NULL; -} -//------------------------------------------------------------------------------ -bool copy_list_pred(_loop_data_ *looper, void* data) -{ - BList* List = (BList*)data; - if (List && looper->looper) - { - List->AddItem(looper->looper); - } - - // Ride this train to the end - return false; -} //------------------------------------------------------------------------------ port_id _get_looper_port_(const BLooper* looper) { diff --git a/src/tests/kits/app/Jamfile b/src/tests/kits/app/Jamfile index df22c59c28..daf9effa01 100644 --- a/src/tests/kits/app/Jamfile +++ b/src/tests/kits/app/Jamfile @@ -45,6 +45,7 @@ CommonTestLib libapptest.so LooperForThreadTest.cpp AddCommonFilterTest.cpp RemoveCommonFilterTest.cpp + LooperSizeTest.cpp # BMessageQueue MessageQueueTest.cpp diff --git a/src/tests/kits/app/blooper/LooperSizeTest.cpp b/src/tests/kits/app/blooper/LooperSizeTest.cpp new file mode 100644 index 0000000000..75d1ab4622 --- /dev/null +++ b/src/tests/kits/app/blooper/LooperSizeTest.cpp @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// LooperSizeTest.cpp +// +//------------------------------------------------------------------------------ + +// Standard Includes ----------------------------------------------------------- +#include + +// System Includes ------------------------------------------------------------- +#include + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- +#include "LooperSizeTest.h" + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- +#define R5_BLOOPER_SIZE 172 + +//------------------------------------------------------------------------------ +void TLooperSizeTest::LooperSizeTest() +{ + CPPUNIT_ASSERT(sizeof (BLooper) == R5_BLOOPER_SIZE); +} +//------------------------------------------------------------------------------ +TestSuite* TLooperSizeTest::Suite() +{ + TestSuite* suite = new TestSuite("BLooper sizeof() test"); + ADD_TEST4(BLooper, suite, TLooperSizeTest, LooperSizeTest); + return suite; +} +//------------------------------------------------------------------------------ + +/* + * $Log $ + * + * $Id $ + * + */ + diff --git a/src/tests/kits/app/blooper/LooperSizeTest.h b/src/tests/kits/app/blooper/LooperSizeTest.h new file mode 100644 index 0000000000..69fe0078a5 --- /dev/null +++ b/src/tests/kits/app/blooper/LooperSizeTest.h @@ -0,0 +1,41 @@ +//------------------------------------------------------------------------------ +// LooperSizeTest.h +// +//------------------------------------------------------------------------------ + +#ifndef LOOPERSIZETEST_H +#define LOOPERSIZETEST_H + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- +#include "../common.h" + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +class TLooperSizeTest : public TestCase +{ + public: + TLooperSizeTest() {;} + TLooperSizeTest(std::string name) : TestCase(name) {;} + + void LooperSizeTest(); + + static TestSuite* Suite(); +}; + +#endif //LOOPERSIZETEST_H + +/* + * $Log $ + * + * $Id $ + * + */ + diff --git a/src/tests/kits/app/blooper/LooperTest.cpp b/src/tests/kits/app/blooper/LooperTest.cpp index 9d678c3eee..3fa1c83c5a 100644 --- a/src/tests/kits/app/blooper/LooperTest.cpp +++ b/src/tests/kits/app/blooper/LooperTest.cpp @@ -11,6 +11,7 @@ #include "LooperForThreadTest.h" #include "AddCommonFilterTest.h" #include "RemoveCommonFilterTest.h" +#include "LooperSizeTest.h" Test* LooperTestSuite() { @@ -27,6 +28,7 @@ Test* LooperTestSuite() tests->addTest(TLooperForThreadTest::Suite()); tests->addTest(TAddCommonFilterTest::Suite()); tests->addTest(TRemoveCommonFilterTest::Suite()); + tests->addTest(TLooperSizeTest::Suite()); return tests; }