Skip to content

Commit 1406464

Browse files
core: Inline Time::MarkingTimes() on non-Windows platforms
Time construction, copy, move and destruction all branch on Time::MarkingTimes(), previously a non-inlined call into libns3-core. The out-of-line definition only exists to work around a Windows access violation when referencing the static g_markingTimes from outside time.cc, so keep it under _WIN32 and provide an inline definition elsewhere.
1 parent d4c4921 commit 1406464

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/core/model/nstime.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,10 +772,20 @@ class CORE_EXPORT Time
772772
* The inline Time ctors need to check if g_markingTimes is allocated
773773
* before calling Mark(). Likewise, the dtor also needs to check before
774774
* calling Clear(). On Windows, attempting to access g_markingTimes
775-
* directly from outside the compilation unit is an access violation so
776-
* this method is provided to work around that limitation.
775+
* directly from outside the compilation unit is an access violation, so
776+
* on that platform we fall back to a non-inline function call. On other
777+
* platforms (Linux, macOS, BSD, ...) the static is directly accessible,
778+
* so the check is inlined, since it fires on every Time construction,
779+
* copy, move and destruction.
777780
*/
781+
#ifdef _WIN32
778782
static bool MarkingTimes();
783+
#else
784+
static bool MarkingTimes() noexcept
785+
{
786+
return g_markingTimes != nullptr;
787+
}
788+
#endif
779789

780790
public:
781791
/**

src/core/model/time.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,13 @@ Time::SetResolution(Unit unit, Resolution* resolution, const bool convert /* = t
278278
resolution->unit = unit;
279279
}
280280

281+
#ifdef _WIN32
281282
bool
282283
Time::MarkingTimes()
283284
{
284285
return (g_markingTimes != nullptr);
285286
}
287+
#endif
286288

287289
// static
288290
void

0 commit comments

Comments
 (0)