2019-01-12 20:23:55 +01:00
|
|
|
/* timer.h: Define class timer_tracker, base class for posix timers
|
2019-01-11 19:40:03 +01:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2019-01-22 18:20:18 +01:00
|
|
|
#ifndef __POSIX_TIMER_H__
|
|
|
|
#define __POSIX_TIMER_H__
|
2019-01-11 19:40:03 +01:00
|
|
|
|
|
|
|
#define TT_MAGIC 0x513e4a1c
|
|
|
|
class timer_tracker
|
|
|
|
{
|
|
|
|
unsigned magic;
|
2019-01-22 15:23:05 +01:00
|
|
|
SRWLOCK srwlock;
|
2019-01-11 19:40:03 +01:00
|
|
|
clockid_t clock_id;
|
|
|
|
sigevent evp;
|
2019-01-22 15:23:05 +01:00
|
|
|
struct itimerspec time_spec;
|
|
|
|
HANDLE timer;
|
|
|
|
HANDLE cancel_evt;
|
|
|
|
HANDLE sync_thr;
|
|
|
|
LONG64 interval;
|
|
|
|
LONG64 exp_ts;
|
2019-01-19 19:53:48 +01:00
|
|
|
LONG overrun_count_curr;
|
2019-01-12 21:19:52 +01:00
|
|
|
LONG64 overrun_count;
|
2019-01-11 19:40:03 +01:00
|
|
|
|
|
|
|
bool cancel ();
|
|
|
|
|
|
|
|
public:
|
2019-01-22 15:23:05 +01:00
|
|
|
void *operator new (size_t, void *p) __attribute__ ((nothrow)) {return p;}
|
2019-01-22 16:22:45 +01:00
|
|
|
void operator delete (void *p) { HeapFree (GetProcessHeap (), 0, p); }
|
2019-01-19 19:53:48 +01:00
|
|
|
timer_tracker (clockid_t, const sigevent *);
|
2019-01-11 19:40:03 +01:00
|
|
|
~timer_tracker ();
|
2019-01-12 20:23:55 +01:00
|
|
|
inline bool is_timer_tracker () const { return magic == TT_MAGIC; }
|
2019-01-12 21:19:52 +01:00
|
|
|
inline sigevent_t *sigevt () { return &evp; }
|
2019-01-19 19:53:48 +01:00
|
|
|
inline int getoverrun () const { return overrun_count_curr; }
|
2019-01-11 19:40:03 +01:00
|
|
|
|
2019-01-22 15:23:05 +01:00
|
|
|
LONG64 get_clock_now () const { return get_clock (clock_id)->n100secs (); }
|
|
|
|
LONG64 get_exp_ts () const { return exp_ts; }
|
|
|
|
LONG64 get_interval () const { return interval; }
|
|
|
|
void set_exp_ts (LONG64 ts) { exp_ts = ts; }
|
|
|
|
|
2019-01-22 18:20:18 +01:00
|
|
|
bool arm_overrun_event (LONG64);
|
2019-01-22 15:23:05 +01:00
|
|
|
LONG disarm_overrun_event ();
|
|
|
|
|
|
|
|
int gettime (itimerspec *, bool);
|
2019-01-11 19:40:03 +01:00
|
|
|
int settime (int, const itimerspec *, itimerspec *);
|
|
|
|
|
|
|
|
DWORD thread_func ();
|
2019-01-11 20:36:46 +01:00
|
|
|
static void fixup_after_fork ();
|
2019-01-11 19:40:03 +01:00
|
|
|
};
|
|
|
|
|
2019-01-22 18:20:18 +01:00
|
|
|
#endif /* __POSIX_TIMER_H__ */
|