Flecs v3.1
A fast entity component system (ECS) for C & C++
No Matches
os_api.h File Reference

Operating system abstraction API. More...

#include <stdarg.h>
#include <errno.h>
#include <alloca.h>

Go to the source code of this file.


struct  ecs_time_t
struct  ecs_os_api_t


#define ecs_os_malloc(size)   ecs_os_api.malloc_(size)
#define ecs_os_free(ptr)   ecs_os_api.free_(ptr)
#define ecs_os_realloc(ptr, size)   ecs_os_api.realloc_(ptr, size)
#define ecs_os_calloc(size)   ecs_os_api.calloc_(size)
#define ecs_os_alloca(size)   alloca((size_t)(size))
#define ecs_os_malloc_t(T)   ECS_CAST(T*, ecs_os_malloc(ECS_SIZEOF(T)))
#define ecs_os_malloc_n(T, count)   ECS_CAST(T*, ecs_os_malloc(ECS_SIZEOF(T) * (count)))
#define ecs_os_calloc_t(T)   ECS_CAST(T*, ecs_os_calloc(ECS_SIZEOF(T)))
#define ecs_os_calloc_n(T, count)   ECS_CAST(T*, ecs_os_calloc(ECS_SIZEOF(T) * (count)))
#define ecs_os_realloc_t(ptr, T)   ECS_CAST(T*, ecs_os_realloc([ptr, ECS_SIZEOF(T)))
#define ecs_os_realloc_n(ptr, T, count)   ECS_CAST(T*, ecs_os_realloc(ptr, ECS_SIZEOF(T) * (count)))
#define ecs_os_alloca_t(T)   ECS_CAST(T*, ecs_os_alloca(ECS_SIZEOF(T)))
#define ecs_os_alloca_n(T, count)   ECS_CAST(T*, ecs_os_alloca(ECS_SIZEOF(T) * (count)))
#define ecs_os_strdup(str)   ecs_os_api.strdup_(str)
#define ecs_os_strlen(str)   (ecs_size_t)strlen(str)
#define ecs_os_strncmp(str1, str2, num)   strncmp(str1, str2, (size_t)(num))
#define ecs_os_memcmp(ptr1, ptr2, num)   memcmp(ptr1, ptr2, (size_t)(num))
#define ecs_os_memcpy(ptr1, ptr2, num)   memcpy(ptr1, ptr2, (size_t)(num))
#define ecs_os_memset(ptr, value, num)   memset(ptr, value, (size_t)(num))
#define ecs_os_memmove(dst, src, size)   memmove(dst, src, (size_t)(size))
#define ecs_os_memcpy_t(ptr1, ptr2, T)   ecs_os_memcpy(ptr1, ptr2, ECS_SIZEOF(T))
#define ecs_os_memcpy_n(ptr1, ptr2, T, count)   ecs_os_memcpy(ptr1, ptr2, ECS_SIZEOF(T) * count)
#define ecs_os_memcmp_t(ptr1, ptr2, T)   ecs_os_memcmp(ptr1, ptr2, ECS_SIZEOF(T))
#define ecs_os_strcmp(str1, str2)   strcmp(str1, str2)
#define ecs_os_memset_t(ptr, value, T)   ecs_os_memset(ptr, value, ECS_SIZEOF(T))
#define ecs_os_memset_n(ptr, value, T, count)   ecs_os_memset(ptr, value, ECS_SIZEOF(T) * count)
#define ecs_os_zeromem(ptr)   ecs_os_memset(ptr, 0, ECS_SIZEOF(*ptr))
#define ecs_os_memdup_t(ptr, T)   ecs_os_memdup(ptr, ECS_SIZEOF(T))
#define ecs_os_memdup_n(ptr, T, count)   ecs_os_memdup(ptr, ECS_SIZEOF(T) * count)
#define ecs_offset(ptr, T, index)    ECS_CAST(T*, ECS_OFFSET(ptr, ECS_SIZEOF(T) * index))
#define ecs_os_strcat(str1, str2)   strcat(str1, str2)
#define ecs_os_sprintf(ptr, ...)   sprintf(ptr, __VA_ARGS__)
#define ecs_os_vsprintf(ptr, fmt, args)   vsprintf(ptr, fmt, args)
#define ecs_os_strcpy(str1, str2)   strcpy(str1, str2)
#define ecs_os_strncpy(str1, str2, num)   strncpy(str1, str2, (size_t)(num))
#define ecs_os_fopen(result, file, mode)   (*(result)) = fopen(file, mode)
#define ecs_os_thread_new(callback, param)   ecs_os_api.thread_new_(callback, param)
#define ecs_os_thread_join(thread)   ecs_os_api.thread_join_(thread)
#define ecs_os_thread_self()   ecs_os_api.thread_self_()
#define ecs_os_ainc(value)   ecs_os_api.ainc_(value)
#define ecs_os_adec(value)   ecs_os_api.adec_(value)
#define ecs_os_lainc(value)   ecs_os_api.lainc_(value)
#define ecs_os_ladec(value)   ecs_os_api.ladec_(value)
#define ecs_os_mutex_new()   ecs_os_api.mutex_new_()
#define ecs_os_mutex_free(mutex)   ecs_os_api.mutex_free_(mutex)
#define ecs_os_mutex_lock(mutex)   ecs_os_api.mutex_lock_(mutex)
#define ecs_os_mutex_unlock(mutex)   ecs_os_api.mutex_unlock_(mutex)
#define ecs_os_cond_new()   ecs_os_api.cond_new_()
#define ecs_os_cond_free(cond)   ecs_os_api.cond_free_(cond)
#define ecs_os_cond_signal(cond)   ecs_os_api.cond_signal_(cond)
#define ecs_os_cond_broadcast(cond)   ecs_os_api.cond_broadcast_(cond)
#define ecs_os_cond_wait(cond, mutex)   ecs_os_api.cond_wait_(cond, mutex)
#define ecs_os_sleep(sec, nanosec)   ecs_os_api.sleep_(sec, nanosec)
#define ecs_os_now()   ecs_os_api.now_()
#define ecs_os_get_time(time_out)   ecs_os_api.get_time_(time_out)
#define ecs_os_inc(v)   (++(*v))
#define ecs_os_linc(v)   (++(*v))
#define ecs_os_dec(v)   (--(*v))
#define ecs_os_ldec(v)   (--(*v))
#define ecs_os_abort()   ecs_os_api.abort_()
#define ecs_os_dlopen(libname)   ecs_os_api.dlopen_(libname)
#define ecs_os_dlproc(lib, procname)   ecs_os_api.dlproc_(lib, procname)
#define ecs_os_dlclose(lib)   ecs_os_api.dlclose_(lib)
#define ecs_os_module_to_dl(lib)   ecs_os_api.module_to_dl_(lib)
#define ecs_os_module_to_etc(lib)   ecs_os_api.module_to_etc_(lib)


typedef struct ecs_time_t ecs_time_t
typedef uintptr_t ecs_os_thread_t
typedef uintptr_t ecs_os_cond_t
typedef uintptr_t ecs_os_mutex_t
typedef uintptr_t ecs_os_dl_t
typedef uintptr_t ecs_os_sock_t
typedef uint64_t ecs_os_thread_id_t
typedef void(* ecs_os_proc_t) (void)
typedef void(* ecs_os_api_init_t) (void)
typedef void(* ecs_os_api_fini_t) (void)
typedef void *(* ecs_os_api_malloc_t) (ecs_size_t size)
typedef void(* ecs_os_api_free_t) (void *ptr)
typedef void *(* ecs_os_api_realloc_t) (void *ptr, ecs_size_t size)
typedef void *(* ecs_os_api_calloc_t) (ecs_size_t size)
typedef char *(* ecs_os_api_strdup_t) (const char *str)
typedef void *(* ecs_os_thread_callback_t) (void *)
typedef ecs_os_thread_t(* ecs_os_api_thread_new_t) (ecs_os_thread_callback_t callback, void *param)
typedef void *(* ecs_os_api_thread_join_t) (ecs_os_thread_t thread)
typedef ecs_os_thread_id_t(* ecs_os_api_thread_self_t) (void)
typedef int32_t(* ecs_os_api_ainc_t) (int32_t *value)
typedef int64_t(* ecs_os_api_lainc_t) (int64_t *value)
typedef ecs_os_mutex_t(* ecs_os_api_mutex_new_t) (void)
typedef void(* ecs_os_api_mutex_lock_t) (ecs_os_mutex_t mutex)
typedef void(* ecs_os_api_mutex_unlock_t) (ecs_os_mutex_t mutex)
typedef void(* ecs_os_api_mutex_free_t) (ecs_os_mutex_t mutex)
typedef ecs_os_cond_t(* ecs_os_api_cond_new_t) (void)
typedef void(* ecs_os_api_cond_free_t) (ecs_os_cond_t cond)
typedef void(* ecs_os_api_cond_signal_t) (ecs_os_cond_t cond)
typedef void(* ecs_os_api_cond_broadcast_t) (ecs_os_cond_t cond)
typedef void(* ecs_os_api_cond_wait_t) (ecs_os_cond_t cond, ecs_os_mutex_t mutex)
typedef void(* ecs_os_api_sleep_t) (int32_t sec, int32_t nanosec)
typedef void(* ecs_os_api_enable_high_timer_resolution_t) (bool enable)
typedef void(* ecs_os_api_get_time_t) (ecs_time_t *time_out)
typedef uint64_t(* ecs_os_api_now_t) (void)
typedef void(* ecs_os_api_log_t) (int32_t level, const char *file, int32_t line, const char *msg)
typedef void(* ecs_os_api_abort_t) (void)
typedef ecs_os_dl_t(* ecs_os_api_dlopen_t) (const char *libname)
typedef ecs_os_proc_t(* ecs_os_api_dlproc_t) (ecs_os_dl_t lib, const char *procname)
typedef void(* ecs_os_api_dlclose_t) (ecs_os_dl_t lib)
typedef char *(* ecs_os_api_module_to_path_t) (const char *module_id)
typedef struct ecs_os_api_t ecs_os_api_t


FLECS_API void ecs_os_init (void)
FLECS_API void ecs_os_fini (void)
FLECS_API void ecs_os_set_api (ecs_os_api_t *os_api)
FLECS_API ecs_os_api_t ecs_os_get_api (void)
FLECS_API void ecs_os_set_api_defaults (void)
FLECS_API void ecs_os_dbg (const char *file, int32_t line, const char *msg)
FLECS_API void ecs_os_trace (const char *file, int32_t line, const char *msg)
FLECS_API void ecs_os_warn (const char *file, int32_t line, const char *msg)
FLECS_API void ecs_os_err (const char *file, int32_t line, const char *msg)
FLECS_API void ecs_os_fatal (const char *file, int32_t line, const char *msg)
FLECS_API const char * ecs_os_strerror (int err)
FLECS_API void ecs_os_strset (char **str, const char *value)
FLECS_API void ecs_sleepf (double t)
FLECS_API double ecs_time_measure (ecs_time_t *start)
FLECS_API ecs_time_t ecs_time_sub (ecs_time_t t1, ecs_time_t t2)
FLECS_API double ecs_time_to_double (ecs_time_t t)
FLECS_API void * ecs_os_memdup (const void *src, ecs_size_t size)
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_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?


int64_t ecs_os_api_malloc_count
int64_t ecs_os_api_realloc_count
int64_t ecs_os_api_calloc_count
int64_t ecs_os_api_free_count
FLECS_API ecs_os_api_t ecs_os_api

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.