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
This commit is contained in:
Ingo Weinhold 2005-01-24 01:22:03 +00:00
parent 244ddcf058
commit 65174bbf57
2 changed files with 55 additions and 0 deletions

View File

@ -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;
}

View File

@ -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;