haiku/headers/private/app/TokenSpace.h
Axel Dörfler 9dbe170a69 Implemented direct message passing for local targets; this fixes a deadlock
with PostMessage() in case the message queue is full.
Some notes:
* for synchronous replies, we don't use this mechanism yet, but it could be
  extended to do that as well.
* the code looks so complicated because we need a way to access the looper's
  queue without locking it (to prevent deadlocks); like Dano's solution, I've
  abused BTokenSpace to store a BDirectMessageTarget with a BHandler.
* we also need to decouple the lifetime of a looper's queue from its target,
  as we cannot lock the looper, and therefore, can't guarantee it stays valid
  as long as we're accessing it outside of BLooper.
* init_clipboard() now needs to be done after the global constructors have
  been called - since sending messages now needs gDefaultTokens to be initialized.
  Since this is done per image, it shouldn't cause any troubles, though.
* some minor cleanup, removed unused _msg_cache_cleanup_() and friends.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19968 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-01-26 13:59:56 +00:00

68 lines
1.4 KiB
C++

/*
* Copyright 2001-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Erik Jaesler (erik@cgsoftware.com)
* Axel Dörfler, axeld@pinc-software.de
*/
#ifndef _TOKEN_SPACE_H
#define _TOKEN_SPACE_H
#include <BeBuild.h>
#include <Locker.h>
#include <SupportDefs.h>
#include <map>
#include <stack>
// token types as specified in targets
#define B_PREFERRED_TOKEN -2 /* A little bird told me about this one */
#define B_NULL_TOKEN -1
#define B_ANY_TOKEN 0
// token types in the token list
#define B_HANDLER_TOKEN 1
#define B_SERVER_TOKEN 2
namespace BPrivate {
class BDirectMessageTarget;
class BTokenSpace : public BLocker {
public:
BTokenSpace();
~BTokenSpace();
int32 NewToken(int16 type, void* object);
void SetToken(int32 token, int16 type, void* object);
bool RemoveToken(int32 token);
bool CheckToken(int32 token, int16 type) const;
status_t GetToken(int32 token, int16 type, void** _object) const;
status_t SetHandlerTarget(int32 token, BDirectMessageTarget* target);
status_t AcquireHandlerTarget(int32 token, BDirectMessageTarget** _target);
private:
struct token_info {
int16 type;
void* object;
BDirectMessageTarget* target;
};
typedef std::map<int32, token_info> TokenMap;
TokenMap fTokenMap;
int32 fTokenCount;
};
extern _IMPEXP_BE BTokenSpace gDefaultTokens;
} // namespace BPrivate
#endif // _TOKEN_SPACE_H