static ACE_THR_FUNC_RETURN controller (void *arg) { ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg); Quit_Handler *quit_handler = 0; ACE_NEW_RETURN (quit_handler, Quit_Handler (reactor), 0); #if defined (ACE_WIN32) && (!defined (ACE_HAS_STANDARD_CPP_LIBRARY) || \ (ACE_HAS_STANDARD_CPP_LIBRARY == 0) || \ defined (ACE_USES_OLD_IOSTREAMS)) for (;;) { char user_input[80]; ACE_OS::fgets (user_input, sizeof (user_input), stdin); if (ACE_OS::strcmp (user_input, "quit") == 0) { reactor->notify (quit_handler); break; } } #else for (;;) { std::string user_input; std::getline (cin, user_input, '\n'); if (user_input == "quit") { reactor->notify (quit_handler); break; } } #endif return 0; }
void notify (ACE_Reactor &reactor, ACE_Event_Handler *event_handler, int extra_iterations_needed) { ACE_Thread_Manager thread_manager; // Create a thread to run the event loop. Event_Loop_Thread event_loop_thread (thread_manager, reactor, extra_iterations_needed); int result = event_loop_thread.activate (); ACE_ASSERT (result == 0); for (int i = 0; i < iterations; ++i) { ACE_OS::sleep (ACE_Time_Value (0, 500 * 1000)); result = reactor.notify (event_handler, ACE_Event_Handler::READ_MASK); ACE_ASSERT (result == 0); } thread_manager.wait (); }
int Test_Task::svc (void) { // Every thread must register the same stream to write to file. if (out_stream) { ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM); ACE_LOG_MSG->msg_ostream (out_stream); } for (size_t index = 0; index < NUM_INVOCATIONS; index++) { ACE_OS::thr_yield (); if (r_->notify (this, ACE_Event_Handler::READ_MASK) == -1) { ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Lock, -1); ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Test_Task: error %p!\n"), ACE_TEXT ("notifying reactor")), 0); } } ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" (%t) returning from svc ()\n"))); return 0; }
Dispatch_Count_Handler::Dispatch_Count_Handler (void) { ACE_Reactor *r = ACE_Reactor::instance (); this->input_seen_ = this->notify_seen_ = 0; this->timers_fired_ = 0; // Initialize the pipe. if (this->pipe_.open () == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_Pipe::open"))); // Register the "read" end of the pipe. else if (r->register_handler (this->pipe_.read_handle (), this, ACE_Event_Handler::READ_MASK) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("register_handler"))); // Put something in our pipe and smoke it... ;-) else if (ACE::send (this->pipe_.write_handle (), "z", 1) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("send"))); // Call notify to prime the pump for this, as well. else if (r->notify (this) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("notify"))); }
ACE_THR_FUNC_RETURN ACE_Event_Handler::read_adapter (void *args) { ACE_Event_Handler *this_ptr = static_cast<ACE_Event_Handler *> (args); ACE_Reactor *r = this_ptr->reactor (); while (this_ptr->handle_input (ACE_STDIN) != -1) continue; this_ptr->handle_close (ACE_STDIN, ACE_Event_Handler::READ_MASK); // It's possible for handle_close() to "delete this" so we need to // cache the reactor pointer and use it here. r->notify (); return 0; }
void TAO_Leader_Follower::resume_events () { // not need to obtain the lock, only called when holding the lock while (!this->deferred_event_set_.is_empty ()) { ACE_Auto_Ptr<Deferred_Event> event (this->deferred_event_set_.pop_front ()); // Send a notification to the reactor to cause the awakening of a new // follower, if there is one already available. ACE_Reactor *reactor = this->orb_core_->reactor (); int const retval = reactor->notify (event->handler (), ACE_Event_Handler::READ_MASK); if (TAO_debug_level > 2) { // @@todo: need to think about what is the action that // we can take when we get here with an error?! TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - TAO_Leader_Follower::resume_events, ") ACE_TEXT ("an event handler[%d] has been resumed, ") ACE_TEXT ("notified the reactor, retval=%d.\n"), event->handler ()->get_handle (), retval)); } } }
extern "C" void handler (int) { finished = 1; reactor.notify(); // notify() 를 하면 handle_events() 함수가 종료. }
static int run_notify_purge_test (void) { int status; ACE_Reactor *r = ACE_Reactor::instance (); { Purged_Notify n1; Purged_Notify *n2; ACE_NEW_RETURN (n2, Purged_Notify, -1); auto_ptr<Purged_Notify> ap (n2); // First test: // Notify EXCEPT, and purge ALL r->notify (&n1); // the mask is EXCEPT_MASK status = r->purge_pending_notifications (&n1); if (status == -1 && errno == ENOTSUP) return 0; // Select Reactor w/o ACE_HAS_REACTOR_NOTIFICATION_QUEUE if (status != 1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("Purged %d notifies; expected 1\n"), status)); // Second test: // Notify READ twice, and WRITE once, and purge READ and WRITE - should purge 3 times. r->notify (&n1, ACE_Event_Handler::READ_MASK); r->notify (&n1, ACE_Event_Handler::READ_MASK); r->notify (&n1, ACE_Event_Handler::WRITE_MASK); status = r->purge_pending_notifications (&n1, ACE_Event_Handler::READ_MASK | ACE_Event_Handler::WRITE_MASK); if (status != 3) ACE_ERROR ((LM_ERROR, ACE_TEXT ("Purged %d notifies; expected 3\n"), status)); // Third test: // Notify READ on 2 handlers, and purge READ|WRITE on all handlers. Should purge 2 r->notify (&n1, ACE_Event_Handler::READ_MASK); r->notify (n2, ACE_Event_Handler::READ_MASK); status = r->purge_pending_notifications (0, ACE_Event_Handler::READ_MASK | ACE_Event_Handler::WRITE_MASK); if (status != 2) ACE_ERROR ((LM_ERROR, ACE_TEXT ("Purged %d notifies; expected 2\n"), status)); // Forth test: // Notify EXCEPT and WRITE, purge READ. Should not purge r->notify (&n1); // the mask is EXCEPT_MASK r->notify (&n1, ACE_Event_Handler::WRITE_MASK); status = r->purge_pending_notifications (&n1, ACE_Event_Handler::READ_MASK); if (status != 0) ACE_ERROR ((LM_ERROR, ACE_TEXT ("Purged %d notifies; expected 0\n"), status)); // Fifth test: r->notify (n2); // The destructor of the event handler no longer removes the // notifications. It is the application's responsability to do // so. r->purge_pending_notifications(n2, ACE_Event_Handler::ALL_EVENTS_MASK); r->purge_pending_notifications(&n1, ACE_Event_Handler::ALL_EVENTS_MASK); } ACE_Time_Value t (1); status = r->handle_events (t); // Should be nothing to do, and time out return status < 0 ? 1 : 0; // Return 0 for all ok, else error }
extern "C" void handler (int) { finished = 1; reactor.notify(); }