76 extern "C" void _mm_pause(
void);
147 [[nodiscard]]
VLINK_EXPORT std::
string get_env(const std::
string& key, const std::
string& default_value = "") noexcept;
223 int max_count = 5) noexcept;
332 bool pass_through = false) noexcept;
356 int poll_ms = 20) noexcept;
430 #if defined(__GNUC__) && !defined(_WIN32) && !defined(__CYGWIN__)
431 inline __attribute__((artificial))
void yield_cpu() noexcept {
435 #if __has_builtin(__yield)
437 #elif defined(_MSC_VER) && defined(_YIELD_PROCESSOR)
439 #elif __has_builtin(__builtin_ia32_pause)
440 __builtin_ia32_pause();
441 #elif defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
442 #if defined(_MSC_VER)
444 #elif defined(__GNUC__)
445 __builtin_ia32_pause();
449 #elif __has_builtin(__builtin_arm_yield)
450 __builtin_arm_yield();
451 #elif defined(__arm__) || defined(__aarch64__)
452 #if defined(__GNUC__)
455 std::this_thread::yield();
457 #elif defined(__riscv)
458 __asm__(
".word 0x0100000f");
459 #elif defined(_MSC_VER) && defined(_YIELD_PROCESSOR)
462 std::this_thread::yield();
Move-only type-erased callable analogue of std::move_only_function with pool spill.
Definition: functional.h:134
Pool-backed type-erased callables: copyable vlink::Function and move-only vlink::MoveFunction.
Cross-platform macros for visibility, branch hints, copy prevention, singletons and string helpers.
#define VLINK_EXPORT
Definition: macros.h:81
VLINK_EXPORT double get_memory_usage() noexcept
Returns the system-wide memory usage as a percentage of total physical RAM.
VLINK_EXPORT int32_t get_timezone_diff() noexcept
Returns the local timezone offset from UTC in minutes.
VLINK_EXPORT std::string get_interface_name_by_ipv4(const std::string &ipv4) noexcept
Returns the interface name that owns a given IPv4 address.
VLINK_EXPORT void stop_detect_keyboard() noexcept
Stops the keyboard poller started by start_detect_keyboard().
VLINK_EXPORT std::string get_app_path() noexcept
Returns the absolute path of the executable that is currently running.
VLINK_EXPORT std::string get_tmp_dir() noexcept
Returns a path suitable for short-lived temporary files.
VLINK_EXPORT bool is_ignored_iface_name(const char *name) noexcept
Returns whether an interface name is treated as virtual/tunnel-only by address discovery.
VLINK_EXPORT void set_console_utf8_output() noexcept
Sets the Windows console output code page to UTF-8.
VLINK_EXPORT bool set_thread_stick(uint32_t core_mask, std::thread *thread=nullptr) noexcept
Pins a thread to a set of CPU cores expressed as a bitmask.
VLINK_EXPORT std::string get_env(const std::string &key, const std::string &default_value="") noexcept
Reads the current value of an environment variable.
VLINK_EXPORT bool set_thread_name(const std::string &name, std::thread *thread=nullptr) noexcept
Sets the OS-visible name of a thread so debug tools display it.
VLINK_EXPORT bool is_process_running(const std::string &process_name) noexcept
Reports whether at least one process with the given executable name is alive.
VLINK_EXPORT std::string get_host_name() noexcept
Returns the local machine's host name as reported by the operating system.
VLINK_EXPORT std::vector< std::string > get_all_ipv6_address(bool filter_available=false) noexcept
Returns every IPv6 address bound to a local network interface.
VLINK_EXPORT std::string get_app_name() noexcept
Returns the file-name portion of the executable's absolute path.
VLINK_EXPORT bool check_singleton(const std::string &program_name="") noexcept
Provides a singleton mutual-exclusion check for a program name.
VLINK_EXPORT std::string get_pid_str() noexcept
Returns the process identifier of the calling process as a decimal string.
VLINK_EXPORT std::pair< int, int > get_terminal_size() noexcept
Returns the current terminal dimensions in columns and rows.
VLINK_EXPORT bool wait_for_device(const std::string &path, int timeout_ms, int poll_ms=50) noexcept
Polls a filesystem path until it exists or a timeout expires.
VLINK_EXPORT std::string get_app_dir() noexcept
Returns the directory portion of the executable's absolute path.
VLINK_EXPORT void try_release_sys_memory() noexcept
Hints to the OS that any unreferenced cached memory pages can be released.
VLINK_EXPORT double get_cpu_usage() noexcept
Returns the system-wide CPU usage as a percentage averaged over all logical CPUs.
VLINK_EXPORT void register_crash_signal(MoveFunction< void(int)> &&callback) noexcept
Installs a callback for crash signals such as SIGSEGV, SIGABRT, SIGFPE, SIGBUS.
VLINK_EXPORT void yield_cpu() noexcept
Emits the most efficient CPU pause/yield hint for the host ISA.
Definition: utils.h:433
VLINK_EXPORT void start_detect_keyboard(MoveFunction< void(const std::string &key)> &&callback=nullptr, int poll_ms=20) noexcept
Starts a background poller that detects keyboard input on stdin.
VLINK_EXPORT uint64_t get_native_thread_id() noexcept
Returns the native OS thread identifier of the calling thread.
VLINK_EXPORT bool set_env(const std::string &key, const std::string &value, bool force=true) noexcept
Sets or updates an environment variable.
VLINK_EXPORT std::vector< std::string > get_dds_default_address(bool filter_available=false, int max_count=5) noexcept
Selects IPv4 addresses suitable as DDS participant unicast locators.
VLINK_EXPORT bool set_thread_priority(int priority_level, int policy=-1, std::thread *thread=nullptr) noexcept
Updates the scheduling policy and priority of a thread.
VLINK_EXPORT bool unset_env(const std::string &key) noexcept
Removes an environment variable.
VLINK_EXPORT void register_terminate_signal(MoveFunction< void(int)> &&callback, bool is_async=false, bool pass_through=false) noexcept
Installs a callback for graceful termination signals.
VLINK_EXPORT int32_t get_pid() noexcept
Returns the process identifier of the calling process.
VLINK_EXPORT std::string get_machine_id() noexcept
Returns a stable identifier for the host machine.
VLINK_EXPORT std::string get_interface_name_by_ipv6(const std::string &ipv6) noexcept
Returns the interface name that owns a given IPv6 address.
VLINK_EXPORT std::vector< std::string > get_all_ipv4_address(bool filter_available=false) noexcept
Returns every IPv4 address bound to a local network interface.