Prechádzať zdrojové kódy

* 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 rokov pred
rodič
commit
cada770f9e
2 zmenil súbory, kde vykonal 10 pridanie a 4 odobranie
  1. 9 3
      rtl/unix/cthreads.pp
  2. 1 1
      rtl/unix/tthread.inc

+ 9 - 3
rtl/unix/cthreads.pp

@@ -627,7 +627,9 @@ begin
     { the process exits                                              }
     { the process exits                                              }
     sem_unlink(name)
     sem_unlink(name)
   else
   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;
 end;
 {$endif}
 {$endif}
 
 
@@ -644,7 +646,9 @@ begin
   if sem_init(PSemaphore(cIntSemaphoreInit), 0, ord(initvalue)) <> 0 then
   if sem_init(PSemaphore(cIntSemaphoreInit), 0, ord(initvalue)) <> 0 then
     begin
     begin
       FreeMem(cIntSemaphoreInit);
       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;
     end;
 {$else}
 {$else}
 {$ifdef has_sem_open}
 {$ifdef has_sem_open}
@@ -658,7 +662,9 @@ begin
   if (fppipe(PFilDes(cIntSemaphoreInit)^) <> 0) then
   if (fppipe(PFilDes(cIntSemaphoreInit)^) <> 0) then
     begin
     begin
       FreeMem(cIntSemaphoreInit);
       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
     end
   else if initvalue then
   else if initvalue then
     cSemaphorePost(cIntSemaphoreInit);
     cSemaphorePost(cIntSemaphoreInit);

+ 1 - 1
rtl/unix/tthread.inc

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