Skip to content

Commit

Permalink
Enable mutex implementation and inlining strategy to be configurable …
Browse files Browse the repository at this point in the history
…at build-time
  • Loading branch information
mattrm456 authored Jun 21, 2024
1 parent a9571fa commit a624d18
Show file tree
Hide file tree
Showing 25 changed files with 962 additions and 512 deletions.
15 changes: 15 additions & 0 deletions cmake/templates/ntccfg_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,27 @@ namespace ntccfg {
// Build with metrics.
#define NTC_BUILD_WITH_METRICS @NTF_BUILD_WITH_METRICS@

// Build with inlining suggested.
#define NTC_BUILD_WITH_INLINING_SUGGESTED @NTF_BUILD_WITH_INLINING_SUGGESTED@

// Build with inlining forced.
#define NTC_BUILD_WITH_INLINING_FORCED @NTF_BUILD_WITH_INLINING_FORCED@

// Build with inlining disabled.
#define NTC_BUILD_WITH_INLINING_DISABLED @NTF_BUILD_WITH_INLINING_DISABLED@

// Build with branch prediction.
#define NTC_BUILD_WITH_BRANCH_PREDICTION @NTF_BUILD_WITH_BRANCH_PREDICTION@

// Build with mutually-exclusive locks implemented with spin locks.
#define NTC_BUILD_WITH_SPIN_LOCKS @NTF_BUILD_WITH_SPIN_LOCKS@

// Build with mutually-exclusive locks implemented with userspace mutexes.
#define NTC_BUILD_WITH_USERSPACE_MUTEXES @NTF_BUILD_WITH_USERSPACE_MUTEXES@

// Build with mutually-exclusive locks implemented with system mutexes.
#define NTC_BUILD_WITH_SYSTEM_MUTEXES @NTF_BUILD_WITH_SYSTEM_MUTEXES@

// Build with mutually-exclusive locks implemented with recursive mutexes.
#define NTC_BUILD_WITH_RECURSIVE_MUTEXES @NTF_BUILD_WITH_RECURSIVE_MUTEXES@

Expand Down
21 changes: 21 additions & 0 deletions cmake/templates/ntscfg_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,30 @@ namespace ntscfg {
// Build with metrics.
#define NTS_BUILD_WITH_METRICS @NTF_BUILD_WITH_METRICS@

// Build with inlining suggested.
#define NTS_BUILD_WITH_INLINING_SUGGESTED @NTF_BUILD_WITH_INLINING_SUGGESTED@

// Build with inlining forced.
#define NTS_BUILD_WITH_INLINING_FORCED @NTF_BUILD_WITH_INLINING_FORCED@

// Build with inlining disabled.
#define NTS_BUILD_WITH_INLINING_DISABLED @NTF_BUILD_WITH_INLINING_DISABLED@

// Build with branch prediction.
#define NTS_BUILD_WITH_BRANCH_PREDICTION @NTF_BUILD_WITH_BRANCH_PREDICTION@

// Build with mutually-exclusive locks implemented with spin locks.
#define NTS_BUILD_WITH_SPIN_LOCKS @NTF_BUILD_WITH_SPIN_LOCKS@

// Build with mutually-exclusive locks implemented with userspace mutexes.
#define NTS_BUILD_WITH_USERSPACE_MUTEXES @NTF_BUILD_WITH_USERSPACE_MUTEXES@

// Build with mutually-exclusive locks implemented with system mutexes.
#define NTS_BUILD_WITH_SYSTEM_MUTEXES @NTF_BUILD_WITH_SYSTEM_MUTEXES@

// Build with mutually-exclusive locks implemented with recursive mutexes.
#define NTS_BUILD_WITH_RECURSIVE_MUTEXES @NTF_BUILD_WITH_RECURSIVE_MUTEXES@

// Build with a test allocator that dumps stack traces upon memory leaks.
#define NTS_BUILD_WITH_STACK_TRACE_TEST_ALLOCATOR @NTF_BUILD_WITH_STACK_TRACE_TEST_ALLOCATOR@

Expand Down
66 changes: 66 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,18 @@ if [[ -z "${NTF_CONFIGURE_WITH_METRICS}" ]]; then
NTF_CONFIGURE_WITH_METRICS=1
fi

if [[ -z "${NTF_CONFIGURE_WITH_INLINING_SUGGESTED}" ]]; then
NTF_CONFIGURE_WITH_INLINING_SUGGESTED=0
fi

if [[ -z "${NTF_CONFIGURE_WITH_INLINING_FORCED}" ]]; then
NTF_CONFIGURE_WITH_INLINING_FORCED=1
fi

if [[ -z "${NTF_CONFIGURE_WITH_INLINING_DISABLED}" ]]; then
NTF_CONFIGURE_WITH_INLINING_DISABLED=0
fi

if [[ -z "${NTF_CONFIGURE_WITH_BRANCH_PREDICTION}" ]]; then
NTF_CONFIGURE_WITH_BRANCH_PREDICTION=1
fi
Expand All @@ -327,6 +339,22 @@ if [[ -z "${NTF_CONFIGURE_WITH_SPIN_LOCKS}" ]]; then
NTF_CONFIGURE_WITH_SPIN_LOCKS=0
fi

if [[ -z "${NTF_CONFIGURE_WITH_USERSPACE_MUTEXES}" ]]; then
if [[ "${NTF_CONFIGURE_UNAME}" == "Linux" ]]; then
NTF_CONFIGURE_WITH_USERSPACE_MUTEXES=1
else
NTF_CONFIGURE_WITH_USERSPACE_MUTEXES=0
fi
fi

if [[ -z "${NTF_CONFIGURE_WITH_SYSTEM_MUTEXES}" ]]; then
if [[ "${NTF_CONFIGURE_UNAME}" == "Linux" ]]; then
NTF_CONFIGURE_WITH_SYSTEM_MUTEXES=0
else
NTF_CONFIGURE_WITH_SYSTEM_MUTEXES=1
fi
fi

if [[ -z "${NTF_CONFIGURE_WITH_RECURSIVE_MUTEXES}" ]]; then
NTF_CONFIGURE_WITH_RECURSIVE_MUTEXES=0
fi
Expand Down Expand Up @@ -451,9 +479,16 @@ usage()

echo " --with-logging Build with logging [${NTF_CONFIGURE_WITH_LOGGING}]"
echo " --with-metrics Build with metrics [${NTF_CONFIGURE_WITH_METRICS}]"

echo " --with-inlining-suggested Build functions suggested to be inlined by the compiler [${NTF_CONFIGURE_WITH_INLINING_SUGGESTED}]"
echo " --with-inlining-forced Build functions forcibly inlined [${NTF_CONFIGURE_WITH_INLINING_FORCED}]"
echo " --with-inlining-suggested Build with no functions inlined [${NTF_CONFIGURE_WITH_INLINING_DISABLED}]"

echo " --with-branch-prediction Build with branch prediction [${NTF_CONFIGURE_WITH_BRANCH_PREDICTION}]"

echo " --with-spin-locks Build with mutually-exclusive locks implemented as spin locks [${NTF_CONFIGURE_WITH_SPIN_LOCKS}]"
echo " --with-userspace-mutexes Build with mutually-exclusive locks implemented as userspace mutexes [${NTF_CONFIGURE_WITH_USERSPACE_MUTEXES}]"
echo " --with-system-mutexes Build with mutually-exclusive locks implemented as system mutexes [${NTF_CONFIGURE_WITH_SYSTEM_MUTEXES}]"
echo " --with-recursive-mutexes Build with mutually-exclusive locks implemented as recursive mutexes [${NTF_CONFIGURE_WITH_RECURSIVE_MUTEXES}]"

echo " --with-stack-trace-leak-report Build chronology with stack traces dumped upon function and timer leaks [${NTF_CONFIGURE_WITH_STACK_TRACE_LEAK_REPORT}]"
Expand Down Expand Up @@ -615,11 +650,23 @@ while true ; do
NTF_CONFIGURE_WITH_LOGGING=1 ; shift ;;
--with-metrics)
NTF_CONFIGURE_WITH_METRICS=1 ; shift ;;

--with-inlining-suggested)
NTF_CONFIGURE_WITH_INLINING_SUGGESTED=1 ; shift ;;
--with-inlining-forced)
NTF_CONFIGURE_WITH_INLINING_FORCED=1 ; shift ;;
--with-inlining-disabled)
NTF_CONFIGURE_WITH_INLINING_DISABLED=1 ; shift ;;

--with-branch-prediction)
NTF_CONFIGURE_WITH_BRANCH_PREDICTION=1 ; shift ;;

--with-spin-locks)
NTF_CONFIGURE_WITH_SPIN_LOCKS=1 ; shift ;;
--with-userspace-mutexes)
NTF_CONFIGURE_WITH_USERSPACE_MUTEXES=1 ; shift ;;
--with-system-mutexes)
NTF_CONFIGURE_WITH_SYSTEM_MUTEXES=1 ; shift ;;
--with-recursive-mutexes)
NTF_CONFIGURE_WITH_RECURSIVE_MUTEXES=1 ; shift ;;

Expand Down Expand Up @@ -710,11 +757,23 @@ while true ; do
NTF_CONFIGURE_WITH_LOGGING=0 ; shift ;;
--without-metrics)
NTF_CONFIGURE_WITH_METRICS=0 ; shift ;;

--without-inlining-suggested)
NTF_CONFIGURE_WITH_INLINING_SUGGESTED=0 ; shift ;;
--without-inlining-forced)
NTF_CONFIGURE_WITH_INLINING_FORCED=0 ; shift ;;
--without-inlining-disabled)
NTF_CONFIGURE_WITH_INLINING_DISABLED=0 ; shift ;;

--without-branch-prediction)
NTF_CONFIGURE_WITH_BRANCH_PREDICTION=0 ; shift ;;

--without-spin-locks)
NTF_CONFIGURE_WITH_SPIN_LOCKS=0 ; shift ;;
--without-userspace-mutexes)
NTF_CONFIGURE_WITH_USERSPACE_MUTEXES=0 ; shift ;;
--without-system-mutexes)
NTF_CONFIGURE_WITH_SYSTEM_MUTEXES=0 ; shift ;;
--without-recursive-mutexes)
NTF_CONFIGURE_WITH_RECURSIVE_MUTEXES=0 ; shift ;;

Expand Down Expand Up @@ -816,9 +875,16 @@ export NTF_CONFIGURE_WITH_DEPRECATED_FEATURES

export NTF_CONFIGURE_WITH_LOGGING
export NTF_CONFIGURE_WITH_METRICS

export NTF_CONFIGURE_WITH_INLINING_SUGGESTED
export NTF_CONFIGURE_WITH_INLINING_FORCED
export NTF_CONFIGURE_WITH_INLINING_DISABLED

export NTF_CONFIGURE_WITH_BRANCH_PREDICTION

export NTF_CONFIGURE_WITH_SPIN_LOCKS
export NTF_CONFIGURE_WITH_USERSPACE_MUTEXES
export NTF_CONFIGURE_WITH_SYSTEM_MUTEXES
export NTF_CONFIGURE_WITH_RECURSIVE_MUTEXES

export NTF_CONFIGURE_WITH_STACK_TRACE_LEAK_REPORT
Expand Down
68 changes: 68 additions & 0 deletions configure.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ IF NOT DEFINED NTF_CONFIGURE_WITH_METRICS (
set NTF_CONFIGURE_WITH_METRICS=1
)

IF NOT DEFINED NTF_CONFIGURE_WITH_INLINING_SUGGESTED (
set NTF_CONFIGURE_WITH_INLINING_SUGGESTED=0
)

IF NOT DEFINED NTF_CONFIGURE_WITH_INLINING_FORCED (
set NTF_CONFIGURE_WITH_INLINING_FORCED=1
)

IF NOT DEFINED NTF_CONFIGURE_WITH_INLINING_DISABLED (
set NTF_CONFIGURE_WITH_INLINING_DISABLED=0
)

IF NOT DEFINED NTF_CONFIGURE_WITH_BRANCH_PREDICTION (
set NTF_CONFIGURE_WITH_BRANCH_PREDICTION=1
)
Expand All @@ -133,6 +145,14 @@ IF NOT DEFINED NTF_CONFIGURE_WITH_SPIN_LOCKS (
set NTF_CONFIGURE_WITH_SPIN_LOCKS=0
)

IF NOT DEFINED NTF_CONFIGURE_WITH_USERSPACE_MUTEXES (
set NTF_CONFIGURE_WITH_USERSPACE_MUTEXES=0
)

IF NOT DEFINED NTF_CONFIGURE_WITH_SYSTEM_MUTEXES (
set NTF_CONFIGURE_WITH_SYSTEM_MUTEXES=0
)

IF NOT DEFINED NTF_CONFIGURE_WITH_RECURSIVE_MUTEXES (
set NTF_CONFIGURE_WITH_RECURSIVE_MUTEXES=0
)
Expand Down Expand Up @@ -290,10 +310,34 @@ if not "%1"=="" (
if "%1"=="--with-metrics" (
set NTF_CONFIGURE_WITH_METRICS=1
)

if "%1"=="--with-inlining-suggested" (
set NTF_CONFIGURE_WITH_INLINING_SUGGESTED=1
)
if "%1"=="--with-inlining-forced" (
set NTF_CONFIGURE_WITH_INLINING_FORCED=1
)
if "%1"=="--with-inlining-disabled" (
set NTF_CONFIGURE_WITH_INLINING_DISABLED=1
)

if "%1"=="--with-branch-prediction" (
set NTF_CONFIGURE_WITH_BRANCH_PREDICTION=1
)

if "%1"=="--with-spin-locks" (
set NTF_CONFIGURE_WITH_SPIN_LOCKS=1
)
if "%1"=="--with-userspace-mutexes" (
set NTF_CONFIGURE_WITH_USERSPACE_MUTEXES=1
)
if "%1"=="--with-system-mutexes" (
set NTF_CONFIGURE_WITH_SYSTEM_MUTEXES=1
)
if "%1"=="--with-recursive-mutexes" (
set NTF_CONFIGURE_WITH_RECURSIVE_MUTEXES=1
)

if "%1"=="--with-usage-examples" (
set NTF_CONFIGURE_WITH_USAGE_EXAMPLES=1
)
Expand Down Expand Up @@ -382,10 +426,34 @@ if not "%1"=="" (
if "%1"=="--without-metrics" (
set NTF_CONFIGURE_WITH_METRICS=0
)

if "%1"=="--without-inlining-suggested" (
set NTF_CONFIGURE_WITH_INLINING_SUGGESTED=0
)
if "%1"=="--without-inlining-forced" (
set NTF_CONFIGURE_WITH_INLINING_FORCED=0
)
if "%1"=="--without-inlining-disabled" (
set NTF_CONFIGURE_WITH_INLINING_DISABLED=0
)

if "%1"=="--without-branch-prediction" (
set NTF_CONFIGURE_WITH_BRANCH_PREDICTION=0
)

if "%1"=="--without-spin-locks" (
set NTF_CONFIGURE_WITH_SPIN_LOCKS=0
)
if "%1"=="--without-userspace-mutexes" (
set NTF_CONFIGURE_WITH_USERSPACE_MUTEXES=0
)
if "%1"=="--without-system-mutexes" (
set NTF_CONFIGURE_WITH_SYSTEM_MUTEXES=0
)
if "%1"=="--without-recursive-mutexes" (
set NTF_CONFIGURE_WITH_RECURSIVE_MUTEXES=0
)

if "%1"=="--without-usage-examples" (
set NTF_CONFIGURE_WITH_USAGE_EXAMPLES=0
)
Expand Down
14 changes: 14 additions & 0 deletions groups/ntc/ntccfg/ntccfg_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ BSLS_IDENT("$Id: $")
#include <ntcscm_version.h>
#include <bsls_platform.h>

#if NTC_BUILD_WITH_INLINING_FORCED

#if defined(NDEBUG) || defined(BDE_BUILD_TARGET_OPT)
#if defined(BSLS_PLATFORM_CMP_GNU) || defined(BSLS_PLATFORM_CMP_CLANG)

Expand Down Expand Up @@ -51,4 +53,16 @@ BSLS_IDENT("$Id: $")

#endif

#elif NTC_BUILD_WITH_INLINING_SUGGESTED

/// Hint that the following function can be inlined at its call site.
/// @ingroup module_ntccfg
#define NTCCFG_INLINE inline

#elif NTC_BUILD_WITH_INLINING_DISABLED
#error Not implemented
#else
#error Not implemented
#endif

#endif
Loading

0 comments on commit a624d18

Please sign in to comment.