thread.inc 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Run time library.
  4. Copyright (c) 2000 by the Free Pascal development team
  5. OS independent thread functions/overloads
  6. See the File COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {*****************************************************************************
  13. Threadvar initialization
  14. *****************************************************************************}
  15. procedure InitThread(stklen:cardinal);
  16. begin
  17. SysResetFPU;
  18. { ExceptAddrStack and ExceptObjectStack are threadvars }
  19. { so every thread has its on exception handling capabilities }
  20. SysInitExceptions;
  21. { Open all stdio fds again }
  22. SysInitStdio;
  23. InOutRes:=0;
  24. // ErrNo:=0;
  25. { Stack checking }
  26. StackLength:=stklen;
  27. StackBottom:=Sptr - StackLength;
  28. end;
  29. {*****************************************************************************
  30. Overloaded functions
  31. *****************************************************************************}
  32. function BeginThread(sa : Pointer;stacksize : dword;
  33. ThreadFunction : tthreadfunc;p : pointer;creationFlags : dword;
  34. var ThreadId : Longint) : DWord;
  35. begin
  36. BeginThread:=BeginThread(nil,StackSize,ThreadFunction,p,creationFlags,Dword(THreadId));
  37. end;
  38. function BeginThread(ThreadFunction : tthreadfunc) : DWord;
  39. var
  40. dummy : dword;
  41. begin
  42. BeginThread:=BeginThread(nil,DefaultStackSize,ThreadFunction,nil,0,dummy);
  43. end;
  44. function BeginThread(ThreadFunction : tthreadfunc;p : pointer) : DWord;
  45. var
  46. dummy : dword;
  47. begin
  48. BeginThread:=BeginThread(nil,DefaultStackSize,ThreadFunction,p,0,dummy);
  49. end;
  50. function BeginThread(ThreadFunction : tthreadfunc;p : pointer;var ThreadId : DWord) : DWord;
  51. begin
  52. BeginThread:=BeginThread(nil,DefaultStackSize,ThreadFunction,p,0,ThreadId);
  53. end;
  54. function BeginThread(ThreadFunction : tthreadfunc;p : pointer;var ThreadId : Longint) : DWord;
  55. begin
  56. BeginThread:=BeginThread(nil,DefaultStackSize,ThreadFunction,p,0,Dword(ThreadId));
  57. end;
  58. procedure EndThread;
  59. begin
  60. EndThread(0);
  61. end;
  62. {
  63. $Log$
  64. Revision 1.3 2002-11-14 12:40:06 jonas
  65. * the BeginThread() variant that allowed you to specify the stacksize
  66. still passed DefaultStackSize to the OS-specific routines
  67. Revision 1.2 2002/10/16 19:04:27 michael
  68. + More system-independent thread routines
  69. Revision 1.1 2002/10/14 19:39:17 peter
  70. * threads unit added for thread support
  71. }