void cv_wait(cond_t *cv, lock_t *lk){ while(xchg(&cv->cond,0) == 0){ printf(1, "in cv_wait goling to sleep\n"); lock_release(lk); t_sleep(); } printf(1,"in cv after sleep\n"); lock_acquire(lk); }
int sys_t_sleep(void) { void *chan, *p_lk; if(argptr(0, (void *)&chan, sizeof(void *)) < 0) { return -1; } if(argptr(1, (void *)&p_lk, sizeof(void *)) < 0) { return -1; } t_sleep(chan, (lock_t*)p_lk); return 0; }
int Thread_Task::svc (void) { // if debugging, dump the priority that we're actually at. if (TAO_debug_level > 0) { // Get the priority of the current thread. RTCORBA::Priority prio = ACTIVITY::instance()->current ()->the_priority (); if (prio == this->task_priority_) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) actual prio of %d equals desired priority\n"), prio)); else { ACE_DEBUG ((LM_ERROR, ACE_TEXT ("(%t) actual prio = %d, desired priority_ = %d!\n"), prio, this->task_priority_)); } } if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG, "Thread_Task (%t) - wait\n")); // First, wait for other threads. this->barrier_->wait (); // first thread here inits the Base_Time. task_stats_->base_time (BASE_TIME::instance ()->base_time_); // now wait till the phase_ period expires. ACE_OS::sleep (ACE_Time_Value (0, phase_)); ACE_High_Res_Timer::global_scale_factor_type gsf = ACE_High_Res_Timer::global_scale_factor (); ACE_hrtime_t before, after; for (int i = 0; i < iter_ ; ++i) { before = ACE_OS::gethrtime (); job_->work (load_); after = ACE_OS::gethrtime (); task_stats_->sample (before, after); if (period_ != 0) // blast mode, no sleep. { // convert to microseconds ACE_UINT32 elapsed_microseconds = ACE_UINT32((after - before) / gsf); #if defined (ACE_WIN32) elapsed_microseconds*=1000; // convert to uSec on Win32 #endif /* ACE_WIN32 */ // did we miss any deadlines? int const missed = elapsed_microseconds > period_ ? elapsed_microseconds/period_ : 0; long sleep_time = (missed + 1)*period_ ; sleep_time -= elapsed_microseconds; if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG, "(%t) sleep time = %d\n", sleep_time)); ACE_Time_Value t_sleep (0, sleep_time); ACE_OS::sleep (t_sleep); } /* period != 0 */ } /* for */ task_stats_->end_time (ACE_OS::gethrtime ()); job_->shutdown (); // tell the job that we're done. ACTIVITY::instance ()->task_ended (this); return 0; }
void TAO_Notify_Tests_Periodic_Supplier::handle_svc (void) { this->send_prologue (); ACE_hrtime_t before, after; TimeBase::TimeT time_t; CORBA::Any buffer; ACE_hrtime_t base_time = BASE_TIME::instance ()->base_time_; for (int i = 0; i < iter_ ; ++i) { before = ACE_OS::gethrtime (); ORBSVCS_Time::hrtime_to_TimeT (time_t, before); buffer <<= time_t; this->event_.payload (buffer); if (this->run_time_ != 0 && Task_Stats::diff_sec (base_time, before) > this->run_time_) { // Time up, send a "Stop" event. buffer <<= (CORBA::Long) 1; this->event_.opt_header ("Stop", buffer); i = iter_; // Load the iter so that the loop exits. } if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG, "(%P, %t) Supplier (%s) sending event #%d\n", this->name_.c_str (), i)); this->send_event (this->event_.event ()); after = ACE_OS::gethrtime (); stats_.sample (before, after); if (period_ != 0) // blast mode, no sleep. { ACE_UINT32 elapsed_microseconds = Task_Stats::diff_usec (before, after); // did we miss any deadlines? long missed = (int)elapsed_microseconds > period_ ? elapsed_microseconds/period_ : 0; this->total_deadlines_missed_ += missed; /* Start -- "Immediate run if last call missed deadline" */ if (missed > 0) // if we missed continue; long sleep_time = period_ - elapsed_microseconds; /* End -- "Immediate run if last call missed deadline" */ /* * This logic sleeps till the next period. * So, if we missed a deadline we wait. * long sleep_time = (missed + 1)*period_ ; sleep_time -= elapsed_microseconds; */ if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG, "(%t) sleep time = %d uSec, missed %d deadlines\n", sleep_time, missed)); ACE_Time_Value t_sleep (0, sleep_time); ACE_OS::sleep (t_sleep); } /* period != 0 */ } /* for */ stats_.end_time (ACE_OS::gethrtime ()); if (this->client_) this->client_->done (this); }