OSDN Git Service

* pinfo.cc (pinfo::exit): Right shift exit value by eight when not started in a
authorcgf <cgf>
Tue, 8 Mar 2005 14:31:20 +0000 (14:31 +0000)
committercgf <cgf>
Tue, 8 Mar 2005 14:31:20 +0000 (14:31 +0000)
cygwin environment.

winsup/cygwin/ChangeLog
winsup/cygwin/pinfo.cc
winsup/cygwin/timer.cc

index eea18c3..0ca345f 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-08  Christopher Faylor  <cgf@timesys.com>
+
+       * pinfo.cc (pinfo::exit): Right shift exit value by eight when not
+       started in a cygwin environment.
+
 2005-03-07  Corinna Vinschen  <corinna@vinschen.de>
 
        * mmap.cc (mmap64): Handle MAP_AUTOGROW flag.
index a7b650a..5a046f9 100644 (file)
@@ -158,14 +158,16 @@ pinfo::exit (DWORD n)
       self->alert_parent (0);          /* Shave a little time by telling our
                                           parent that we have now exited.  */
     }
-  int exitcode = self->exitcode;
+  int exitcode = self->exitcode & 0xffff;
+  if (!self->cygstarted)
+    exitcode >>= 8;
   release ();
 
   _my_tls.stacklock = 0;
   _my_tls.stackptr = _my_tls.stack;
   sigproc_printf ("Calling ExitProcess hProcess %p, n %p, exitcode %p",
                  hProcess, n, exitcode);
-  ExitProcess (exitcode & 0xffff);
+  ExitProcess (exitcode);
 }
 # undef self
 
index 6a53a57..d710c2c 100644 (file)
@@ -22,7 +22,6 @@ details. */
 #define TT_MAGIC 0x513e4a1c
 struct timer_tracker
 {
-  static muto *protect;
   unsigned magic;
   clockid_t clock_id;
   sigevent evp;
@@ -33,20 +32,52 @@ struct timer_tracker
   struct timer_tracker *next;
   int settime (int, const itimerspec *, itimerspec *);
   timer_tracker (clockid_t, const sigevent *);
-  timer_tracker ();
+  timer_tracker () {};
+  static void lock ();
+  static void unlock ();
+  ~timer_tracker ();
 };
 
-timer_tracker ttstart;
+timer_tracker NO_COPY ttstart;
+
+class lock_timer_tracker
+{
+  static muto *protect;
+public:
+  lock_timer_tracker ();
+  ~lock_timer_tracker ();
+};
 
-muto *timer_tracker::protect;
+muto NO_COPY *lock_timer_tracker::protect;
 
-timer_tracker::timer_tracker ()
+lock_timer_tracker::lock_timer_tracker ()
 {
-  new_muto (protect);
+  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)
 {
+  lock_timer_tracker now;
   if (e != NULL)
     evp = *e;
   else
@@ -59,19 +90,17 @@ timer_tracker::timer_tracker (clockid_t c, const sigevent *e)
   cancel = NULL;
   flags = 0;
   memset (&it, 0, sizeof (it));
-  protect->acquire ();
   next = ttstart.next;
   ttstart.next = this;
-  protect->release ();
   magic = TT_MAGIC;
 }
 
 static long long
-to_us (timespec& ts)
+to_us (const timespec& ts)
 {
   long long res = ts.tv_sec;
   res *= 1000000;
-  res += ts.tv_nsec / 1000 + ((ts.tv_nsec % 1000) >= 500 ? 1 : 0);
+  res += ts.tv_nsec / 1000 + (ts.tv_nsec % 1000) ? 1 : 0;
   return res;
 }
 
@@ -150,10 +179,6 @@ timer_thread (VOID *x)
     }
 
 out:
-  CloseHandle (tt.cancel);
-  // FIXME: race here but is it inevitable?
-  if (tt.cancel == tp->cancel)
-    tp->cancel = NULL;
   return 0;
 }
 
@@ -183,13 +208,16 @@ timer_tracker::settime (int in_flags, const itimerspec *value, itimerspec *ovalu
   if (ovalue && check_null_invalid_struct_errno (ovalue))
     return -1;
 
+  lock_timer_tracker now;
   itimerspec *elapsed;
   if (!cancel)
     elapsed = &itzero;
   else
     {
-      SetEvent (cancel);       // should be closed when the thread exits
+      SetEvent (cancel);
       th->detach ();
+      CloseHandle (cancel);
+      th = NULL;
       elapsed = &it;
     }
 
@@ -246,18 +274,14 @@ timer_delete (timer_t timerid)
   if (check_null_invalid_struct_errno (in_tt) || in_tt->magic != TT_MAGIC)
     return -1;
 
-  timer_tracker::protect->acquire ();
+  lock_timer_tracker now;
   for (timer_tracker *tt = &ttstart; tt->next != NULL; tt = tt->next)
     if (tt->next == in_tt)
       {
-       timer_tracker *deleteme = tt->next;
-       tt->next = deleteme->next;
-       delete deleteme;
-       timer_tracker::protect->release ();
+       tt->next = in_tt->next;
+       delete in_tt;
        return 0;
       }
-  timer_tracker::protect->release ();
-
   set_errno (EINVAL);
   return 0;
 }