Parcourir la source

* make webtbs/tw30535 also working on OSes using cthreads

git-svn-id: trunk@35570 -
florian il y a 8 ans
Parent
commit
1b371b15e3
1 fichiers modifiés avec 11 ajouts et 5 suppressions
  1. 11 5
      rtl/unix/cthreads.pp

+ 11 - 5
rtl/unix/cthreads.pp

@@ -306,10 +306,14 @@ Type  PINTRTLEvent = ^TINTRTLEvent;
         pthread_exit(ThreadMain);
       end;
 
-  Procedure InitCThreading;
+
+  var
+    TLSInitialized : longbool = FALSE;
+
+  Procedure InitCTLS;
   
   begin
-    if (InterLockedExchange(longint(IsMultiThread),ord(true)) = 0) then
+    if (InterLockedExchange(longint(TLSInitialized),ord(true)) = 0) then
       begin
         { We're still running in single thread mode, setup the TLS }
         pthread_key_create(@TLSKey,nil);
@@ -338,8 +342,10 @@ Type  PINTRTLEvent = ^TINTRTLEvent;
       writeln('Creating new thread');
 {$endif DEBUG_MT}
       { Initialize multithreading if not done }
-      if not IsMultiThread then
-        InitCThreading;
+      if not TLSInitialized then
+        InitCTLS;
+      IsMultiThread:=true;
+
       { the only way to pass data to the newly created thread
         in a MT safe way, is to use the heap }
       new(ti);
@@ -817,7 +823,7 @@ begin
   Writeln('InitThreads : ',Result);
 {$endif DEBUG_MT}
   // We assume that if you set the thread manager, the application is multithreading.
-  InitCThreading;
+  InitCTLS;
 end;
 
 Function CDoneThreads : Boolean;