Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
os_api.h File Reference

Operating system abstraction API. More...

#include <stdarg.h>
#include <errno.h>
#include <stdio.h>
#include <alloca.h>
Include dependency graph for os_api.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ecs_time_t
 Time type. More...
 
struct  ecs_os_api_t
 OS API interface. More...
 

Typedefs

typedef struct ecs_time_t ecs_time_t
 Time type.
 
typedef uintptr_t ecs_os_thread_t
 OS thread.
 
typedef uintptr_t ecs_os_cond_t
 OS cond.
 
typedef uintptr_t ecs_os_mutex_t
 OS mutex.
 
typedef uintptr_t ecs_os_dl_t
 OS dynamic library.
 
typedef uintptr_t ecs_os_sock_t
 OS socket.
 
typedef uint64_t ecs_os_thread_id_t
 64 bit thread id.
 
typedef void(* ecs_os_proc_t) (void)
 Generic function pointer type.
 
typedef void(* ecs_os_api_init_t) (void)
 OS API init.
 
typedef void(* ecs_os_api_fini_t) (void)
 OS API deinit.
 
typedef void *(* ecs_os_api_malloc_t) (ecs_size_t size)
 OS API malloc function type.
 
typedef void(* ecs_os_api_free_t) (void *ptr)
 OS API free function type.
 
typedef void *(* ecs_os_api_realloc_t) (void *ptr, ecs_size_t size)
 OS API realloc function type.
 
typedef void *(* ecs_os_api_calloc_t) (ecs_size_t size)
 OS API calloc function type.
 
typedef char *(* ecs_os_api_strdup_t) (const char *str)
 OS API strdup function type.
 
typedef void *(* ecs_os_thread_callback_t) (void *)
 OS API thread_callback function type.
 
typedef ecs_os_thread_t(* ecs_os_api_thread_new_t) (ecs_os_thread_callback_t callback, void *param)
 OS API thread_new function type.
 
typedef void *(* ecs_os_api_thread_join_t) (ecs_os_thread_t thread)
 OS API thread_join function type.
 
typedef ecs_os_thread_id_t(* ecs_os_api_thread_self_t) (void)
 OS API thread_self function type.
 
typedef ecs_os_thread_t(* ecs_os_api_task_new_t) (ecs_os_thread_callback_t callback, void *param)
 OS API task_new function type.
 
typedef void *(* ecs_os_api_task_join_t) (ecs_os_thread_t thread)
 OS API task_join function type.
 
typedef int32_t(* ecs_os_api_ainc_t) (int32_t *value)
 OS API ainc function type.
 
typedef int64_t(* ecs_os_api_lainc_t) (int64_t *value)
 OS API lainc function type.
 
typedef ecs_os_mutex_t(* ecs_os_api_mutex_new_t) (void)
 OS API mutex_new function type.
 
typedef void(* ecs_os_api_mutex_lock_t) (ecs_os_mutex_t mutex)
 OS API mutex_lock function type.
 
typedef void(* ecs_os_api_mutex_unlock_t) (ecs_os_mutex_t mutex)
 OS API mutex_unlock function type.
 
typedef void(* ecs_os_api_mutex_free_t) (ecs_os_mutex_t mutex)
 OS API mutex_free function type.
 
typedef ecs_os_cond_t(* ecs_os_api_cond_new_t) (void)
 OS API cond_new function type.
 
typedef void(* ecs_os_api_cond_free_t) (ecs_os_cond_t cond)
 OS API cond_free function type.
 
typedef void(* ecs_os_api_cond_signal_t) (ecs_os_cond_t cond)
 OS API cond_signal function type.
 
typedef void(* ecs_os_api_cond_broadcast_t) (ecs_os_cond_t cond)
 OS API cond_broadcast function type.
 
typedef void(* ecs_os_api_cond_wait_t) (ecs_os_cond_t cond, ecs_os_mutex_t mutex)
 OS API cond_wait function type.
 
typedef void(* ecs_os_api_sleep_t) (int32_t sec, int32_t nanosec)
 OS API sleep function type.
 
typedef void(* ecs_os_api_enable_high_timer_resolution_t) (bool enable)
 OS API enable_high_timer_resolution function type.
 
typedef void(* ecs_os_api_get_time_t) (ecs_time_t *time_out)
 OS API get_time function type.
 
typedef uint64_t(* ecs_os_api_now_t) (void)
 OS API now function type.
 
typedef void(* ecs_os_api_log_t) (int32_t level, const char *file, int32_t line, const char *msg)
 OS API log function type.
 
typedef void(* ecs_os_api_abort_t) (void)
 OS API abort function type.
 
typedef ecs_os_dl_t(* ecs_os_api_dlopen_t) (const char *libname)
 OS API dlopen function type.
 
typedef ecs_os_proc_t(* ecs_os_api_dlproc_t) (ecs_os_dl_t lib, const char *procname)
 OS API dlproc function type.
 
typedef void(* ecs_os_api_dlclose_t) (ecs_os_dl_t lib)
 OS API dlclose function type.
 
typedef char *(* ecs_os_api_module_to_path_t) (const char *module_id)
 OS API module_to_path function type.
 
typedef struct ecs_os_api_t ecs_os_api_t
 OS API interface.
 

Functions

FLECS_API void ecs_os_init (void)
 Initialize OS API.
 
FLECS_API void ecs_os_fini (void)
 Deinitialize OS API.
 
FLECS_API void ecs_os_set_api (ecs_os_api_t *os_api)
 Override OS API.
 
FLECS_API ecs_os_api_t ecs_os_get_api (void)
 Get OS API.
 
FLECS_API void ecs_os_set_api_defaults (void)
 Set default values for OS API.
 
FLECS_API void ecs_os_dbg (const char *file, int32_t line, const char *msg)
 Macro utilities.
 
FLECS_API void ecs_os_trace (const char *file, int32_t line, const char *msg)
 Log at trace level.
 
FLECS_API void ecs_os_warn (const char *file, int32_t line, const char *msg)
 Log at warning level.
 
FLECS_API void ecs_os_err (const char *file, int32_t line, const char *msg)
 Log at error level.
 
FLECS_API void ecs_os_fatal (const char *file, int32_t line, const char *msg)
 Log at fatal level.
 
FLECS_API const char * ecs_os_strerror (int err)
 Convert errno to string.
 
FLECS_API void ecs_os_strset (char **str, const char *value)
 Utility for assigning strings.
 
FLECS_API void ecs_sleepf (double t)
 Sleep with floating point time.
 
FLECS_API double ecs_time_measure (ecs_time_t *start)
 Measure time since provided timestamp.
 
FLECS_API ecs_time_t ecs_time_sub (ecs_time_t t1, ecs_time_t t2)
 Calculate difference between two timestamps.
 
FLECS_API double ecs_time_to_double (ecs_time_t t)
 Convert time value to a double.
 
FLECS_API void * ecs_os_memdup (const void *src, ecs_size_t size)
 Return newly allocated memory that contains a copy of src.
 
FLECS_API bool ecs_os_has_heap (void)
 Are heap functions available?
 
FLECS_API bool ecs_os_has_threading (void)
 Are threading functions available?
 
FLECS_API bool ecs_os_has_task_support (void)
 Are task functions available?
 
FLECS_API bool ecs_os_has_time (void)
 Are time functions available?
 
FLECS_API bool ecs_os_has_logging (void)
 Are logging functions available?
 
FLECS_API bool ecs_os_has_dl (void)
 Are dynamic library functions available?
 
FLECS_API bool ecs_os_has_modules (void)
 Are module path functions available?
 

Variables

int64_t ecs_os_api_malloc_count
 malloc count.
 
int64_t ecs_os_api_realloc_count
 realloc count.
 
int64_t ecs_os_api_calloc_count
 calloc count.
 
int64_t ecs_os_api_free_count
 free count.
 
FLECS_API ecs_os_api_t ecs_os_api
 Static OS API variable with configured callbacks.
 

Detailed Description

Operating system abstraction API.

This file contains the operating system abstraction API. The flecs core library avoids OS/runtime specific API calls as much as possible. Instead it provides an interface that can be implemented by applications.

Examples for how to implement this interface can be found in the examples/os_api folder.

Definition in file os_api.h.