From e3bc8a8cc5a925fca506d1d920b086e2223b026b Mon Sep 17 00:00:00 2001 From: Arnaud Bouchez Date: Mon, 30 Oct 2023 20:16:26 +0100 Subject: [PATCH] new NODIRECTTHREADMANAGER conditional --- src/core/mormot.core.os.pas | 8 +++- src/core/mormot.core.os.posix.inc | 65 +++++++++++++++++-------------- src/mormot.commit.inc | 2 +- src/mormot.defines.inc | 3 ++ 4 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/core/mormot.core.os.pas b/src/core/mormot.core.os.pas index b71920bd7..86f178518 100644 --- a/src/core/mormot.core.os.pas +++ b/src/core/mormot.core.os.pas @@ -2723,7 +2723,11 @@ procedure DeleteCriticalSection(var cs : TRTLCriticalSection); {$ifdef OSPOSIX} -{$ifdef OSDARWIN} // try to stabilize MacOS pthreads API calls +{$ifndef OSLINUX} // try to stabilize MacOS/BSD pthreads API calls + {$define NODIRECTTHREADMANAGER} +{$endif OSLINUX} + +{$ifdef NODIRECTTHREADMANAGER} // try to stabilize MacOS pthreads API calls function GetCurrentThreadId: TThreadID; inline; function TryEnterCriticalSection(var cs: TRTLCriticalSection): integer; inline; procedure EnterCriticalSection(var cs: TRTLCriticalSection); inline; @@ -2747,7 +2751,7 @@ procedure LeaveCriticalSection(var cs: TRTLCriticalSection); inline; // - defined in mormot.core.os for inlined FpcCurrentThreadManager call var TryEnterCriticalSection: function(var cs: TRTLCriticalSection): integer; -{$endif OSDARWIN} +{$endif NODIRECTTHREADMANAGER} {$endif OSPOSIX} diff --git a/src/core/mormot.core.os.posix.inc b/src/core/mormot.core.os.posix.inc index 83ca6194e..ff4c10fe0 100644 --- a/src/core/mormot.core.os.posix.inc +++ b/src/core/mormot.core.os.posix.inc @@ -560,6 +560,31 @@ begin result := 0; // fixed result on a window-abstracted system end; + +{$ifdef NODIRECTTHREADMANAGER} // try to stabilize MacOS/BSD pthreads API calls + +function GetCurrentThreadId: TThreadID; +begin + result := system.GetCurrentThreadID(); +end; + +function TryEnterCriticalSection(var cs: TRTLCriticalSection): integer; +begin + result := system.TryEnterCriticalSection(cs); +end; + +procedure EnterCriticalSection(var cs: TRTLCriticalSection); +begin + system.EnterCriticalSection(cs); +end; + +procedure LeaveCriticalSection(var cs: TRTLCriticalSection); +begin + system.LeaveCriticalSection(cs); +end; + +{$endif NODIRECTTHREADMANAGER} + const // Date Translation - see http://en.wikipedia.org/wiki/Julian_day HoursPerDay = 24; MinsPerHour = 60; @@ -695,28 +720,6 @@ begin result.MilliSecond := tz.tv_usec div MicroSecsPerMilliSec; end; -// try to stabilize MacOS pthreads API calls - -function GetCurrentThreadId: TThreadID; -begin - result := system.GetCurrentThreadID(); -end; - -function TryEnterCriticalSection(var cs: TRTLCriticalSection): integer; -begin - result := system.TryEnterCriticalSection(cs); -end; - -procedure EnterCriticalSection(var cs: TRTLCriticalSection); -begin - system.EnterCriticalSection(cs); -end; - -procedure LeaveCriticalSection(var cs: TRTLCriticalSection); -begin - system.LeaveCriticalSection(cs); -end; - {$else} @@ -3743,9 +3746,9 @@ var SR: TSearchRec; {$endif OSLINUX} {$endif OSBSDDARWIN} - {$ifndef OSDARWIN} + {$ifndef NODIRECTTHREADMANAGER} tm: TThreadManager; - {$endif OSDARWIN} + {$endif NODIRECTTHREADMANAGER} begin // retrieve Kernel and Hardware information StdOutIsTTY := not IsDebuggerPresent and @@ -3975,18 +3978,20 @@ begin [SystemInfo.dwNumberOfProcessors, modname, CpuInfoText]); // intialize supported APIs TimeZoneLocalBias := -GetLocalTimeOffset; - {$ifdef OSDARWIN} - mach_timebase_info(mach_timeinfo); - mach_timecoeff := mach_timeinfo.Numer / mach_timeinfo.Denom; - mach_timenanosecond := (mach_timeinfo.Numer = 1) and - (mach_timeinfo.Denom = 1); - {$else} + {$ifndef NODIRECTTHREADMANAGER} // for inlined RTL calls (avoid one level of redirection) GetThreadManager(tm); @GetCurrentThreadId := @tm.GetCurrentThreadId; @TryEnterCriticalSection := @tm.TryEnterCriticalSection; @EnterCriticalSection := @tm.EnterCriticalSection; @LeaveCriticalSection := @tm.LeaveCriticalSection; + {$endif NODIRECTTHREADMANAGER} + {$ifdef OSDARWIN} + mach_timebase_info(mach_timeinfo); + mach_timecoeff := mach_timeinfo.Numer / mach_timeinfo.Denom; + mach_timenanosecond := (mach_timeinfo.Numer = 1) and + (mach_timeinfo.Denom = 1); + {$else} // try Linux kernel 2.6.32+ or FreeBSD 8.1+ fastest clocks if clock_gettime(CLOCK_REALTIME_COARSE, @tp) = 0 then CLOCK_REALTIME_FAST := CLOCK_REALTIME_COARSE; diff --git a/src/mormot.commit.inc b/src/mormot.commit.inc index 2b9e8fdc9..347521e82 100644 --- a/src/mormot.commit.inc +++ b/src/mormot.commit.inc @@ -1 +1 @@ -'2.1.6231' +'2.1.6232' diff --git a/src/mormot.defines.inc b/src/mormot.defines.inc index b3479ed7a..580c5998e 100644 --- a/src/mormot.defines.inc +++ b/src/mormot.defines.inc @@ -40,6 +40,9 @@ // if defined, SetThreadName() would not raise the exception used to set the // thread name: to be defined if you have issues when debugging your application +{.$define NODIRECTTHREADMANAGER} +// on POSIX, omit direct GetThreadManager() API calls and just use RTL functions + {.$define NOEXCEPTIONINTERCEPT} // if defined, exceptions shall not be intercepted nor logged