libqb
2.0.0
|
These are some convience functions used throughout libqb. More...
Data Structures | |
struct | qb_version |
Structured library versioning info. More... | |
Macros | |
#define | QB_UTIL_SW_OVERWRITE 0x01 |
Typedefs | |
typedef struct qb_thread_lock_s | qb_thread_lock_t |
typedef void(* | qb_util_log_fn_t )(const char *file_name, int32_t file_line, int32_t severity, const char *msg) |
typedef struct qb_util_stopwatch | qb_util_stopwatch_t |
Enumerations | |
enum | qb_thread_lock_type_t { QB_THREAD_LOCK_SHORT, QB_THREAD_LOCK_LONG } |
QB_THREAD_LOCK_SHORT is a short term lock (spinlock if available on your system) QB_THREAD_LOCK_LONG is a mutex. More... | |
Functions | |
qb_thread_lock_t * | qb_thread_lock_create (qb_thread_lock_type_t type) |
Create a new lock of the given type. More... | |
int32_t | qb_thread_lock (qb_thread_lock_t *tl) |
Calls either pthread_mutex_lock() or pthread_spin_lock(). More... | |
int32_t | qb_thread_trylock (qb_thread_lock_t *tl) |
Calls either pthread_mutex_trylock() or pthread_spin_trylock(). More... | |
int32_t | qb_thread_unlock (qb_thread_lock_t *tl) |
Calls either pthread_mutex_unlock() or pthread_spin_unlock. More... | |
int32_t | qb_thread_lock_destroy (qb_thread_lock_t *tl) |
Calls either pthread_mutex_destro() or pthread_spin_destroy(). More... | |
void | qb_util_set_log_function (qb_util_log_fn_t fn) |
Use this function to output libqb internal log message as you wish. More... | |
void | qb_timespec_add_ms (struct timespec *ts, int32_t ms) |
Add milliseconds onto the timespec. More... | |
uint64_t | qb_util_nano_current_get (void) |
Get the current number of nano secounds produced by the systems incrementing clock (CLOCK_MONOTOMIC if available). More... | |
uint64_t | qb_util_nano_monotonic_hz (void) |
Get the frequence of the clock used in qb_util_nano_current_get(). More... | |
uint64_t | qb_util_nano_from_epoch_get (void) |
Get the time in nano seconds since epoch. More... | |
void | qb_util_timespec_from_epoch_get (struct timespec *ts) |
Get the time in timespec since epoch. More... | |
char * | qb_strerror_r (int errnum, char *buf, size_t buflen) |
strerror_r replacement. More... | |
qb_util_stopwatch_t * | qb_util_stopwatch_create (void) |
Create a Stopwatch (to time operations) More... | |
void | qb_util_stopwatch_free (qb_util_stopwatch_t *sw) |
Free the stopwatch. More... | |
void | qb_util_stopwatch_start (qb_util_stopwatch_t *sw) |
Start the stopwatch. More... | |
void | qb_util_stopwatch_stop (qb_util_stopwatch_t *sw) |
Stop the stopwatch. More... | |
uint64_t | qb_util_stopwatch_us_elapsed_get (qb_util_stopwatch_t *sw) |
Get the elapsed time in micro seconds. More... | |
float | qb_util_stopwatch_sec_elapsed_get (qb_util_stopwatch_t *sw) |
Get the elapsed time in seconds. More... | |
int32_t | qb_util_stopwatch_split_ctl (qb_util_stopwatch_t *sw, uint32_t max_splits, uint32_t options) |
uint64_t | qb_util_stopwatch_split (qb_util_stopwatch_t *sw) |
Create a new time split (or lap time) More... | |
uint32_t | qb_util_stopwatch_split_last (qb_util_stopwatch_t *sw) |
Get the last split index to be used by qb_util_stopwatch_time_split_get() More... | |
uint64_t | qb_util_stopwatch_time_split_get (qb_util_stopwatch_t *sw, uint32_t receint, uint32_t older) |
Read the time split (in us) from "receint" to "older". More... | |
Variables | |
struct qb_version | qb_ver |
const char *const | qb_ver_str |
Complete library versioning info as a string. More... | |
These are some convience functions used throughout libqb.
#define QB_UTIL_SW_OVERWRITE 0x01 |
typedef struct qb_thread_lock_s qb_thread_lock_t |
typedef void(* qb_util_log_fn_t)(const char *file_name, int32_t file_line, int32_t severity, const char *msg) |
typedef struct qb_util_stopwatch qb_util_stopwatch_t |
char* qb_strerror_r | ( | int | errnum, |
char * | buf, | ||
size_t | buflen | ||
) |
strerror_r replacement.
int32_t qb_thread_lock | ( | qb_thread_lock_t * | tl | ) |
Calls either pthread_mutex_lock() or pthread_spin_lock().
qb_thread_lock_t* qb_thread_lock_create | ( | qb_thread_lock_type_t | type | ) |
Create a new lock of the given type.
type | QB_THREAD_LOCK_SHORT == spinlock (where available, else mutex) QB_THREAD_LOCK_LONG == mutex |
int32_t qb_thread_lock_destroy | ( | qb_thread_lock_t * | tl | ) |
Calls either pthread_mutex_destro() or pthread_spin_destroy().
int32_t qb_thread_trylock | ( | qb_thread_lock_t * | tl | ) |
Calls either pthread_mutex_trylock() or pthread_spin_trylock().
int32_t qb_thread_unlock | ( | qb_thread_lock_t * | tl | ) |
Calls either pthread_mutex_unlock() or pthread_spin_unlock.
void qb_timespec_add_ms | ( | struct timespec * | ts, |
int32_t | ms | ||
) |
Add milliseconds onto the timespec.
ts | the ts to add to |
ms | the amount of milliseconds to increment ts |
uint64_t qb_util_nano_current_get | ( | void | ) |
Get the current number of nano secounds produced by the systems incrementing clock (CLOCK_MONOTOMIC if available).
uint64_t qb_util_nano_from_epoch_get | ( | void | ) |
Get the time in nano seconds since epoch.
uint64_t qb_util_nano_monotonic_hz | ( | void | ) |
Get the frequence of the clock used in qb_util_nano_current_get().
void qb_util_set_log_function | ( | qb_util_log_fn_t | fn | ) |
Use this function to output libqb internal log message as you wish.
qb_util_stopwatch_t* qb_util_stopwatch_create | ( | void | ) |
Create a Stopwatch (to time operations)
void qb_util_stopwatch_free | ( | qb_util_stopwatch_t * | sw | ) |
Free the stopwatch.
float qb_util_stopwatch_sec_elapsed_get | ( | qb_util_stopwatch_t * | sw | ) |
uint64_t qb_util_stopwatch_split | ( | qb_util_stopwatch_t * | sw | ) |
Create a new time split (or lap time)
sw | the stopwatch |
the | relative split time in micro seconds |
0 | if no more splits available |
int32_t qb_util_stopwatch_split_ctl | ( | qb_util_stopwatch_t * | sw, |
uint32_t | max_splits, | ||
uint32_t | options | ||
) |
sw | the stopwatch |
max_splits | maximum number of time splits |
options | (0 or QB_UTIL_SW_OVERWRITE ) |
0 | on success |
-errno | on failure |
uint32_t qb_util_stopwatch_split_last | ( | qb_util_stopwatch_t * | sw | ) |
Get the last split index to be used by qb_util_stopwatch_time_split_get()
sw | the stopwatch |
void qb_util_stopwatch_start | ( | qb_util_stopwatch_t * | sw | ) |
Start the stopwatch.
This also acts as a reset. Essentially it sets the starting time and clears the splits.
void qb_util_stopwatch_stop | ( | qb_util_stopwatch_t * | sw | ) |
Stop the stopwatch.
This just allows you to get the elapsed time. So you can call this multiple times. Do not call qb_util_stopwatch_start() unless you want to reset the stopwatch.
uint64_t qb_util_stopwatch_time_split_get | ( | qb_util_stopwatch_t * | sw, |
uint32_t | receint, | ||
uint32_t | older | ||
) |
Read the time split (in us) from "receint" to "older".
If older == receint then the cumulated split will be returned (from the stopwatch start).
sw | the stopwatch |
receint | split |
older | split |
the | split time in micro seconds |
0 | if not a valid split |
uint64_t qb_util_stopwatch_us_elapsed_get | ( | qb_util_stopwatch_t * | sw | ) |
Get the elapsed time in micro seconds.
(it must have been started and stopped).
void qb_util_timespec_from_epoch_get | ( | struct timespec * | ts | ) |
Get the time in timespec since epoch.
ts | (out) the timespec |
struct qb_version qb_ver |
const char* const qb_ver_str |
Complete library versioning info as a string.