OSDN Git Service

* cygthread.cc (operator new): Be more defensive when messing with threads that
authorcgf <cgf>
Fri, 4 Apr 2003 05:58:06 +0000 (05:58 +0000)
committercgf <cgf>
Fri, 4 Apr 2003 05:58:06 +0000 (05:58 +0000)
are marked "unavailable".

winsup/cygwin/ChangeLog
winsup/cygwin/cygthread.cc

index a7a3df8..7de1780 100644 (file)
@@ -1,3 +1,8 @@
+2003-04-04  Christopher Faylor  <cgf@redhat.com>
+
+       * cygthread.cc (operator new): Be more defensive when messing with
+       threads that are marked "unavailable".
+
 2003-04-03  Christopher Faylor  <cgf@redhat.com>
 
        * fhandler_console.cc (CONVERT_LIMIT): Use a size for the 21st century.
index 251fe5e..4ed0d52 100644 (file)
@@ -136,7 +136,9 @@ new (size_t)
 
   /* Search the threads array for an empty slot to use */
   for (info = threads; info < threads + NTHREADS; info++)
-    if ((id = (DWORD) InterlockedExchange ((LPLONG) &info->avail, 0)))
+    if ((LONG) (id = (DWORD) InterlockedExchange ((LPLONG) &info->avail, -1)) < 0)
+      /* being considered */;
+    else if (id > 0)
       {
 #ifdef DEBUGGING
        if (info->__name)
@@ -146,7 +148,9 @@ new (size_t)
 #endif
        goto out;
       }
-    else if (!info->id)
+    else if (info->id)
+      InterlockedExchange ((LPLONG) &info->avail, 0);
+    else
       {
        info->h = CreateThread (&sec_none_nih, 0, cygthread::stub, info,
                                CREATE_SUSPENDED, &info->id);
@@ -162,6 +166,7 @@ new (size_t)
   info = freerange (); /* exhausted thread pool */
 
 out:
+  InterlockedExchange ((LPLONG) &info->avail, 0);
   cygthread_protect->release ();
   return info;
 }