From 37faaaded5dd4a0cb611707bcf50ab03a0f99544 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 20 Jun 2003 00:18:56 +0000 Subject: [PATCH] Made the (BHandler*, BLooper*,) constructor more robust. Now the looper list is locked and the looper checked for validity. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3581 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/app/Messenger.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/kits/app/Messenger.cpp b/src/kits/app/Messenger.cpp index 5d08f9312a..e011a05c4b 100644 --- a/src/kits/app/Messenger.cpp +++ b/src/kits/app/Messenger.cpp @@ -47,6 +47,7 @@ // Project Includes ------------------------------------------------------------ #include #include +#include "ObjectLocker.h" #include "TokenSpace.h" // Local Includes -------------------------------------------------------------- @@ -56,6 +57,9 @@ // Globals --------------------------------------------------------------------- using BPrivate::gDefaultTokens; +using BPrivate::gLooperList; +using BPrivate::BLooperList; +using BPrivate::BObjectLocker; enum { NOT_IMPLEMENTED = B_ERROR, @@ -131,23 +135,17 @@ BMessenger::BMessenger(const BHandler *handler, const BLooper *looper, if (looper == NULL) error = B_MISMATCHED_VALUES; } - // set port, token,... - if (error == B_OK) { - fPort = looper->fMsgPort; - fHandlerToken = _get_object_token_(handler); - fPreferredTarget = false; - } - } else { // handler == NULL (=> looper != NULL) - fPort = looper->fMsgPort; - fHandlerToken = false; - fPreferredTarget = true; } - // get and set the team ID + // set port, token,... if (error == B_OK) { - thread_info info; - error = get_thread_info(find_thread(NULL), &info); - if (error == B_OK) - fTeam = info.team; + BObjectLocker locker(gLooperList); + if (locker.IsLocked() && gLooperList.IsLooperValid(looper)) { + fPort = looper->fMsgPort; + fHandlerToken = (handler ? _get_object_token_(handler) : -1); + fPreferredTarget = !handler; + fTeam = looper->Team(); + } else + error = B_BAD_VALUE; } } if (result)