systhrd.inc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2002 by Peter Vreman,
  4. member of the Free Pascal development team.
  5. Embedded threading support implementation
  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. { resourcestrings are not supported by the system unit,
  13. they are in the objpas unit and not available for fpc/tp modes }
  14. const
  15. SNoThreads = 'This binary has no thread support compiled in.';
  16. SRecompileWithThreads = 'Recompile the application with a thread-driver in the program uses clause before other units using thread.';
  17. Procedure NoThreadError;NoReturn;
  18. begin
  19. {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
  20. If IsConsole then
  21. begin
  22. Writeln(StdErr,SNoThreads);
  23. Writeln(StdErr,SRecompileWithThreads);
  24. end;
  25. {$endif FPC_HAS_FEATURE_CONSOLEIO}
  26. { providing an rte on embedded makes often little sense and
  27. runerror(...) would pull in a lot of unnecessary code }
  28. system_exit;
  29. end;
  30. function NoGetCurrentThreadId : TThreadID;
  31. begin
  32. if IsMultiThread then
  33. NoThreadError
  34. else
  35. ThreadingAlreadyUsed:=true;
  36. result:=TThreadID(1);
  37. end;
  38. function NoBeginThread(sa : Pointer;stacksize : PtrUInt;
  39. ThreadFunction : tthreadfunc;p : pointer;
  40. creationFlags : dword; var ThreadId : TThreadID) : TThreadID;NoReturn;
  41. begin
  42. NoThreadError;
  43. end;
  44. procedure SysInitCriticalSection(var cs);
  45. begin
  46. end;
  47. procedure SysDoneCriticalSection(var cs);
  48. begin
  49. end;
  50. procedure SysEnterCriticalSection(var cs);
  51. begin
  52. end;
  53. function SysTryEnterCriticalSection(var cs):longint;
  54. begin
  55. end;
  56. procedure SysLeaveCriticalSection(var cs);
  57. begin
  58. end;
  59. const
  60. EmbeddedThreadManager : TThreadManager = (
  61. InitManager : Nil;
  62. DoneManager : Nil;
  63. { while this is pretty hacky, it reduces the size of typical embedded programs
  64. and works fine on arm and avr }
  65. BeginThread : @NoBeginThread;
  66. EndThread : TEndThreadHandler(@NoThreadError);
  67. SuspendThread : TThreadHandler(@NoThreadError);
  68. ResumeThread : TThreadHandler(@NoThreadError);
  69. KillThread : TThreadHandler(@NoThreadError);
  70. CloseThread : TThreadHandler(@NoThreadError);
  71. ThreadSwitch : TThreadSwitchHandler(@NoThreadError);
  72. WaitForThreadTerminate : TWaitForThreadTerminateHandler(@NoThreadError);
  73. ThreadSetPriority : TThreadSetPriorityHandler(@NoThreadError);
  74. ThreadGetPriority : TThreadGetPriorityHandler(@NoThreadError);
  75. GetCurrentThreadId : @NoGetCurrentThreadId;
  76. SetThreadDebugNameA : TThreadSetThreadDebugNameHandlerA(@NoThreadError);
  77. {$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
  78. SetThreadDebugNameU : TThreadSetThreadDebugNameHandlerU(@NoThreadError);
  79. {$endif FPC_HAS_FEATURE_UNICODESTRINGS}
  80. InitCriticalSection : @SysInitCriticalSection;
  81. DoneCriticalSection : @SysDoneCriticalSection;
  82. EnterCriticalSection : @SysEnterCriticalSection;
  83. TryEnterCriticalSection: @SysTryEnterCriticalSection;
  84. LeaveCriticalSection : @SysLeaveCriticalSection;
  85. InitThreadVar : TInitThreadVarHandler(@NoThreadError);
  86. RelocateThreadVar : TRelocateThreadVarHandler(@NoThreadError);
  87. AllocateThreadVars : @NoThreadError;
  88. ReleaseThreadVars : @NoThreadError;
  89. BasicEventCreate : TBasicEventCreateHandler(@NoThreadError);
  90. BasicEventdestroy : TBasicEventHandler(@NoThreadError);
  91. BasicEventResetEvent : TBasicEventHandler(@NoThreadError);
  92. BasicEventSetEvent : TBasicEventHandler(@NoThreadError);
  93. BasicEventWaitFor : TBasicEventWaitForHandler(@NoThreadError);
  94. RTLEventCreate : TRTLCreateEventHandler(@NoThreadError);
  95. RTLEventdestroy : TRTLEventHandler(@NoThreadError);
  96. RTLEventSetEvent : TRTLEventHandler(@NoThreadError);
  97. RTLEventResetEvent : TRTLEventHandler(@NoThreadError);
  98. RTLEventWaitFor : TRTLEventHandler(@NoThreadError);
  99. RTLEventwaitfortimeout : TRTLEventHandlerTimeout(@NoThreadError);
  100. );
  101. Procedure InitSystemThreads;
  102. begin
  103. { calling SetThreadManager pulls in too much code }
  104. CurrentTM:=EmbeddedThreadManager;
  105. end;