Minor tweaks to add a thread_intern struct that should ultimately
Gurusamy Sarathy [Wed, 12 Nov 1997 01:22:26 +0000 (01:22 +0000)]
contain all the win32-specific statics.
Win32 branch now passes all tests with or w/o USE_THREADS.

p4raw-id: //depot/win32/perl@235

embed.h
perl.c
win32/win32thread.c
win32/win32thread.h

diff --git a/embed.h b/embed.h
index bb36539..5a00219 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define formfeed               (curinterp->Iformfeed)
 #define formtarget             (curinterp->Iformtarget)
 #define gensym                 (curinterp->Igensym)
+#define globalstash            (curinterp->Iglobalstash)
 #define in_eval                        (curinterp->Iin_eval)
 #define incgv                  (curinterp->Iincgv)
 #define initav                 (curinterp->Iinitav)
 #define Iformfeed              formfeed
 #define Iformtarget            formtarget
 #define Igensym                        gensym
+#define Iglobalstash           globalstash
 #define Iin_eval               in_eval
 #define Iincgv                 incgv
 #define Iinitav                        initav
 #define formfeed               Perl_formfeed
 #define formtarget             Perl_formtarget
 #define gensym                 Perl_gensym
+#define globalstash            Perl_globalstash
 #define in_eval                        Perl_in_eval
 #define incgv                  Perl_incgv
 #define initav                 Perl_initav
diff --git a/perl.c b/perl.c
index 338193d..2e2435e 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -2842,11 +2842,11 @@ init_main_thread()
     thr->prev = thr;
     MUTEX_UNLOCK(&threads_mutex);
 
-#ifdef INIT_THREAD_INTERN
-    INIT_THREAD_INTERN(thr);
+#ifdef HAVE_THREAD_INTERN
+    init_thread_intern(thr);
 #else
     thr->self = pthread_self();
-#endif /* INIT_THREAD_INTERN */
+#endif /* HAVE_THREAD_INTERN */
     SET_THR(thr);
 
     /*
index dfa9a0c..a9ca8e8 100644 (file)
@@ -18,8 +18,8 @@ void
 init_thread_intern(struct thread *thr)
 {
 #ifdef USE_THREADS
-    /* GetCurrentThread() retrurns a pseudo handle, need
-       this to convert it into a handle another thread can use
+    /* Set thr->self.  GetCurrentThread() retrurns a pseudo handle, need
+       this to convert it into a handle another thread can use.
      */
     DuplicateHandle(GetCurrentProcess(),
                    GetCurrentThread(),
@@ -28,6 +28,7 @@ init_thread_intern(struct thread *thr)
                    0,
                    FALSE,
                    DUPLICATE_SAME_ACCESS);
+    /* XXX init thr->i here */
 #endif
 }
 
index 75aa25b..5bb6e6d 100644 (file)
@@ -4,20 +4,21 @@ typedef struct win32_cond { LONG waiters; HANDLE sem; } perl_cond;
 typedef DWORD perl_key;
 typedef HANDLE perl_thread;
 
-/* XXX Critical Sections used instead of mutexes: lightweight,
+#ifndef DONT_USE_CRITICAL_SECTION
+
+/* Critical Sections used instead of mutexes: lightweight,
  * but can't be communicated to child processes, and can't get
- * HANDLE to it for use elsewhere
+ * HANDLE to it for use elsewhere.
  */
-
-#ifndef DONT_USE_CRITICAL_SECTION
 typedef CRITICAL_SECTION perl_mutex;
 #define MUTEX_INIT(m) InitializeCriticalSection(m)
 #define MUTEX_LOCK(m) EnterCriticalSection(m)
 #define MUTEX_UNLOCK(m) LeaveCriticalSection(m)
 #define MUTEX_DESTROY(m) DeleteCriticalSection(m)
+
 #else
-typedef HANDLE perl_mutex;
 
+typedef HANDLE perl_mutex;
 #define MUTEX_INIT(m) \
     STMT_START {                                               \
        if ((*(m) = CreateMutex(NULL,FALSE,NULL)) == NULL)      \
@@ -46,44 +47,46 @@ typedef HANDLE perl_mutex;
  * so there's no separate mutex protecting access to (c)->waiters
  */
 #define COND_INIT(c) \
-    STMT_START {                                                \
-        (c)->waiters = 0;                                       \
-        (c)->sem = CreateSemaphore(NULL,0,LONG_MAX,NULL);       \
-        if ((c)->sem == NULL)                                   \
-            croak("panic: COND_INIT (%ld)",GetLastError());     \
+    STMT_START {                                               \
+       (c)->waiters = 0;                                       \
+       (c)->sem = CreateSemaphore(NULL,0,LONG_MAX,NULL);       \
+       if ((c)->sem == NULL)                                   \
+           croak("panic: COND_INIT (%ld)",GetLastError());     \
     } STMT_END
 
 #define COND_SIGNAL(c) \
-    STMT_START {                                                \
-        if (ReleaseSemaphore((c)->sem,1,NULL) == 0)             \
-            croak("panic: COND_SIGNAL (%ld)",GetLastError());   \
+    STMT_START {                                               \
+       if ((c)->waiters > 0 &&                                 \
+           ReleaseSemaphore((c)->sem,1,NULL) == 0)             \
+           croak("panic: COND_SIGNAL (%ld)",GetLastError());   \
     } STMT_END
 
 #define COND_BROADCAST(c) \
-    STMT_START {                                                \
-        if ((c)->waiters > 0 &&                                 \
-            ReleaseSemaphore((c)->sem,(c)->waiters,NULL) == 0)  \
-            croak("panic: COND_BROADCAST (%ld)",GetLastError());\
+    STMT_START {                                               \
+       if ((c)->waiters > 0 &&                                 \
+           ReleaseSemaphore((c)->sem,(c)->waiters,NULL) == 0)  \
+           croak("panic: COND_BROADCAST (%ld)",GetLastError());\
     } STMT_END
 
 #define COND_WAIT(c, m) \
-    STMT_START {                                                \
-        (c)->waiters++;                                         \
-        MUTEX_UNLOCK(m);                                        \
-        /* Note that there's no race here, since a              \
-         * COND_BROADCAST() on another thread will have seen the\
-         * right number of waiters (i.e. including this one) */ \
-        if (WaitForSingleObject((c)->sem,INFINITE)==WAIT_FAILED)\
-            croak("panic: COND_WAIT (%ld)",GetLastError());     \
-        MUTEX_LOCK(m);                                          \
-        (c)->waiters--;                                         \
+    STMT_START {                                               \
+       (c)->waiters++;                                         \
+       MUTEX_UNLOCK(m);                                        \
+       /* Note that there's no race here, since a              \
+        * COND_BROADCAST() on another thread will have seen the\
+        * right number of waiters (i.e. including this one) */ \
+       if (WaitForSingleObject((c)->sem,INFINITE)==WAIT_FAILED)\
+           croak("panic: COND_WAIT (%ld)",GetLastError());     \
+       /* XXX there may be an inconsequential race here */     \
+       MUTEX_LOCK(m);                                          \
+       (c)->waiters--;                                         \
     } STMT_END
 
 #define COND_DESTROY(c) \
-    STMT_START {                                                \
-        (c)->waiters = 0;                                       \
-        if (CloseHandle((c)->sem) == 0)                         \
-            croak("panic: COND_DESTROY (%ld)",GetLastError());  \
+    STMT_START {                                               \
+       (c)->waiters = 0;                                       \
+       if (CloseHandle((c)->sem) == 0)                         \
+           croak("panic: COND_DESTROY (%ld)",GetLastError());  \
     } STMT_END
 
 #define DETACH(t) \
@@ -110,12 +113,16 @@ END_EXTERN_C
 
 #define INIT_THREADS NOOP
 #define ALLOC_THREAD_KEY Perl_alloc_thread_key()
-#define INIT_THREAD_INTERN(thr) Perl_init_thread_intern(thr)
+#define HAVE_THREAD_INTERN
+
+struct thread_intern {
+    int dummy;                 /* XXX for now */
+};
 
 #define JOIN(t, avp)                                                   \
     STMT_START {                                                       \
        if ((WaitForSingleObject((t)->self,INFINITE) == WAIT_FAILED)    \
-             || (GetExitCodeThread((t)->self,(LPDWORD)(avp)) == 0))    \
+            || (GetExitCodeThread((t)->self,(LPDWORD)(avp)) == 0))     \
            croak("panic: JOIN");                                       \
     } STMT_END