Module Name: src Committed By: christos Date: Mon Dec 19 21:59:46 UTC 2011
Modified Files: src/external/bsd/atf/dist/atf-run: timer.cpp Log Message: Put back setitimer based code for the have-nots: (OS/X Lion) To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/external/bsd/atf/dist/atf-run/timer.cpp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/atf/dist/atf-run/timer.cpp diff -u src/external/bsd/atf/dist/atf-run/timer.cpp:1.3 src/external/bsd/atf/dist/atf-run/timer.cpp:1.4 --- src/external/bsd/atf/dist/atf-run/timer.cpp:1.3 Sun Dec 18 22:16:05 2011 +++ src/external/bsd/atf/dist/atf-run/timer.cpp Mon Dec 19 16:59:46 2011 @@ -44,11 +44,25 @@ namespace impl = atf::atf_run; // Auxiliary functions. // ------------------------------------------------------------------------ +#ifdef SIGEV_NONE +#define HAVE_POSIX_TIMER +#endif + +#ifndef HAVE_POSIX_TIMER +static void *handle; +#endif + static void handler(int signo, siginfo_t *si, void *uc) { - impl::timer *timer = static_cast<impl::timer *>(si->si_value.sival_ptr); + impl::timer *timer = static_cast<impl::timer *>( +#ifndef HAVE_POSIX_TIMER + handle +#else + si->si_value.sival_ptr +#endif + ); timer->setfired(); timer->timeout_callback(); @@ -68,7 +82,7 @@ impl::timer::timer(const unsigned int se throw system_error(IMPL_NAME "::timer::timer", "Failed to set signal handler", errno); - +#ifndef HAVE_POSIX_TIMER ::sigevent se; se.sigev_notify = SIGEV_SIGNAL; se.sigev_signo = SIGALRM; @@ -92,11 +106,32 @@ impl::timer::timer(const unsigned int se throw system_error(IMPL_NAME "::timer::timer", "Failed to program timer", errno); } +#else + ::itimerval it, oit; + it.it_interval.tv_sec = 0; + it.it_interval.tv_usec = 0; + it.it_value.tv_sec = seconds; + it.it_value.tv_usec = 0; + if (::setitimer(ITIMER_REAL, &it, &oit) == -1) + ::sigaction(SIGALRM, &m_old_sa, NULL); + throw system_error(IMPL_NAME "::timer::timer", + "Failed to program timer", errno); + } + TIMEVAL_TO_TIMESPEC(&m_old_it, &oit); + handle = static_cast<void *>(this); +#endif } impl::timer::~timer(void) { - int ret = ::timer_delete(m_timer); + int ret; +#ifdef HAVE_POSIX_TIMER + ::itimerval oit; + TIMESPEC_TO_TIMEVAL(&oit, &m_old_it); + ret = ::setitimer(ITIMER_REAL, &oit, NULL); +#else + ret = ::timer_delete(m_timer); +#endif INV(ret != -1); ret = ::sigaction(SIGALRM, &m_old_sa, NULL); INV(ret != -1);