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