Jelajahi Sumber

* use pthread_kill() for Suspend/Resume in cthreads

git-svn-id: trunk@5280 -
Jonas Maebe 19 tahun lalu
induk
melakukan
edafc80d8c

+ 2 - 0
rtl/darwin/pthread.inc

@@ -60,6 +60,8 @@ function  pthread_cond_destroy(_para1:Ppthread_cond_t):cint;cdecl;external 'c' n
 function  pthread_cond_init(_para1:Ppthread_cond_t;_para2:Ppthread_condattr_t):cint;cdecl;external  'c' name 'pthread_cond_init';
 function  pthread_cond_signal(_para1:Ppthread_cond_t):cint;cdecl;external 'c' name 'pthread_cond_signal';
 function  pthread_cond_wait(_para1:Ppthread_cond_t;_para2:Ppthread_mutex_t):cint;cdecl;external 'c' name 'pthread_cond_wait';
+function pthread_kill(__thread:pthread_t; __signo:cint):cint;cdecl;external 'c';
+
 
 function sem_init(__sem:Psem_t; __pshared:cint;__value:cuint):cint;cdecl; external 'c' name 'sem_init';
 function sem_destroy(__sem:Psem_t):cint;cdecl;external 'c' name 'sem_destroy';

+ 1 - 0
rtl/freebsd/pthread.inc

@@ -62,6 +62,7 @@ function pthread_cond_destroy(_para1:Ppthread_cond_t):cint;cdecl;external;
 function pthread_cond_init(_para1:Ppthread_cond_t;_para2:Ppthread_condattr_t):cint;cdecl;external;
 function pthread_cond_signal(_para1:Ppthread_cond_t):cint;cdecl;external;
 function pthread_cond_wait(_para1:Ppthread_cond_t;_para2:Ppthread_mutex_t):cint;cdecl;external;
+function pthread_kill(__thread:pthread_t; __signo:cint):cint;cdecl;external;
 
 function sem_init(__sem:Psem_t; __pshared:cint;__value:dword):cint;cdecl; external;
 function sem_destroy(__sem:Psem_t):cint;cdecl;external ;

+ 2 - 17
rtl/linux/tthread.inc

@@ -193,18 +193,7 @@ begin
       CurrentTM.SemaphoreWait(FSem);
     end else begin
       FSuspendedExternal := true;
-      // naughty hack if the user doesn't have Linux with NPTL...
-      // in that case, the PID of threads will not be identical
-      // to the other threads, which means that our thread is a normal
-      // process that we can suspend via SIGSTOP...
-      // this violates POSIX, but is the way it works on the
-      // LinuxThreads pthread implementation. Not with NPTL, but in that case
-      // getpid(2) also behaves properly and returns the same PID for
-      // all threads. Thats actually (FINALLY!) native thread support :-)
-      if FPid <> GMainPID then begin
-        FSuspended := true;
-        fpkill(FPid, SIGSTOP);
-      end;
+      SuspendThread(FHandle);
     end;
   end;
 end;
@@ -219,11 +208,7 @@ begin
     end;
   end else begin
     FSuspendedExternal := false;
-    // see .Suspend
-    if FPid <> GMainPID then begin
-      FSuspended := False;
-      fpkill(FPid, SIGCONT);
-    end;  end;
+    ResumeThread(FHandle);
 end;
 
 

+ 1 - 0
rtl/solaris/pthread.inc

@@ -158,6 +158,7 @@ function  pthread_cond_destroy(_para1:Ppthread_cond_t):cint;cdecl;external 'c' n
 function  pthread_cond_init(_para1:Ppthread_cond_t;_para2:Ppthread_condattr_t):cint;cdecl;external  'c' name 'pthread_cond_init';
 function  pthread_cond_signal(_para1:Ppthread_cond_t):cint;cdecl;external 'c' name 'pthread_cond_signal';
 function  pthread_cond_wait(_para1:Ppthread_cond_t;_para2:Ppthread_mutex_t):cint;cdecl;external 'c' name 'pthread_cond_wait';
+function pthread_kill(__thread:pthread_t; __signo:cint):cint;cdecl;external 'c';
 
 function sem_init(__sem:Psem_t; __pshared:cint;__value:cuint):cint;cdecl; external 'c' name 'sem_init';
 function sem_destroy(__sem:Psem_t):cint;cdecl;external 'c' name 'sem_destroy';

+ 2 - 2
rtl/unix/cthreads.pp

@@ -249,13 +249,13 @@ Type  PINTRTLEvent = ^TINTRTLEvent;
 
   function  CSuspendThread (threadHandle : TThreadID) : dword;
     begin
-      {$Warning SuspendThread needs to be implemented}
+      result := pthread_kill(threadHandle,SIGSTOP);
     end;
 
 
   function  CResumeThread  (threadHandle : TThreadID) : dword;
     begin
-      {$Warning ResumeThread needs to be implemented}
+      result := pthread_kill(threadHandle,SIGCONT);
     end;