From 565155afa138d4aa9db28bc8cf3cd36d14a30764 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 27 Jul 2019 17:40:24 -0400 Subject: [PATCH] Remove unnecessary usages of BLocker::Sem(). Most of these should have been BLocker::InitCheck() anyway. The one that was actually using the sem (MessageLooper) should just store the name parameter, which simplifies things anyway. Done as a result of a branch where I'm experimenting with making BLocker not even create a semaphore in "benaphore" mode. --- .../file_systems/netfs/shared/NetAddress.cpp | 2 +- src/apps/terminal/TerminalBuffer.cpp | 4 +- src/kits/media/MediaFormats.cpp | 40 +++++++++---------- src/servers/app/MessageLooper.cpp | 7 ++-- src/servers/app/MessageLooper.h | 1 + src/servers/app/ServerApp.cpp | 4 +- src/servers/registrar/TRoster.cpp | 4 +- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/add-ons/kernel/file_systems/netfs/shared/NetAddress.cpp b/src/add-ons/kernel/file_systems/netfs/shared/NetAddress.cpp index f978504701..86a5b13158 100644 --- a/src/add-ons/kernel/file_systems/netfs/shared/NetAddress.cpp +++ b/src/add-ons/kernel/file_systems/netfs/shared/NetAddress.cpp @@ -198,7 +198,7 @@ public: status_t InitCheck() const { - return (fLock.Sem() >= 0 ? B_OK : B_NO_INIT); + return fLock.InitCheck(); } status_t GetHostAddress(const char* hostName, NetAddress* address) diff --git a/src/apps/terminal/TerminalBuffer.cpp b/src/apps/terminal/TerminalBuffer.cpp index f93c0b8410..396cd728cb 100644 --- a/src/apps/terminal/TerminalBuffer.cpp +++ b/src/apps/terminal/TerminalBuffer.cpp @@ -47,8 +47,8 @@ TerminalBuffer::~TerminalBuffer() status_t TerminalBuffer::Init(int32 width, int32 height, int32 historySize) { - if (Sem() < 0) - return Sem(); + if (BLocker::InitCheck() < 0) + return BLocker::InitCheck(); fAlternateScreen = _AllocateLines(width, height); if (fAlternateScreen == NULL) diff --git a/src/kits/media/MediaFormats.cpp b/src/kits/media/MediaFormats.cpp index bc2afa76a1..4f3b9e0eea 100644 --- a/src/kits/media/MediaFormats.cpp +++ b/src/kits/media/MediaFormats.cpp @@ -100,7 +100,7 @@ get_next_encoder(int32* cookie, const media_file_format* fileFormat, status_t ret = AddOnManager::GetInstance()->GetCodecInfo( &candidateCodecInfo, &candidateFormatFamily, &candidateInputFormat, &candidateOutputFormat, *cookie); - + if (ret != B_OK) return ret; @@ -186,7 +186,7 @@ _media_format_description::_media_format_description( } -_media_format_description& +_media_format_description& _media_format_description::operator=(const _media_format_description& other) { memcpy(this, &other, sizeof(*this)); @@ -318,7 +318,7 @@ meta_format::meta_format(const meta_format& other) } -bool +bool meta_format::Matches(const media_format& otherFormat, media_format_family family) { @@ -329,7 +329,7 @@ meta_format::Matches(const media_format& otherFormat, } -int +int meta_format::CompareDescriptions(const meta_format* a, const meta_format* b) { if (a->description == b->description) @@ -342,7 +342,7 @@ meta_format::CompareDescriptions(const meta_format* a, const meta_format* b) } -int +int meta_format::Compare(const meta_format* a, const meta_format* b) { int compare = CompareDescriptions(a, b); @@ -422,7 +422,7 @@ update_media_formats() BMediaFormats::BMediaFormats() : - fIteratorIndex(0) + fIteratorIndex(0) { } @@ -432,14 +432,14 @@ BMediaFormats::~BMediaFormats() } -status_t +status_t BMediaFormats::InitCheck() { - return sLock.Sem() >= B_OK ? B_OK : sLock.Sem(); + return sLock.InitCheck(); } -status_t +status_t BMediaFormats::GetCodeFor(const media_format& format, media_format_family family, media_format_description* _description) @@ -465,7 +465,7 @@ BMediaFormats::GetCodeFor(const media_format& format, } -status_t +status_t BMediaFormats::GetFormatFor(const media_format_description& description, media_format* _format) { @@ -499,8 +499,8 @@ BMediaFormats::GetFormatFor(const media_format_description& description, } -status_t -BMediaFormats::GetBeOSFormatFor(uint32 format, +status_t +BMediaFormats::GetBeOSFormatFor(uint32 format, media_format* _format, media_type type) { BMediaFormats formats; @@ -520,7 +520,7 @@ BMediaFormats::GetBeOSFormatFor(uint32 format, } -status_t +status_t BMediaFormats::GetAVIFormatFor(uint32 codec, media_format* _format, media_type type) { @@ -542,8 +542,8 @@ BMediaFormats::GetAVIFormatFor(uint32 codec, } -status_t -BMediaFormats::GetQuicktimeFormatFor(uint32 vendor, uint32 codec, +status_t +BMediaFormats::GetQuicktimeFormatFor(uint32 vendor, uint32 codec, media_format* _format, media_type type) { BMediaFormats formats; @@ -564,7 +564,7 @@ BMediaFormats::GetQuicktimeFormatFor(uint32 vendor, uint32 codec, } -status_t +status_t BMediaFormats::RewindFormats() { if (!sLock.IsLocked() || sLock.LockingThread() != find_thread(NULL)) { @@ -577,7 +577,7 @@ BMediaFormats::RewindFormats() } -status_t +status_t BMediaFormats::GetNextFormat(media_format* _format, media_format_description* _description) { @@ -609,14 +609,14 @@ BMediaFormats::Lock() } -void +void BMediaFormats::Unlock() { sLock.Unlock(); } -status_t +status_t BMediaFormats::MakeFormatFor(const media_format_description* descriptions, int32 descriptionCount, media_format* format, uint32 flags, void* _reserved) @@ -631,7 +631,7 @@ BMediaFormats::MakeFormatFor(const media_format_description* descriptions, // #pragma mark - deprecated API -status_t +status_t BMediaFormats::MakeFormatFor(const media_format_description& description, const media_format& inFormat, media_format* _outFormat) { diff --git a/src/servers/app/MessageLooper.cpp b/src/servers/app/MessageLooper.cpp index 56ce033668..2038cf9aa2 100644 --- a/src/servers/app/MessageLooper.cpp +++ b/src/servers/app/MessageLooper.cpp @@ -18,6 +18,7 @@ MessageLooper::MessageLooper(const char* name) : BLocker(name), + fName(name), fThread(-1), fQuitting(false), fDeathSemaphore(-1) @@ -120,10 +121,8 @@ MessageLooper::_PrepareQuit() void MessageLooper::_GetLooperName(char* name, size_t length) { - sem_id semaphore = Sem(); - sem_info info; - if (get_sem_info(semaphore, &info) == B_OK) - strlcpy(name, info.name, length); + if (fName != NULL) + strlcpy(name, fName, length); else strlcpy(name, "unnamed looper", length); } diff --git a/src/servers/app/MessageLooper.h b/src/servers/app/MessageLooper.h index 2b6bd7dcd8..a8c1c5e8ec 100644 --- a/src/servers/app/MessageLooper.h +++ b/src/servers/app/MessageLooper.h @@ -46,6 +46,7 @@ protected: static int32 _message_thread(void*_looper); protected: + const char* fName; thread_id fThread; BPrivate::PortLink fLink; bool fQuitting; diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index 4d524c18ab..e2092f60df 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -223,8 +223,8 @@ ServerApp::InitCheck() if (fClientReplyPort < B_OK) return fClientReplyPort; - if (fWindowListLock.Sem() < B_OK) - return fWindowListLock.Sem(); + if (fWindowListLock.InitCheck() < B_OK) + return fWindowListLock.InitCheck(); if (fMemoryAllocator == NULL) return B_NO_MEMORY; diff --git a/src/servers/registrar/TRoster.cpp b/src/servers/registrar/TRoster.cpp index d72a020eef..90034edb1b 100644 --- a/src/servers/registrar/TRoster.cpp +++ b/src/servers/registrar/TRoster.cpp @@ -1232,8 +1232,8 @@ status_t TRoster::Init() { // check lock initialization - if (fLock.Sem() < 0) - return fLock.Sem(); + if (fLock.InitCheck() < 0) + return fLock.InitCheck(); // create the info RosterAppInfo* info = new(nothrow) RosterAppInfo;