~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to rtl/darwin/tthread.inc

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2005-05-30 11:59:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050530115910-x5pbzm4qqta4i94h
Tags: 2.0.0-2
debian/fp-compiler.postinst.in: forgot to reapply the patch that
correctly creates the slave link to pc(1).  (Closes: #310907)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
{
2
 
    $Id: tthread.inc,v 1.3 2004/03/04 12:42:44 jonas Exp $
 
2
    $Id: tthread.inc,v 1.7 2005/03/25 22:53:39 jonas Exp $
3
3
    This file is part of the Free Component Library (FCL)
4
4
    Copyright (c) 1999-2000 by Peter Vreman
5
5
 
19
19
  What follows, is a short description on my implementation of TThread.
20
20
  Most information can also be found by reading the source and accompanying
21
21
  comments.
22
 
  
 
22
 
23
23
  A thread is created using BeginThread, which in turn calls
24
24
  pthread_create. So the threads here are always posix threads.
25
25
  Posix doesn't define anything for suspending threads as this is
26
26
  inherintly unsafe. Just don't suspend threads at points they cannot
27
27
  control. Therefore, I didn't implement .Suspend() if its called from
28
28
  outside the threads execution flow (except on Linux _without_ NPTL).
29
 
  
 
29
 
30
30
  The implementation for .suspend uses a semaphore, which is initialized
31
31
  at thread creation. If the thread tries to suspend itself, we simply
32
32
  let it wait on the semaphore until it is unblocked by someone else
37
37
  are possible.
38
38
  1) the system has the LinuxThreads pthread implementation
39
39
  2) the system has NPTL as the pthread implementation.
40
 
  
 
40
 
41
41
  In the first case, each thread is a process on its own, which as far as
42
42
  know actually violates posix with respect to signal handling.
43
43
  But we can detect this case, because getpid(2) will
48
48
  PID across all threads, which is detected, and TThread.Suspend() does
49
49
  nothing in that case. This should probably be changed, but I know of
50
50
  no way to suspend a thread when using NPTL.
51
 
  
 
51
 
52
52
  If the symbol LINUX is not defined, then the unimplemented
53
53
  function SuspendThread is called.
54
 
  
 
54
 
55
55
  Johannes Berg <johannes@sipsolutions.de>, Sunday, November 16 2003
56
56
}
57
57
 
125
125
function ThreadFunc(parameter: Pointer): LongInt;
126
126
var
127
127
  LThread: TThread;
128
 
  c: char;
129
128
begin
130
129
  WRITE_DEBUG('ThreadFunc is here...');
131
130
  LThread := TThread(parameter);
133
132
  try
134
133
    if LThread.FInitialSuspended then begin
135
134
      SemaphoreWait(LThread.FSem);
136
 
      if not LThread.FInitialSuspended then begin
 
135
      if not LThread.FSuspended then begin
 
136
        LThread.FInitialSuspended := false;
137
137
        WRITE_DEBUG('going into LThread.Execute');
138
138
        LThread.Execute;
139
139
      end;
231
231
begin
232
232
  if (not FSuspendedExternal) then begin
233
233
    if FSuspended then begin
 
234
      FSuspended := False;
234
235
      SemaphorePost(FSem);
235
 
      FInitialSuspended := false;
236
 
      FSuspended := False;
237
236
    end;
238
237
  end else begin
 
238
    FSuspendedExternal := false;
239
239
    ResumeThread(FHandle);
240
 
    FSuspendedExternal := false;
241
240
  end;
242
241
end;
243
242
 
279
278
      Result := I;
280
279
end;
281
280
 
282
 
procedure TThread.Synchronize(Method: TThreadMethod);
283
 
begin
284
 
{$TODO someone with more clue of the GUI stuff will have to do this}
285
 
end;
286
281
 
287
282
procedure TThread.SetPriority(Value: TThreadPriority);
288
283
begin
291
286
 
292
287
{
293
288
  $Log: tthread.inc,v $
294
 
  Revision 1.3  2004/03/04 12:42:44  jonas
295
 
    - removed legacy code
296
 
 
297
 
  Revision 1.2  2004/03/04 12:34:36  jonas
298
 
    * fixed compilation
299
 
 
300
 
  Revision 1.1  2004/01/04 20:05:38  jonas
301
 
    * first working version of the Darwin/Mac OS X (for PowerPC) RTL
302
 
      Several non-essential units are still missing, but make cycle works
303
 
 
304
 
  Revision 1.7  2003/11/22 11:04:08  marco
305
 
   * Johill: suspend fix
306
 
 
307
 
  Revision 1.6  2003/11/19 10:12:02  marco
308
 
   * more cleanups
309
 
 
310
 
  Revision 1.5  2003/11/17 10:05:51  marco
311
 
   * threads for FreeBSD. Not working tho
312
 
 
313
 
  Revision 1.4  2003/11/17 08:27:49  marco
314
 
   * pthreads based ttread from Johannes Berg
315
 
 
316
 
  Revision 1.3  2003/11/10 16:54:28  marco
317
 
   * new oldlinux unit. 1_0 defines killed in some former FCL parts.
318
 
 
319
 
  Revision 1.2  2003/11/03 09:42:28  marco
320
 
   * Peter's Cardinal<->Longint fixes patch
321
 
 
322
 
  Revision 1.1  2003/10/06 21:01:06  peter
323
 
    * moved classes unit to rtl
324
 
 
325
 
  Revision 1.9  2003/10/06 17:06:55  florian
326
 
    * applied Johannes Berg's patch for exception handling in threads
327
 
 
328
 
  Revision 1.8  2003/09/20 15:10:30  marco
329
 
   * small fixes. fcl now compiles
330
 
 
331
 
  Revision 1.7  2002/12/18 20:44:36  peter
332
 
    * use fillchar to clear sigset
333
 
 
334
 
  Revision 1.6  2002/09/07 15:15:27  peter
335
 
    * old logs removed and tabs fixed
 
289
  Revision 1.7  2005/03/25 22:53:39  jonas
 
290
    * fixed several warnings and notes about unused variables (mainly) or
 
291
      uninitialised use of variables/function results (a few)
 
292
 
 
293
  Revision 1.6  2005/03/01 20:38:49  jonas
 
294
    * fixed web bug 3387: if one called resume right after creating a
 
295
      suspended thread, it was possible that resume was executed before
 
296
      that thread had completed its initialisation in BeginThread ->
 
297
      FInitialSuspended was set to false in resume and nevertheless a
 
298
      semafore was posted
 
299
    * second problem fixed: set FSuspended to false before waking up the
 
300
      thread, so that it doesn't get FSuspended = true right after waking
 
301
      up. This should be done atomically to be completely correct though.
 
302
 
 
303
  Revision 1.5  2005/02/25 21:41:09  florian
 
304
    * generic tthread.synchronize
 
305
    * delphi compatible wakemainthread
 
306
 
 
307
  Revision 1.4  2005/02/14 17:13:22  peter
 
308
    * truncate log
336
309
 
337
310
}