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; }
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); }
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; }