From 65174bbf57303662cb6a02e616b0e4f5ba3d5981 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 24 Jan 2005 01:22:03 +0000 Subject: [PATCH] Added unregistration. Fixed MessagingService::RegisterService(): the semaphores weren't stored. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10992 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../core/messaging/MessagingService.cpp | 53 +++++++++++++++++++ src/kernel/core/messaging/MessagingService.h | 2 + 2 files changed, 55 insertions(+) diff --git a/src/kernel/core/messaging/MessagingService.cpp b/src/kernel/core/messaging/MessagingService.cpp index 39ad85f4fb..82ebf87f2b 100644 --- a/src/kernel/core/messaging/MessagingService.cpp +++ b/src/kernel/core/messaging/MessagingService.cpp @@ -60,6 +60,25 @@ _user_register_messaging_service(sem_id lockSem, sem_id counterSem) return (error != B_OK ? error : areaID); } +// _user_unregister_messaging_service +status_t +_user_unregister_messaging_service() +{ + // check, if init_messaging_service() has been called yet + if (!sMessagingService) + return B_NO_INIT; + + if (!sMessagingService->Lock()) + return B_BAD_VALUE; + + status_t error = sMessagingService->UnregisterService(); + + sMessagingService->Unlock(); + + return error; +} + + // send_message status_t send_message(const void *message, int32 messageSize, @@ -386,6 +405,40 @@ MessagingService::RegisterService(sem_id lockSem, sem_id counterSem, areaID = fFirstArea->ID(); fFirstArea->Unlock(); + // store the server team and the semaphores + fServerTeam = threadInfo.team; + fLockSem = lockSem; + fCounterSem = counterSem; + + return B_OK; +} + +// UnregisterService +status_t +MessagingService::UnregisterService() +{ + // check, if the team calling this function is indeed the server team + thread_info threadInfo; + status_t error = get_thread_info(find_thread(NULL), &threadInfo); + if (error != B_OK) + return error; + + if (threadInfo.team != fServerTeam) + return B_BAD_VALUE; + + // delete all areas + while (fFirstArea) { + MessagingArea *area = fFirstArea; + fFirstArea = area; + delete area; + } + fLastArea = NULL; + + // unset the other members + fLockSem = -1; + fCounterSem -1; + fServerTeam = -1; + return B_OK; } diff --git a/src/kernel/core/messaging/MessagingService.h b/src/kernel/core/messaging/MessagingService.h index de27268fd9..85fc46e016 100644 --- a/src/kernel/core/messaging/MessagingService.h +++ b/src/kernel/core/messaging/MessagingService.h @@ -63,6 +63,7 @@ public: status_t RegisterService(sem_id lockingSem, sem_id counterSem, area_id &areaID); + status_t UnregisterService(); status_t SendMessage(const void *message, int32 messageSize, const messaging_target *targets, int32 targetCount); @@ -72,6 +73,7 @@ private: MessagingArea *&area, void *&data); BLocker fLock; + team_id fServerTeam; sem_id fLockSem; sem_id fCounterSem; MessagingArea *fFirstArea;