CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches

Functions

void osYield ()
 
void osSleep (int64 time)
 
int osPhysicalCPUs ()
 
int osLogicalCPUs ()
 
bool osGenRandom (uint8 *buffer, uint32 size)
 

Detailed Description

Cross-platform operating system services for threading, timing, and system information. This module provides a unified interface across Windows, Unix-like systems, and WebAssembly.

The implementation is selected at compile time based on the target platform:

Available Services:

Example usage:

// Query system
int physical = osPhysicalCPUs();
int logical = osLogicalCPUs();
// Thread control
osYield(); // Yield to other threads
osSleep(1000000); // Sleep for 1ms (microseconds)
// Random data
uint8 key[32];
if (osGenRandom(key, sizeof(key))) {
// Use cryptographically secure random key
}
bool osGenRandom(uint8 *buffer, uint32 size)
int osPhysicalCPUs()
int osLogicalCPUs()
void osSleep(int64 time)
void osYield()

Function Documentation

◆ osGenRandom()

bool osGenRandom ( uint8 *  buffer,
uint32  size 
)

Generate cryptographically secure random data.

Fills the provided buffer with random bytes from the operating system's cryptographically secure random number generator:

  • Windows: BCryptGenRandom
  • Linux: /dev/urandom
  • FreeBSD: arc4random_buf
Parameters
bufferBuffer to fill with random data
sizeNumber of bytes to generate
Returns
true if random generation succeeded, false on error

◆ osLogicalCPUs()

int osLogicalCPUs ( )

Get the number of logical CPU cores.

Returns the count of logical processors, including hyperthreading cores. This is typically the number of concurrent threads the system can execute.

Returns
Number of logical CPU cores, or 0 if detection fails

◆ osPhysicalCPUs()

int osPhysicalCPUs ( )

Get the number of physical CPU cores.

Returns the count of physical processor cores, not including hyperthreading or other logical processors.

Returns
Number of physical CPU cores, or 0 if detection fails

◆ osSleep()

void osSleep ( int64  time)

Sleep for a specified duration.

Suspends execution of the current thread for at least the specified time. The actual sleep duration may be longer due to system scheduling.

Parameters
timeSleep duration in microseconds

◆ osYield()

void osYield ( )

Yield the current thread's time slice.

Hints to the OS scheduler that the current thread should yield execution to other threads. Useful in busy-wait loops to reduce CPU usage.