2
0
Эх сурвалжийг харах

* changed return value in case of failure in ThreadManager.SemaphoreInit
from nil to pointer(-1), because nil/0 is a valid return value for
sem_open() on some platforms

git-svn-id: trunk@26079 -

Jonas Maebe 11 жил өмнө
parent
commit
cada770f9e

+ 9 - 3
rtl/unix/cthreads.pp

@@ -627,7 +627,9 @@ begin
     { the process exits                                              }
     sem_unlink(name)
   else
-    cIntSemaphoreOpen:=NIL;
+    { 0 is a valid for sem_open on some platforms; pointer(-1) shouldn't
+      be valid anywhere, even for sem_init }
+    cIntSemaphoreOpen:=pointer(-1);
 end;
 {$endif}
 
@@ -644,7 +646,9 @@ begin
   if sem_init(PSemaphore(cIntSemaphoreInit), 0, ord(initvalue)) <> 0 then
     begin
       FreeMem(cIntSemaphoreInit);
-      cIntSemaphoreInit:=NIL;
+      { 0 is a valid for sem_open on some platforms; pointer(-1) shouldn't
+        be valid anywhere, even for sem_init }
+      cIntSemaphoreInit:=pointer(-1);
     end;
 {$else}
 {$ifdef has_sem_open}
@@ -658,7 +662,9 @@ begin
   if (fppipe(PFilDes(cIntSemaphoreInit)^) <> 0) then
     begin
       FreeMem(cIntSemaphoreInit);
-      cIntSemaphoreInit:=nil;
+      { 0 is a valid for sem_open on some platforms; pointer(-1) shouldn't
+        be valid anywhere, even for sem_init }
+      cIntSemaphoreInit:=pointer(-1);
     end
   else if initvalue then
     cSemaphorePost(cIntSemaphoreInit);

+ 1 - 1
rtl/unix/tthread.inc

@@ -178,7 +178,7 @@ begin
   // via BeginThread and creates the first TThread Object in there!
   InitThreads;
   FSem := CurrentTM.SemaphoreInit();
-  if FSem = nil then
+  if FSem = pointer(-1) then
     raise EThread.create('Semaphore init failed (possibly too many concurrent threads)');
   WRITE_DEBUG('thread ', ptruint(self), ' created semaphore ', ptruint(FSem));
   FSuspended := CreateSuspended;