63extern "C" void _mm_pause(
void);
198 int max_count = 5) noexcept;
310 bool pass_through = false) noexcept;
335 int poll_ms = 20) noexcept;
409#if defined(__GNUC__) && !defined(_WIN32) && !defined(__CYGWIN__)
410inline __attribute__((artificial))
void yield_cpu() noexcept {
414#if __has_builtin(__yield)
416#elif defined(_MSC_VER) && defined(_YIELD_PROCESSOR)
418#elif __has_builtin(__builtin_ia32_pause)
419__builtin_ia32_pause();
420#elif defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
423#elif defined(__GNUC__)
424__builtin_ia32_pause();
428#elif __has_builtin(__builtin_arm_yield)
429__builtin_arm_yield();
430#elif defined(__arm__) || defined(__aarch64__)
434std::this_thread::yield();
436#elif defined(__riscv)
437__asm__(
".word 0x0100000f");
438#elif defined(_MSC_VER) && defined(_YIELD_PROCESSOR)
441std::this_thread::yield();
Platform-independent macro definitions for the VLink library.
#define VLINK_EXPORT
Definition macros.h:85
Platform-agnostic system utility functions.
VLINK_EXPORT double get_memory_usage() noexcept
Returns the resident set size (RSS) of the process as a percentage of total RAM.
VLINK_EXPORT int32_t get_timezone_diff() noexcept
Returns the local timezone offset from UTC in seconds.
VLINK_EXPORT std::string get_interface_name_by_ipv4(const std::string &ipv4) noexcept
Returns the network interface name that owns a given IPv4 address.
VLINK_EXPORT void stop_detect_keyboard() noexcept
Stops the keyboard detection thread started by start_detect_keyboard().
VLINK_EXPORT std::vector< std::string > get_dds_default_address(bool filter_available=false, int max_count=5) noexcept
Returns suitable IPv4 addresses for use as DDS participant unicast locators.
VLINK_EXPORT std::string get_app_path() noexcept
Returns the absolute path of the running executable.
VLINK_EXPORT std::string get_tmp_dir() noexcept
Returns the platform-specific temporary directory path.
VLINK_EXPORT void register_crash_signal(std::function< void(int)> &&callback) noexcept
Registers a callback for crash signals (SIGSEGV, SIGABRT, SIGFPE, SIGBUS, etc.).
VLINK_EXPORT void set_console_utf8_output() noexcept
Configures the Windows console for UTF-8 output.
VLINK_EXPORT std::vector< std::string > get_all_ipv6_address(bool filter_available=false) noexcept
Returns all IPv6 addresses assigned to local network interfaces.
VLINK_EXPORT bool set_thread_stick(uint32_t core_mask, std::thread *thread=nullptr) noexcept
Pins a thread to a set of CPU cores specified by a bitmask.
VLINK_EXPORT std::pair< int, int > get_terminal_size() noexcept
Returns the current terminal window dimensions.
VLINK_EXPORT std::string get_env(const std::string &key, const std::string &default_value="") noexcept
Reads the value of an environment variable.
VLINK_EXPORT bool set_thread_name(const std::string &name, std::thread *thread=nullptr) noexcept
Sets the OS-level name of a thread for debugging tools (e.g., gdb, perf).
VLINK_EXPORT bool is_process_running(const std::string &process_name) noexcept
Checks whether a process with the given name is currently running.
VLINK_EXPORT std::string get_host_name() noexcept
Returns the host name of the current machine.
VLINK_EXPORT std::vector< std::string > get_all_ipv4_address(bool filter_available=false) noexcept
Returns all IPv4 addresses assigned to local network interfaces.
VLINK_EXPORT std::string get_app_name() noexcept
Returns the file name of the running executable (without directory prefix).
VLINK_EXPORT bool check_singleton(const std::string &program_name="") noexcept
Checks that only one instance of the process is running (singleton guard).
VLINK_EXPORT std::string get_pid_str() noexcept
Returns the process ID of the current process as a decimal string.
VLINK_EXPORT bool wait_for_device(const std::string &path, int timeout_ms, int poll_ms=50) noexcept
Blocks until a file-system path appears or the timeout elapses.
VLINK_EXPORT std::string get_app_dir() noexcept
Returns the directory containing the running executable.
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 current CPU usage of the process as a percentage.
VLINK_EXPORT void yield_cpu() noexcept
Emits a CPU pause/yield hint to reduce bus contention in busy-wait loops.
Definition utils.h:412
VLINK_EXPORT uint64_t get_native_thread_id() noexcept
Returns the native OS thread identifier of the calling thread.
VLINK_EXPORT void start_detect_keyboard(std::function< void(const std::string &key)> &&callback=nullptr, int poll_ms=20) noexcept
Starts a background thread that detects keyboard input.
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 void register_terminate_signal(std::function< void(int)> &&callback, bool is_async=false, bool pass_through=false) noexcept
Registers a callback for graceful termination signals (SIGTERM, SIGINT, etc.).
VLINK_EXPORT bool set_thread_priority(int priority_level, int policy=-1, std::thread *thread=nullptr) noexcept
Sets the scheduling policy and priority of a thread.
VLINK_EXPORT bool unset_env(const std::string &key) noexcept
Removes an environment variable.
VLINK_EXPORT int32_t get_pid() noexcept
Returns the process ID of the current process.
VLINK_EXPORT std::string get_machine_id() noexcept
Returns a unique identifier for the current machine.
VLINK_EXPORT std::string get_interface_name_by_ipv6(const std::string &ipv6) noexcept
Returns the network interface name that owns a given IPv6 address.