Преглед изворни кода

* Fix to be able to allocate threadvars when code outside FPC creates a thread

git-svn-id: trunk@5474 -
michael пре 18 година
родитељ
комит
285e02ba83
1 измењених фајлова са 15 додато и 4 уклоњено
  1. 15 4
      rtl/unix/cthreads.pp

+ 15 - 4
rtl/unix/cthreads.pp

@@ -101,10 +101,6 @@ Type  PINTRTLEvent = ^TINTRTLEvent;
         inc(threadvarblocksize,size);
       end;
 
-    function CRelocateThreadvar(offset : dword) : pointer;
-      begin
-        CRelocateThreadvar:=pthread_getspecific(tlskey)+Offset;
-      end;
 
 
     procedure CAllocateThreadVars;
@@ -121,6 +117,21 @@ Type  PINTRTLEvent = ^TINTRTLEvent;
         pthread_setspecific(tlskey,dataindex);
       end;
 
+    function CRelocateThreadvar(offset : dword) : pointer;
+
+    var
+      P : Pointer;
+
+      begin
+        P:=pthread_getspecific(tlskey);
+        if (P=Nil) then
+          begin
+          CAllocateThreadvars;
+          // If this also goes wrong: bye bye threadvars...
+          P:=pthread_getspecific(tlskey);
+          end;
+        CRelocateThreadvar:=P+Offset;
+      end;
 
     procedure CReleaseThreadVars;
       begin