* 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 -
This commit is contained in:
Jonas Maebe 2013-11-13 16:51:11 +00:00
parent 3ce0b33302
commit cada770f9e
2 changed files with 10 additions and 4 deletions

View File

@ -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);

View File

@ -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;