File Info

Rev. efeab20e689880041b1ce76d479bb22c776d3f74
Size 3,314 bytes
Time 2020-07-04 19:41:12
Author simphone
Log Message

simphone 0.8.1

Content

diff -urb npth-1.6/w32/npth.c npth/w32/npth.c
--- npth-1.6/w32/npth.c
+++ npth/w32/npth.c
@@ -19,9 +19,13 @@
 
 /* We implement the join mechanism ourself.  */
 
+#ifdef _MSC_VER
+#include "../simcore/config.h"
+#else
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
+#endif
 
 #include <assert.h>
 #include <errno.h>
@@ -41,13 +45,17 @@
 #endif
 
 /* This seems to be a common standard.  */
-#define THREAD_NAME_MAX 15
+//#define THREAD_NAME_MAX 15
 
 /* The global lock that excludes all threads but one.  Note that this
    implements the single-user-thread policy, but also protects all our
    global data such as the thread_table.  GOT_SCEPTRE is a flag used
    for debugging to tell wether we hold SCEPTRE.  */
+#ifdef SIM_NONRECURSIVE
+static HANDLE sceptre;
+#else
 static CRITICAL_SECTION sceptre;
+#endif
 static int got_sceptre;
 
 
@@ -61,7 +69,7 @@
 
 
 typedef struct npth_impl_s *npth_impl_t;
-#define MAX_THREADS 1024
+#define MAX_THREADS 20480
 #define INVALID_THREAD_ID 0
 /* Thread ID to thread context table.  We never allocate ID 0.  */
 static npth_impl_t thread_table[MAX_THREADS];
@@ -156,14 +164,22 @@
     _npth_debug (DEBUG_CALLS, "tid %lu: enter_npth (%s)\n",
 		 npth_self (), function ? function : "unknown");
   got_sceptre = 0;
+#ifdef SIM_NONRECURSIVE
+  ReleaseSemaphore (sceptre, 1, NULL);
+#else
   LeaveCriticalSection (&sceptre);
+#endif
 }
 
 
 static void
 leave_npth (const char *function)
 {
+#ifdef SIM_NONRECURSIVE
+  WaitForSingleObject (sceptre, INFINITE);
+#else
   EnterCriticalSection (&sceptre);
+#endif
   got_sceptre = 1;
 
   if (DEBUG_CALLS)
@@ -191,7 +207,9 @@
   void *(*start_routine) (void *);
   void *start_arg;
 
+#ifdef THREAD_NAME_MAX
   char name[THREAD_NAME_MAX + 1];
+#endif
 
   /* Doubly-linked list for the waiter queue in condition
      variables.  */
@@ -276,7 +294,9 @@
   /* We create the event when it is first needed (not all threads wait
      on conditions).  */
   thread->event = INVALID_HANDLE_VALUE;
+#ifdef THREAD_NAME_MAX
   memset (thread->name, '\0', sizeof (thread->name));
+#endif
 
   thread_table[id] = thread;
 
@@ -323,7 +343,12 @@
   HANDLE handle;
   npth_impl_t thread;
 
+#ifdef SIM_NONRECURSIVE
+  if ((sceptre = CreateSemaphore (NULL, 1, 1, NULL)) == NULL)
+    return GetLastError ();
+#else
   InitializeCriticalSection (&sceptre);
+#endif
 
   /* Track that we have been initialized.  */
   initialized_or_any_threads = 1;
@@ -410,6 +435,7 @@
 }
 
 
+#ifdef THREAD_NAME_MAX
 int
 npth_getname_np (npth_t target_thread, char *buf, size_t buflen)
 {
@@ -444,6 +470,18 @@
   strcpy (thread->name, name);
   return 0;
 }
+#else
+void *
+npth_gethandle_np (npth_t target_thread)
+{
+  npth_impl_t thread;
+
+  if (find_thread (target_thread, &thread))
+    return INVALID_HANDLE_VALUE;
+
+  return thread->handle;
+}
+#endif
 
 
 static DWORD
diff -urb npth-1.6/w32/npth.h npth/w32/npth.h
--- npth-1.6/w32/npth.h
+++ npth/w32/npth.h
@@ -74,6 +74,7 @@
 int npth_attr_setdetachstate(npth_attr_t *attr, int detachstate);
 int npth_getname_np (npth_t target_thread, char *buf, size_t buflen);
 int npth_setname_np (npth_t target_thread, const char *name);
+void *npth_gethandle_np (npth_t target_thread);
 
 int npth_create (npth_t *newthread, const npth_attr_t *attr,
 		 void *(*start_routine) (void *), void *arg);
Show on old repository browser