Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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;
}