systhrd.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. FreeRTOS 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;
  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. RunError(232)
  27. end;
  28. function NoGetCurrentThreadId : TThreadID;
  29. begin
  30. if IsMultiThread then
  31. NoThreadError
  32. else
  33. ThreadingAlreadyUsed:=true;
  34. result:=TThreadID(1);
  35. end;
  36. function NoBeginThread(sa : Pointer;stacksize : PtrUInt;
  37. ThreadFunction : tthreadfunc;p : pointer;
  38. creationFlags : dword; var ThreadId : TThreadID) : TThreadID;
  39. begin
  40. NoThreadError;
  41. result:=tthreadid(-1);
  42. end;
  43. procedure SysInitCriticalSection(var cs);
  44. begin
  45. end;
  46. procedure SysDoneCriticalSection(var cs);
  47. begin
  48. end;
  49. procedure SysEnterCriticalSection(var cs);
  50. begin
  51. end;
  52. function SysTryEnterCriticalSection(var cs):longint;
  53. begin
  54. end;
  55. procedure SysLeaveCriticalSection(var cs);
  56. begin
  57. end;
  58. const
  59. FreeRTOSThreadManager : TThreadManager = (
  60. InitManager : Nil;
  61. DoneManager : Nil;
  62. { while this is pretty hacky, it reduces the size of typical embedded programs
  63. and works fine on arm and avr }
  64. BeginThread : @NoBeginThread;
  65. EndThread : TEndThreadHandler(@NoThreadError);
  66. SuspendThread : TThreadHandler(@NoThreadError);
  67. ResumeThread : TThreadHandler(@NoThreadError);
  68. KillThread : TThreadHandler(@NoThreadError);
  69. CloseThread : TThreadHandler(@NoThreadError);
  70. ThreadSwitch : TThreadSwitchHandler(@NoThreadError);
  71. WaitForThreadTerminate : TWaitForThreadTerminateHandler(@NoThreadError);
  72. ThreadSetPriority : TThreadSetPriorityHandler(@NoThreadError);
  73. ThreadGetPriority : TThreadGetPriorityHandler(@NoThreadError);
  74. GetCurrentThreadId : @NoGetCurrentThreadId;
  75. SetThreadDebugNameA : TThreadSetThreadDebugNameHandlerA(@NoThreadError);
  76. {$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
  77. SetThreadDebugNameU : TThreadSetThreadDebugNameHandlerU(@NoThreadError);
  78. {$endif FPC_HAS_FEATURE_UNICODESTRINGS}
  79. InitCriticalSection : @SysInitCriticalSection;
  80. DoneCriticalSection : @SysDoneCriticalSection;
  81. EnterCriticalSection : @SysEnterCriticalSection;
  82. TryEnterCriticalSection: @SysTryEnterCriticalSection;
  83. LeaveCriticalSection : @SysLeaveCriticalSection;
  84. InitThreadVar : TInitThreadVarHandler(@NoThreadError);
  85. RelocateThreadVar : TRelocateThreadVarHandler(@NoThreadError);
  86. AllocateThreadVars : @NoThreadError;
  87. ReleaseThreadVars : @NoThreadError;
  88. BasicEventCreate : TBasicEventCreateHandler(@NoThreadError);
  89. BasicEventdestroy : TBasicEventHandler(@NoThreadError);
  90. BasicEventResetEvent : TBasicEventHandler(@NoThreadError);
  91. BasicEventSetEvent : TBasicEventHandler(@NoThreadError);
  92. BasicEventWaitFor : TBasicEventWaitForHandler(@NoThreadError);
  93. RTLEventCreate : TRTLCreateEventHandler(@NoThreadError);
  94. RTLEventdestroy : TRTLEventHandler(@NoThreadError);
  95. RTLEventSetEvent : TRTLEventHandler(@NoThreadError);
  96. RTLEventResetEvent : TRTLEventHandler(@NoThreadError);
  97. RTLEventWaitFor : TRTLEventHandler(@NoThreadError);
  98. RTLEventwaitfortimeout : TRTLEventHandlerTimeout(@NoThreadError);
  99. );
  100. Procedure InitSystemThreads;
  101. begin
  102. SetThreadManager(FreeRTOSThreadManager);
  103. end;