*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
This commit is contained in:
@@ -1,33 +1,23 @@
|
||||
#include "ace/Token_Manager.h"
|
||||
|
||||
#if defined (ACE_HAS_TOKENS_LIBRARY)
|
||||
|
||||
#include "ace/Object_Manager.h"
|
||||
|
||||
#if !defined (__ACE_INLINE__)
|
||||
#include "ace/Token_Manager.inl"
|
||||
#endif /* __ACE_INLINE__ */
|
||||
|
||||
ACE_RCSID (ace,
|
||||
Token_Manager,
|
||||
"$Id: Token_Manager.cpp 80826 2008-03-04 14:51:23Z wotte $")
|
||||
|
||||
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
// singleton token manager
|
||||
ACE_Token_Manager *ACE_Token_Manager::token_manager_ = 0;
|
||||
|
||||
ACE_Token_Manager::ACE_Token_Manager ()
|
||||
{
|
||||
ACE_TRACE ("ACE_Token_Manager::ACE_Token_Manager");
|
||||
}
|
||||
|
||||
ACE_Token_Manager::~ACE_Token_Manager ()
|
||||
{
|
||||
ACE_TRACE ("ACE_Token_Manager::~ACE_Token_Manager");
|
||||
|
||||
COLLECTION::ITERATOR iterator (collection_);
|
||||
|
||||
for (COLLECTION::ENTRY *temp = 0;
|
||||
iterator.next (temp) != 0;
|
||||
iterator.advance ())
|
||||
@@ -38,12 +28,10 @@ ACE_Token_Manager::~ACE_Token_Manager ()
|
||||
// COLLECTION::ENTRYs goes away.
|
||||
}
|
||||
}
|
||||
|
||||
ACE_Token_Manager *
|
||||
ACE_Token_Manager::instance (void)
|
||||
{
|
||||
ACE_TRACE ("ACE_Token_Manager::instance");
|
||||
|
||||
// This first check is to avoid acquiring the mutex in the common
|
||||
// case. Double-Check pattern rules.
|
||||
if (token_manager_ == 0)
|
||||
@@ -54,7 +42,6 @@ ACE_Token_Manager::instance (void)
|
||||
(ACE_Object_Manager::ACE_TOKEN_MANAGER_CREATION_LOCK);
|
||||
ACE_GUARD_RETURN (ACE_TOKEN_CONST::MUTEX, ace_mon, *lock, 0);
|
||||
#endif /* ACE_MT_SAFE */
|
||||
|
||||
if (token_manager_ == 0)
|
||||
{
|
||||
ACE_NEW_RETURN (token_manager_,
|
||||
@@ -64,10 +51,8 @@ ACE_Token_Manager::instance (void)
|
||||
ACE_Object_Manager::at_exit (token_manager_);
|
||||
}
|
||||
}
|
||||
|
||||
return token_manager_;
|
||||
}
|
||||
|
||||
void
|
||||
ACE_Token_Manager::get_token (ACE_Token_Proxy *proxy,
|
||||
const ACE_TCHAR *token_name)
|
||||
@@ -76,17 +61,13 @@ ACE_Token_Manager::get_token (ACE_Token_Proxy *proxy,
|
||||
// Hmm. I think this makes sense. We perform our own locking here
|
||||
// (see safe_acquire.) We have to make sure that only one thread
|
||||
// uses the collection at a time.
|
||||
|
||||
ACE_GUARD (ACE_TOKEN_CONST::MUTEX, ace_mon, this->lock_);
|
||||
|
||||
TOKEN_NAME name (token_name);
|
||||
|
||||
if (collection_.find (name, proxy->token_) == -1)
|
||||
// We did not find one in the collection.
|
||||
{
|
||||
// Make one.
|
||||
proxy->token_ = proxy->create_token (token_name);
|
||||
|
||||
// Put it in the collection.
|
||||
if (collection_.bind (name, proxy->token_) == -1)
|
||||
{
|
||||
@@ -94,14 +75,11 @@ ACE_Token_Manager::get_token (ACE_Token_Proxy *proxy,
|
||||
proxy->token_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (proxy->token_ != 0)
|
||||
proxy->token_->inc_reference ();
|
||||
|
||||
// We may be returning proxy->token_ == 0 if new failed, caller must
|
||||
// check.
|
||||
}
|
||||
|
||||
// 0. check_deadlock (TOKEN)
|
||||
// 1. if TOKEN->visited (), return 0.
|
||||
// 2. mark TOKEN visited.
|
||||
@@ -111,15 +89,12 @@ ACE_Token_Manager::get_token (ACE_Token_Proxy *proxy,
|
||||
// 6. if OWNER is not waiting for a NEW_TOKEN, continue.
|
||||
// 7. else, if check_deadlock (NEW_TOKEN) == 1, return *DEADLOCK*
|
||||
// 8. return 0.
|
||||
|
||||
int
|
||||
ACE_Token_Manager::check_deadlock (ACE_Token_Proxy *proxy)
|
||||
{
|
||||
ACE_TRACE ("ACE_Token_Manager::check_deadlock");
|
||||
|
||||
// Start the recursive deadlock detection algorithm.
|
||||
int result = this->check_deadlock (proxy->token_, proxy);
|
||||
|
||||
// Whether or not we detect deadlock, we have to unmark all tokens
|
||||
// for the next time.
|
||||
COLLECTION::ITERATOR iterator (collection_);
|
||||
@@ -127,24 +102,17 @@ ACE_Token_Manager::check_deadlock (ACE_Token_Proxy *proxy)
|
||||
iterator.next (temp) != 0;
|
||||
iterator.advance ())
|
||||
temp->int_id_->visit (0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Token_Manager::check_deadlock (ACE_Tokens *token, ACE_Token_Proxy *proxy)
|
||||
{
|
||||
ACE_TRACE ("ACE_Token_Manager::check_deadlock");
|
||||
|
||||
if (token->visited ())
|
||||
return 0;
|
||||
|
||||
token->visit (1);
|
||||
|
||||
ACE_Tokens::OWNER_STACK owners;
|
||||
|
||||
int is_owner = token->owners (owners, proxy->client_id ());
|
||||
|
||||
switch (is_owner)
|
||||
{
|
||||
case -1:
|
||||
@@ -160,7 +128,6 @@ ACE_Token_Manager::check_deadlock (ACE_Tokens *token, ACE_Token_Proxy *proxy)
|
||||
token->name (),
|
||||
proxy->token_->name ()));
|
||||
}
|
||||
|
||||
return 1;
|
||||
case 0:
|
||||
default:
|
||||
@@ -186,13 +153,11 @@ ACE_Token_Manager::check_deadlock (ACE_Tokens *token, ACE_Token_Proxy *proxy)
|
||||
}
|
||||
// else, check the next owner.
|
||||
}
|
||||
|
||||
// We've checked all the owners and found no deadlock.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ACE_Tokens *
|
||||
ACE_Token_Manager::token_waiting_for (const ACE_TCHAR *client_id)
|
||||
{
|
||||
@@ -204,11 +169,9 @@ ACE_Token_Manager::token_waiting_for (const ACE_TCHAR *client_id)
|
||||
if (temp->int_id_->is_waiting_for (client_id))
|
||||
return temp->int_id_;
|
||||
}
|
||||
|
||||
// nothing was found, return NULL.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Notify the token manager that a token is has been released. If
|
||||
// as a result, there is no owner of the token, the token is
|
||||
// deleted.
|
||||
@@ -217,17 +180,13 @@ ACE_Token_Manager::release_token (ACE_Tokens *&token)
|
||||
{
|
||||
ACE_TRACE ("ACE_Token_Manager::release_token");
|
||||
// again, let's perform our own locking here.
|
||||
|
||||
ACE_GUARD (ACE_TOKEN_CONST::MUTEX, ace_mon, this->lock_);
|
||||
|
||||
if (token->dec_reference () == 0)
|
||||
{
|
||||
// No one has the token, so we can delete it and remove it from
|
||||
// our collection. First, let's get it from the collection.
|
||||
TOKEN_NAME token_name (token->name ());
|
||||
|
||||
ACE_Tokens *temp;
|
||||
|
||||
if (collection_.unbind (token_name, temp) == -1)
|
||||
// we did not find one in the collection
|
||||
{
|
||||
@@ -252,7 +211,6 @@ ACE_Token_Manager::release_token (ACE_Tokens *&token)
|
||||
// else
|
||||
// someone is still interested in the token, so keep it around.
|
||||
}
|
||||
|
||||
void
|
||||
ACE_Token_Manager::dump (void) const
|
||||
{
|
||||
@@ -267,8 +225,6 @@ ACE_Token_Manager::dump (void) const
|
||||
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
|
||||
#endif /* ACE_HAS_DUMP */
|
||||
}
|
||||
|
||||
ACE_END_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
#endif /* ACE_HAS_TOKENS_LIBRARY */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user