revert errnoneous checkin

This commit is contained in:
Christopher Faylor 2005-03-08 14:32:07 +00:00
parent efdc312d12
commit 8c2fb68a11
1 changed files with 23 additions and 47 deletions

View File

@ -22,6 +22,7 @@ details. */
#define TT_MAGIC 0x513e4a1c #define TT_MAGIC 0x513e4a1c
struct timer_tracker struct timer_tracker
{ {
static muto *protect;
unsigned magic; unsigned magic;
clockid_t clock_id; clockid_t clock_id;
sigevent evp; sigevent evp;
@ -32,52 +33,20 @@ struct timer_tracker
struct timer_tracker *next; struct timer_tracker *next;
int settime (int, const itimerspec *, itimerspec *); int settime (int, const itimerspec *, itimerspec *);
timer_tracker (clockid_t, const sigevent *); timer_tracker (clockid_t, const sigevent *);
timer_tracker () {}; timer_tracker ();
static void lock ();
static void unlock ();
~timer_tracker ();
}; };
timer_tracker NO_COPY ttstart; timer_tracker ttstart;
class lock_timer_tracker muto *timer_tracker::protect;
timer_tracker::timer_tracker ()
{ {
static muto *protect; new_muto (protect);
public:
lock_timer_tracker ();
~lock_timer_tracker ();
};
muto NO_COPY *lock_timer_tracker::protect;
lock_timer_tracker::lock_timer_tracker ()
{
new_muto (protect)->acquire ();
}
lock_timer_tracker::~lock_timer_tracker ()
{
protect->release ();
}
timer_tracker::~timer_tracker ()
{
if (cancel)
{
SetEvent (cancel);
th->detach ();
CloseHandle (cancel);
#ifdef DEBUGGING
th = NULL;
cancel = NULL;
#endif
}
magic = 0;
} }
timer_tracker::timer_tracker (clockid_t c, const sigevent *e) timer_tracker::timer_tracker (clockid_t c, const sigevent *e)
{ {
lock_timer_tracker now;
if (e != NULL) if (e != NULL)
evp = *e; evp = *e;
else else
@ -90,17 +59,19 @@ timer_tracker::timer_tracker (clockid_t c, const sigevent *e)
cancel = NULL; cancel = NULL;
flags = 0; flags = 0;
memset (&it, 0, sizeof (it)); memset (&it, 0, sizeof (it));
protect->acquire ();
next = ttstart.next; next = ttstart.next;
ttstart.next = this; ttstart.next = this;
protect->release ();
magic = TT_MAGIC; magic = TT_MAGIC;
} }
static long long static long long
to_us (const timespec& ts) to_us (timespec& ts)
{ {
long long res = ts.tv_sec; long long res = ts.tv_sec;
res *= 1000000; res *= 1000000;
res += ts.tv_nsec / 1000 + (ts.tv_nsec % 1000) ? 1 : 0; res += ts.tv_nsec / 1000 + ((ts.tv_nsec % 1000) >= 500 ? 1 : 0);
return res; return res;
} }
@ -179,6 +150,10 @@ timer_thread (VOID *x)
} }
out: out:
CloseHandle (tt.cancel);
// FIXME: race here but is it inevitable?
if (tt.cancel == tp->cancel)
tp->cancel = NULL;
return 0; return 0;
} }
@ -208,16 +183,13 @@ timer_tracker::settime (int in_flags, const itimerspec *value, itimerspec *ovalu
if (ovalue && check_null_invalid_struct_errno (ovalue)) if (ovalue && check_null_invalid_struct_errno (ovalue))
return -1; return -1;
lock_timer_tracker now;
itimerspec *elapsed; itimerspec *elapsed;
if (!cancel) if (!cancel)
elapsed = &itzero; elapsed = &itzero;
else else
{ {
SetEvent (cancel); SetEvent (cancel); // should be closed when the thread exits
th->detach (); th->detach ();
CloseHandle (cancel);
th = NULL;
elapsed = ⁢ elapsed = ⁢
} }
@ -274,14 +246,18 @@ timer_delete (timer_t timerid)
if (check_null_invalid_struct_errno (in_tt) || in_tt->magic != TT_MAGIC) if (check_null_invalid_struct_errno (in_tt) || in_tt->magic != TT_MAGIC)
return -1; return -1;
lock_timer_tracker now; timer_tracker::protect->acquire ();
for (timer_tracker *tt = &ttstart; tt->next != NULL; tt = tt->next) for (timer_tracker *tt = &ttstart; tt->next != NULL; tt = tt->next)
if (tt->next == in_tt) if (tt->next == in_tt)
{ {
tt->next = in_tt->next; timer_tracker *deleteme = tt->next;
delete in_tt; tt->next = deleteme->next;
delete deleteme;
timer_tracker::protect->release ();
return 0; return 0;
} }
timer_tracker::protect->release ();
set_errno (EINVAL); set_errno (EINVAL);
return 0; return 0;
} }