Ejemplo n.º 1
0
ACE_Token_Proxy *
ACE_Token_Handler::get_proxy (void)
{
  ACE_TRACE ("ACE_Token_Handler::get_proxy");

  // See if the proxy already exists in the collection.
  ACE_Token_Proxy *proxy = collection_.is_member (token_request_.token_name ());

  // If not, create one.
  if (proxy == 0)
    {
      proxy = this->create_proxy ();

      // Put the new_proxy in this client_id's collection.
      if (collection_.insert (*proxy) == -1)
        ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("insert failed\n")), 0);

      // Delete our copy (one was created in the collection).
      delete proxy;
      proxy = collection_.is_member (token_request_.token_name ());

      if (proxy == 0)
        ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("is_member failed\n")), 0);

      // Set the client_id (it was set to 1 since we're
      // single-threaded.
      proxy->client_id (token_request_.client_id ());
    }

  return proxy;
}
Ejemplo n.º 2
0
/* VIRTUAL */ int
ACE_Token_Handler::handle_timeout (const ACE_Time_Value &,
                                   const void *tp)
{
  ACE_TRACE ("ACE_Token_Handler::handle_timeout");

  this->timeout_id_ = 0;

  // @@ add a try acquire here!
  // Try to acquire the token, but if we can't get it immediately
  // then abandon the wait.
  //  if (this->try_acquire (&token_entry) == -1)
  //    return this->abandon (token_entry);

  ACE_Token_Proxy *proxy = (ACE_Token_Proxy *) tp;

#if 0
  ACE_DEBUG ((LM_DEBUG, "in handle_timeout for client id = %s\n",
             proxy->client_id ()));
#endif /* 0 */

  // Remove ourselves from the waiter list.
  proxy->release ();

  this->send_reply (ETIME);
  return 0;
}
Ejemplo n.º 3
0
ACE_Token_Proxy *
STDIN_Token::get_proxy (const char *_tid, const char *token, char type)
{
  ACE_Token_Collection *proxy_collection;

  TID tid (_tid);

  if (collections_.find (tid, proxy_collection) == -1)
    // We did not find a proxy_collection.
    {
      // Make one.
      proxy_collection = new ACE_Token_Collection (debug_, "no name collection");

      // Put it in the collections.
      if (collections_.bind (tid, proxy_collection) == -1)
        {
          delete proxy_collection;
          return 0;
        }
    }

  // Either way, we have a proxy_collection now.

  // See if the proxy already exists in the collection.
  ACE_Token_Proxy *proxy = proxy_collection->is_member (token);

  // If not, create one.
  if (proxy == 0)
    {
      proxy = this->create_proxy (token, type);

      // Put the new_proxy in this tid's collection.
      if (proxy_collection->insert (*proxy) == -1)
        ACE_ERROR_RETURN ((LM_ERROR, "insert failed\n"), 0);

      // Delete our copy (one was created in the collection).
      delete proxy;
      proxy = proxy_collection->is_member (token);

      if (proxy == 0)
        ACE_ERROR_RETURN ((LM_ERROR, "is_member failed\n"), 0);

      // Set the client_id (it was set to 1 since we're
      // single-threaded.
      proxy->client_id (_tid);
    }

  return proxy;
}
Ejemplo n.º 4
0
int
ACE_Token_Collection::release (const ACE_TCHAR *token_name,
                               ACE_Synch_Options &options)
{
  ACE_TRACE ("ACE_Token_Collection::release");
  TOKEN_NAME name (token_name);
  ACE_Token_Proxy *temp;
  // get the token from the collection
  int result = collection_.find (name, temp);
  // did we find it?
  if (result != 0)
    return result;
  // perform the operation
  return temp->release (options);
}
Ejemplo n.º 5
0
int
ACE_Token_Collection::is_member (const ACE_Token_Proxy &token)
{
  ACE_TRACE ("ACE_Token_Collection::is_member");
  TOKEN_NAME token_name (token.name ());
  return collection_.find (token_name) == 0;
}
Ejemplo n.º 6
0
int
ACE_Token_Collection::tryacquire (const ACE_TCHAR *token_name,
                                  void (*sleep_hook)(void *))
{
  ACE_TRACE ("ACE_Token_Collection::tryacquire");
  TOKEN_NAME name (token_name);
  ACE_Token_Proxy *temp;
  // Get the token from the collection.
  int result = collection_.find (name, temp);
  // did we find it?
  if (result == -1)
    return result;

  // perform the operation
  return temp->tryacquire (sleep_hook);
}
Ejemplo n.º 7
0
int
ACE_Token_Collection::acquire (const ACE_TCHAR *token_name,
                               int notify,
                               void (*sleep_hook)(void *),
                               ACE_Synch_Options &options)
{
  ACE_TRACE ("ACE_Token_Collection::acquire");
  TOKEN_NAME name (token_name);
  ACE_Token_Proxy *temp;
  // Get the token from the collection.
  int result = collection_.find (name, temp);
  // did we find it?
  if (result == -1)
    return result;
  // perform the operation
  return temp->acquire (notify, sleep_hook, options);
}
Ejemplo n.º 8
0
int
ACE_Token_Collection::insert (ACE_Token_Proxy &new_token)
{
  ACE_TRACE ("ACE_Token_Collection::insert");

  TOKEN_NAME name (new_token.name ());

  // Check if the new_proxy is already in the list.
  if (collection_.find (name) == 1)
    // One already exists, so fail.
    return -1;

  // Clone the new token.
  ACE_Token_Proxy *temp = new_token.clone ();

  if (collection_.bind (name, temp) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("bind failed\n")), -1);
  return 0;
}
Ejemplo n.º 9
0
int
ACE_Token_Collection::renew (const ACE_TCHAR *token_name,
                             int requeue_position,
                             ACE_Synch_Options &options)
{
  ACE_TRACE ("ACE_Token_Collection::renew");
  TOKEN_NAME name (token_name);
  ACE_Token_Proxy *temp;

  // Get the token from the collection.
  int result = collection_.find (name, temp);

  // Did we find it?
  if (result == -1)
    ACE_ERROR_RETURN ((LM_DEBUG, ACE_TEXT ("%p %s\n"),
                       ACE_TEXT ("not in collection "),
                       token_name), -1);
  // perform the operation
  return temp->renew (requeue_position, options);
}
Ejemplo n.º 10
0
static void *
run_thread (void *vp)
{
    ACE_Token_Proxy *collection = (ACE_Token_Proxy *) vp;

    int count = iterations;
    while (count--)
    {
        if (collection->acquire () == -1)
        {
            if (ACE_OS::last_error () == EDEADLK)
            {
                ACE_DEBUG ((LM_DEBUG, "deadlock detected in acquire"));
                continue;
            }
            ACE_ERROR ((LM_ERROR, "(%t) %p acquire failed\n","run_thread"));
            return (void *) -1;
        }

        ACE_DEBUG ((LM_DEBUG, "(%t) %s acquired.\n", collection->name ()));

        if (collection->renew () == -1)
        {
            if (ACE_OS::last_error () == EDEADLK)
            {
                ACE_DEBUG ((LM_DEBUG, "deadlock detected"));
                goto deadlock;
            }
            ACE_ERROR ((LM_ERROR, "(%t) %p renew failed\n","run_thread"));
            return (void *) -1;
        }

        ACE_DEBUG ((LM_DEBUG, "(%t) %s renewed.\n", collection->name ()));

deadlock:
        if (collection->release () == -1)
        {
            ACE_ERROR ((LM_ERROR, "(%t) %p release failed\n","run_thread"));
            return (void *) -1;
        }

        ACE_DEBUG ((LM_DEBUG, "(%t) %s released.\n", collection->name ()));
    }

    ACE_DEBUG ((LM_DEBUG, "(%t) thread exiting.\n"));
    return 0;
}
Ejemplo n.º 11
0
int
STDIN_Token::handle_input (ACE_HANDLE fd)
{
  ACE_UNUSED_ARG (fd);

  char tid[BUFSIZ];
  char token[BUFSIZ];
  char type[16];
  char operation[16];

  if (::scanf ("%s %s %s %s", tid, token, type, operation) <= 0)
    {
      ACE_OS::printf ("Try again.\n");
      return 0;
    }

  ACE_Token_Proxy *proxy =
    this->get_proxy (tid, token, type[0]);

  if (proxy == 0)
    return -1;

  switch (operation[0])
    {
    case 'a':
    case 'A':
      if (proxy->acquire () == 0)
        {
          ACE_OS::printf ("Succeeded.\n");
          if (ACE_TOKEN_INVARIANTS::instance ()->acquired (proxy) == 0)
            ACE_OS::printf ("Violated invariant.\n");
        }
      else
        ACE_ERROR ((LM_ERROR, "%p.\n", "Acquire failed"));
      break;
    case 'n':
    case 'N':
      ACE_TOKEN_INVARIANTS::instance ()->releasing (proxy);
      if (proxy->renew () == 0)
        {
          ACE_OS::printf ("Succeeded.\n");
          if (ACE_TOKEN_INVARIANTS::instance ()->acquired (proxy) == 0)
            ACE_OS::printf ("Violated invariant.\n");
        }
      else
        ACE_ERROR ((LM_ERROR, "%p.\n", "Renew failed"));
      break;

    case 'r':
    case 'R':
      ACE_TOKEN_INVARIANTS::instance ()->releasing (proxy);
      if (proxy->release () == 0)
        ACE_OS::printf ("Succeeded.\n");
      else
        ACE_ERROR ((LM_ERROR, "%p.\n", "Release failed"));
      break;

    case 't':
    case 'T':
      if (proxy->tryacquire () == 0)
        {
          ACE_OS::printf ("Succeeded.\n");
          if (ACE_TOKEN_INVARIANTS::instance ()->acquired (proxy) == 0)
            ACE_OS::printf ("Violated invariant.\n");
        }
      else
        ACE_ERROR ((LM_ERROR, "%p.\n", "Tryacquire failed"));
      break;
    }

  this->display_menu ();
  return 0;
}