BTokenSpace: Use pthread_mutex instead of BLocker.
This header gets included in the build platform, so we can't use the private recursive_lock. Eliminates another statically created BLocker, due to gDefaultTokens.
This commit is contained in:
@@ -13,7 +13,6 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
#include <Locker.h>
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -33,11 +32,13 @@ namespace BPrivate {
|
|||||||
class BDirectMessageTarget;
|
class BDirectMessageTarget;
|
||||||
|
|
||||||
|
|
||||||
class BTokenSpace : public BLocker {
|
class BTokenSpace {
|
||||||
public:
|
public:
|
||||||
BTokenSpace();
|
BTokenSpace();
|
||||||
~BTokenSpace();
|
~BTokenSpace();
|
||||||
|
|
||||||
|
pthread_mutex_t* GetLock() { return &fLock; }
|
||||||
|
|
||||||
int32 NewToken(int16 type, void* object);
|
int32 NewToken(int16 type, void* object);
|
||||||
bool SetToken(int32 token, int16 type, void* object);
|
bool SetToken(int32 token, int16 type, void* object);
|
||||||
|
|
||||||
@@ -51,8 +52,6 @@ public:
|
|||||||
status_t AcquireHandlerTarget(int32 token,
|
status_t AcquireHandlerTarget(int32 token,
|
||||||
BDirectMessageTarget** _target);
|
BDirectMessageTarget** _target);
|
||||||
|
|
||||||
void InitAfterFork();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct token_info {
|
struct token_info {
|
||||||
int16 type;
|
int16 type;
|
||||||
@@ -61,6 +60,7 @@ private:
|
|||||||
};
|
};
|
||||||
typedef std::map<int32, token_info> TokenMap;
|
typedef std::map<int32, token_info> TokenMap;
|
||||||
|
|
||||||
|
mutable pthread_mutex_t fLock;
|
||||||
TokenMap fTokenMap;
|
TokenMap fTokenMap;
|
||||||
int32 fNextToken;
|
int32 fNextToken;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ initialize_forked_child()
|
|||||||
|
|
||||||
BMessage::Private::StaticReInitForkedChild();
|
BMessage::Private::StaticReInitForkedChild();
|
||||||
BPrivate::gLooperList.InitAfterFork();
|
BPrivate::gLooperList.InitAfterFork();
|
||||||
BPrivate::gDefaultTokens.InitAfterFork();
|
|
||||||
BPrivate::init_team_after_fork();
|
BPrivate::init_team_after_fork();
|
||||||
|
|
||||||
// Continuing to use BApplication after forking is not supported.
|
// Continuing to use BApplication after forking is not supported.
|
||||||
|
|||||||
+10
-17
@@ -11,7 +11,7 @@
|
|||||||
#include <DirectMessageTarget.h>
|
#include <DirectMessageTarget.h>
|
||||||
#include <TokenSpace.h>
|
#include <TokenSpace.h>
|
||||||
|
|
||||||
#include <Autolock.h>
|
#include <PthreadMutexLocker.h>
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
@@ -32,21 +32,22 @@ get_next_token(int32 token)
|
|||||||
|
|
||||||
BTokenSpace::BTokenSpace()
|
BTokenSpace::BTokenSpace()
|
||||||
:
|
:
|
||||||
BLocker("token space"),
|
|
||||||
fNextToken(1)
|
fNextToken(1)
|
||||||
{
|
{
|
||||||
|
fLock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BTokenSpace::~BTokenSpace()
|
BTokenSpace::~BTokenSpace()
|
||||||
{
|
{
|
||||||
|
pthread_mutex_destroy(&fLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
BTokenSpace::NewToken(int16 type, void* object)
|
BTokenSpace::NewToken(int16 type, void* object)
|
||||||
{
|
{
|
||||||
BAutolock locker(this);
|
PthreadMutexLocker locker(&fLock);
|
||||||
|
|
||||||
token_info tokenInfo = { type, object, NULL };
|
token_info tokenInfo = { type, object, NULL };
|
||||||
|
|
||||||
@@ -79,7 +80,7 @@ BTokenSpace::NewToken(int16 type, void* object)
|
|||||||
bool
|
bool
|
||||||
BTokenSpace::SetToken(int32 token, int16 type, void* object)
|
BTokenSpace::SetToken(int32 token, int16 type, void* object)
|
||||||
{
|
{
|
||||||
BAutolock locker(this);
|
PthreadMutexLocker locker(&fLock);
|
||||||
|
|
||||||
token_info tokenInfo = { type, object, NULL };
|
token_info tokenInfo = { type, object, NULL };
|
||||||
|
|
||||||
@@ -100,7 +101,7 @@ BTokenSpace::SetToken(int32 token, int16 type, void* object)
|
|||||||
bool
|
bool
|
||||||
BTokenSpace::RemoveToken(int32 token)
|
BTokenSpace::RemoveToken(int32 token)
|
||||||
{
|
{
|
||||||
BAutolock locker(this);
|
PthreadMutexLocker locker(&fLock);
|
||||||
|
|
||||||
TokenMap::iterator iterator = fTokenMap.find(token);
|
TokenMap::iterator iterator = fTokenMap.find(token);
|
||||||
if (iterator == fTokenMap.end())
|
if (iterator == fTokenMap.end())
|
||||||
@@ -117,7 +118,7 @@ BTokenSpace::RemoveToken(int32 token)
|
|||||||
bool
|
bool
|
||||||
BTokenSpace::CheckToken(int32 token, int16 type) const
|
BTokenSpace::CheckToken(int32 token, int16 type) const
|
||||||
{
|
{
|
||||||
BAutolock locker(const_cast<BTokenSpace&>(*this));
|
PthreadMutexLocker locker(&fLock);
|
||||||
|
|
||||||
TokenMap::const_iterator iterator = fTokenMap.find(token);
|
TokenMap::const_iterator iterator = fTokenMap.find(token);
|
||||||
if (iterator != fTokenMap.end() && iterator->second.type == type)
|
if (iterator != fTokenMap.end() && iterator->second.type == type)
|
||||||
@@ -133,7 +134,7 @@ BTokenSpace::GetToken(int32 token, int16 type, void** _object) const
|
|||||||
if (token < 1)
|
if (token < 1)
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
BAutolock locker(const_cast<BTokenSpace&>(*this));
|
PthreadMutexLocker locker(&fLock);
|
||||||
|
|
||||||
TokenMap::const_iterator iterator = fTokenMap.find(token);
|
TokenMap::const_iterator iterator = fTokenMap.find(token);
|
||||||
if (iterator == fTokenMap.end() || iterator->second.type != type)
|
if (iterator == fTokenMap.end() || iterator->second.type != type)
|
||||||
@@ -150,7 +151,7 @@ BTokenSpace::SetHandlerTarget(int32 token, BDirectMessageTarget* target)
|
|||||||
if (token < 1)
|
if (token < 1)
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
BAutolock locker(const_cast<BTokenSpace&>(*this));
|
PthreadMutexLocker locker(&fLock);
|
||||||
|
|
||||||
TokenMap::iterator iterator = fTokenMap.find(token);
|
TokenMap::iterator iterator = fTokenMap.find(token);
|
||||||
if (iterator == fTokenMap.end() || iterator->second.type != B_HANDLER_TOKEN)
|
if (iterator == fTokenMap.end() || iterator->second.type != B_HANDLER_TOKEN)
|
||||||
@@ -173,7 +174,7 @@ BTokenSpace::AcquireHandlerTarget(int32 token, BDirectMessageTarget** _target)
|
|||||||
if (token < 1)
|
if (token < 1)
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
BAutolock locker(const_cast<BTokenSpace&>(*this));
|
PthreadMutexLocker locker(&fLock);
|
||||||
|
|
||||||
TokenMap::const_iterator iterator = fTokenMap.find(token);
|
TokenMap::const_iterator iterator = fTokenMap.find(token);
|
||||||
if (iterator == fTokenMap.end() || iterator->second.type != B_HANDLER_TOKEN)
|
if (iterator == fTokenMap.end() || iterator->second.type != B_HANDLER_TOKEN)
|
||||||
@@ -187,12 +188,4 @@ BTokenSpace::AcquireHandlerTarget(int32 token, BDirectMessageTarget** _target)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BTokenSpace::InitAfterFork()
|
|
||||||
{
|
|
||||||
// We need to reinitialize the locker to get a new semaphore
|
|
||||||
new (this) BTokenSpace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <MessageFilter.h>
|
#include <MessageFilter.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
#include <PthreadMutexLocker.h>
|
||||||
#include <Region.h>
|
#include <Region.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
|
|
||||||
@@ -2408,7 +2409,7 @@ void
|
|||||||
Desktop::WriteWindowInfo(int32 serverToken, BPrivate::LinkSender& sender)
|
Desktop::WriteWindowInfo(int32 serverToken, BPrivate::LinkSender& sender)
|
||||||
{
|
{
|
||||||
AutoWriteLocker locker(fWindowLock);
|
AutoWriteLocker locker(fWindowLock);
|
||||||
BAutolock tokenLocker(BPrivate::gDefaultTokens);
|
PthreadMutexLocker tokenLocker(BPrivate::gDefaultTokens.GetLock());
|
||||||
|
|
||||||
::ServerWindow* window;
|
::ServerWindow* window;
|
||||||
if (BPrivate::gDefaultTokens.GetToken(serverToken,
|
if (BPrivate::gDefaultTokens.GetToken(serverToken,
|
||||||
|
|||||||
Reference in New Issue
Block a user