Flecs: include/flecs/os_api.h Source File
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.0 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
os_api.h
Go to the documentation of this file.
1
12
13#ifndef FLECS_OS_API_H
14#define FLECS_OS_API_H
15
23
24#if defined(ECS_TARGET_WINDOWS)
25#include <malloc.h>
26#elif defined(ECS_TARGET_FREEBSD)
27#include <stdlib.h>
28#else
29#include <alloca.h>
30#endif
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
37 typedef struct ecs_time_t {
38 uint32_t sec;
39 uint32_t nanosec;
40} ecs_time_t;
41
42/* Allocation counters */
43extern int64_t ecs_os_api_malloc_count;
44extern int64_t ecs_os_api_realloc_count;
45extern int64_t ecs_os_api_calloc_count;
46extern int64_t ecs_os_api_free_count;
47
48/* Use handle types that _at least_ can store pointers */
49 typedef uintptr_t ecs_os_thread_t;
50 typedef uintptr_t ecs_os_cond_t;
51 typedef uintptr_t ecs_os_mutex_t;
52 typedef uintptr_t ecs_os_dl_t;
53 typedef uintptr_t ecs_os_sock_t;
54
56 typedef uint64_t ecs_os_thread_id_t;
57
59 typedef void (*ecs_os_proc_t)(void);
60
62typedef
63void (*ecs_os_api_init_t)(void);
64
66typedef
67void (*ecs_os_api_fini_t)(void);
68
70typedef
71 void* (*ecs_os_api_malloc_t)(
72 ecs_size_t size);
73
75typedef
76void (*ecs_os_api_free_t)(
77 void *ptr);
78
80typedef
81 void* (*ecs_os_api_realloc_t)(
82 void *ptr,
83 ecs_size_t size);
84
86typedef
87 void* (*ecs_os_api_calloc_t)(
88 ecs_size_t size);
89
91typedef
92 char* (*ecs_os_api_strdup_t)(
93 const char *str);
94
96typedef
97 void* (*ecs_os_thread_callback_t)(
98 void*);
99
101typedef
102 ecs_os_thread_t (*ecs_os_api_thread_new_t)(
103 ecs_os_thread_callback_t callback,
104 void *param);
105
107typedef
108 void* (*ecs_os_api_thread_join_t)(
109 ecs_os_thread_t thread);
110
112typedef
113 ecs_os_thread_id_t (*ecs_os_api_thread_self_t)(void);
114
116typedef
117 ecs_os_thread_t (*ecs_os_api_task_new_t)(
118 ecs_os_thread_callback_t callback,
119 void *param);
120
122typedef
123 void* (*ecs_os_api_task_join_t)(
124 ecs_os_thread_t thread);
125
126/* Atomic increment / decrement */
128typedef
129int32_t (*ecs_os_api_ainc_t)(
130 int32_t *value);
131
133typedef
134int64_t (*ecs_os_api_lainc_t)(
135 int64_t *value);
136
137/* Mutex */
139typedef
140 ecs_os_mutex_t (*ecs_os_api_mutex_new_t)(
141 void);
142
144typedef
145void (*ecs_os_api_mutex_lock_t)(
146 ecs_os_mutex_t mutex);
147
149typedef
150void (*ecs_os_api_mutex_unlock_t)(
151 ecs_os_mutex_t mutex);
152
154typedef
155void (*ecs_os_api_mutex_free_t)(
156 ecs_os_mutex_t mutex);
157
158/* Condition variable */
160typedef
161 ecs_os_cond_t (*ecs_os_api_cond_new_t)(
162 void);
163
165typedef
166void (*ecs_os_api_cond_free_t)(
167 ecs_os_cond_t cond);
168
170typedef
171void (*ecs_os_api_cond_signal_t)(
172 ecs_os_cond_t cond);
173
175typedef
176void (*ecs_os_api_cond_broadcast_t)(
177 ecs_os_cond_t cond);
178
180typedef
181void (*ecs_os_api_cond_wait_t)(
182 ecs_os_cond_t cond,
183 ecs_os_mutex_t mutex);
184
186typedef
187void (*ecs_os_api_sleep_t)(
188 int32_t sec,
189 int32_t nanosec);
190
192typedef
193void (*ecs_os_api_enable_high_timer_resolution_t)(
194 bool enable);
195
197typedef
198void (*ecs_os_api_get_time_t)(
199 ecs_time_t *time_out);
200
202typedef
203uint64_t (*ecs_os_api_now_t)(void);
204
206typedef
207void (*ecs_os_api_log_t)(
208 int32_t level, /* Logging level */
209 const char *file, /* File where message was logged */
210 int32_t line, /* Line it was logged */
211 const char *msg);
212
214typedef
215void (*ecs_os_api_abort_t)(
216 void);
217
219typedef
220 ecs_os_dl_t (*ecs_os_api_dlopen_t)(
221 const char *libname);
222
224typedef
225 ecs_os_proc_t (*ecs_os_api_dlproc_t)(
226 ecs_os_dl_t lib,
227 const char *procname);
228
230typedef
231void (*ecs_os_api_dlclose_t)(
232 ecs_os_dl_t lib);
233
235typedef
236 char* (*ecs_os_api_module_to_path_t)(
237 const char *module_id);
238
239/* Performance tracing */
240typedef void (*ecs_os_api_perf_trace_t)(
241 const char *filename,
242 size_t line,
243 const char *name);
244
245/* Prefix members of struct with 'ecs_' as some system headers may define
246 * macros for functions like "strdup", "log" or "_free" */
247
249 typedef struct ecs_os_api_t {
250 /* API init / deinit */
251 ecs_os_api_init_t init_;
252 ecs_os_api_fini_t fini_;
253
254 /* Memory management */
255 ecs_os_api_malloc_t malloc_;
256 ecs_os_api_realloc_t realloc_;
257 ecs_os_api_calloc_t calloc_;
258 ecs_os_api_free_t free_;
259
260 /* Strings */
261 ecs_os_api_strdup_t strdup_;
262
263 /* Threads */
264 ecs_os_api_thread_new_t thread_new_;
265 ecs_os_api_thread_join_t thread_join_;
266 ecs_os_api_thread_self_t thread_self_;
267
268 /* Tasks */
269 ecs_os_api_thread_new_t task_new_;
270 ecs_os_api_thread_join_t task_join_;
271
272 /* Atomic increment / decrement */
273 ecs_os_api_ainc_t ainc_;
274 ecs_os_api_ainc_t adec_;
275 ecs_os_api_lainc_t lainc_;
276 ecs_os_api_lainc_t ladec_;
277
278 /* Mutex */
279 ecs_os_api_mutex_new_t mutex_new_;
280 ecs_os_api_mutex_free_t mutex_free_;
281 ecs_os_api_mutex_lock_t mutex_lock_;
282 ecs_os_api_mutex_lock_t mutex_unlock_;
283
284 /* Condition variable */
285 ecs_os_api_cond_new_t cond_new_;
286 ecs_os_api_cond_free_t cond_free_;
287 ecs_os_api_cond_signal_t cond_signal_;
288 ecs_os_api_cond_broadcast_t cond_broadcast_;
289 ecs_os_api_cond_wait_t cond_wait_;
290
291 /* Time */
292 ecs_os_api_sleep_t sleep_;
293 ecs_os_api_now_t now_;
294 ecs_os_api_get_time_t get_time_;
295
296 /* Logging */
297 ecs_os_api_log_t log_;
304
305 /* Application termination */
306 ecs_os_api_abort_t abort_;
307
308 /* Dynamic library loading */
309 ecs_os_api_dlopen_t dlopen_;
310 ecs_os_api_dlproc_t dlproc_;
311 ecs_os_api_dlclose_t dlclose_;
312
313 /* Overridable function that translates from a logical module id to a
314 * shared library filename */
315 ecs_os_api_module_to_path_t module_to_dl_;
316
317 /* Overridable function that translates from a logical module id to a
318 * path that contains module-specif resources or assets */
319 ecs_os_api_module_to_path_t module_to_etc_;
320
321 /* Performance tracing */
322 ecs_os_api_perf_trace_t perf_trace_push_;
323
324 /* Performance tracing */
325 ecs_os_api_perf_trace_t perf_trace_pop_;
326
327 int32_t log_level_;
328 int32_t log_indent_;
329 int32_t log_last_error_;
330 int64_t log_last_timestamp_;
331
332 ecs_flags32_t flags_;
333
334 void *log_out_;
336} ecs_os_api_t;
337
339FLECS_API
340extern ecs_os_api_t ecs_os_api;
341
353FLECS_API
354 void ecs_os_init(void);
355
359FLECS_API
360 void ecs_os_fini(void);
361
368FLECS_API
369 void ecs_os_set_api(
370 ecs_os_api_t *os_api);
371
377FLECS_API
378 ecs_os_api_t ecs_os_get_api(void);
379
386FLECS_API
387 void ecs_os_set_api_defaults(void);
388
392
393/* Memory management */
394#ifndef ecs_os_malloc
395#define ecs_os_malloc(size) ecs_os_api.malloc_(size)
396#endif
397#ifndef ecs_os_free
398#define ecs_os_free(ptr) ecs_os_api.free_(ptr)
399#endif
400#ifndef ecs_os_realloc
401#define ecs_os_realloc(ptr, size) ecs_os_api.realloc_(ptr, size)
402#endif
403#ifndef ecs_os_calloc
404#define ecs_os_calloc(size) ecs_os_api.calloc_(size)
405#endif
406#if defined(ECS_TARGET_WINDOWS)
407#define ecs_os_alloca(size) _alloca((size_t)(size))
408#else
409#define ecs_os_alloca(size) alloca((size_t)(size))
410#endif
411
412#define ecs_os_malloc_t(T) ECS_CAST(T*, ecs_os_malloc(ECS_SIZEOF(T)))
413#define ecs_os_malloc_n(T, count) ECS_CAST(T*, ecs_os_malloc(ECS_SIZEOF(T) * (count)))
414#define ecs_os_calloc_t(T) ECS_CAST(T*, ecs_os_calloc(ECS_SIZEOF(T)))
415#define ecs_os_calloc_n(T, count) ECS_CAST(T*, ecs_os_calloc(ECS_SIZEOF(T) * (count)))
416
417#define ecs_os_realloc_t(ptr, T) ECS_CAST(T*, ecs_os_realloc(ptr, ECS_SIZEOF(T)))
418#define ecs_os_realloc_n(ptr, T, count) ECS_CAST(T*, ecs_os_realloc(ptr, ECS_SIZEOF(T) * (count)))
419#define ecs_os_alloca_t(T) ECS_CAST(T*, ecs_os_alloca(ECS_SIZEOF(T)))
420#define ecs_os_alloca_n(T, count) ECS_CAST(T*, ecs_os_alloca(ECS_SIZEOF(T) * (count)))
421
422/* Strings */
423#ifndef ecs_os_strdup
424#define ecs_os_strdup(str) ecs_os_api.strdup_(str)
425#endif
426
427#ifdef __cplusplus
428#define ecs_os_strlen(str) static_cast<ecs_size_t>(strlen(str))
429#define ecs_os_strncmp(str1, str2, num) strncmp(str1, str2, static_cast<size_t>(num))
430#define ecs_os_memcmp(ptr1, ptr2, num) memcmp(ptr1, ptr2, static_cast<size_t>(num))
431#define ecs_os_memcpy(ptr1, ptr2, num) memcpy(ptr1, ptr2, static_cast<size_t>(num))
432#define ecs_os_memset(ptr, value, num) memset(ptr, value, static_cast<size_t>(num))
433#define ecs_os_memmove(dst, src, size) memmove(dst, src, static_cast<size_t>(size))
434#else
435#define ecs_os_strlen(str) (ecs_size_t)strlen(str)
436#define ecs_os_strncmp(str1, str2, num) strncmp(str1, str2, (size_t)(num))
437#define ecs_os_memcmp(ptr1, ptr2, num) memcmp(ptr1, ptr2, (size_t)(num))
438#define ecs_os_memcpy(ptr1, ptr2, num) memcpy(ptr1, ptr2, (size_t)(num))
439#define ecs_os_memset(ptr, value, num) memset(ptr, value, (size_t)(num))
440#define ecs_os_memmove(dst, src, size) memmove(dst, src, (size_t)(size))
441#endif
442
443#define ecs_os_memcpy_t(ptr1, ptr2, T) ecs_os_memcpy(ptr1, ptr2, ECS_SIZEOF(T))
444#define ecs_os_memcpy_n(ptr1, ptr2, T, count) ecs_os_memcpy(ptr1, ptr2, ECS_SIZEOF(T) * (size_t)count)
445#define ecs_os_memcmp_t(ptr1, ptr2, T) ecs_os_memcmp(ptr1, ptr2, ECS_SIZEOF(T))
446
447#define ecs_os_memmove_t(ptr1, ptr2, T) ecs_os_memmove(ptr1, ptr2, ECS_SIZEOF(T))
448#define ecs_os_memmove_n(ptr1, ptr2, T, count) ecs_os_memmove(ptr1, ptr2, ECS_SIZEOF(T) * (size_t)count)
449#define ecs_os_memmove_t(ptr1, ptr2, T) ecs_os_memmove(ptr1, ptr2, ECS_SIZEOF(T))
450
451#define ecs_os_strcmp(str1, str2) strcmp(str1, str2)
452#define ecs_os_memset_t(ptr, value, T) ecs_os_memset(ptr, value, ECS_SIZEOF(T))
453#define ecs_os_memset_n(ptr, value, T, count) ecs_os_memset(ptr, value, ECS_SIZEOF(T) * (size_t)count)
454#define ecs_os_zeromem(ptr) ecs_os_memset(ptr, 0, ECS_SIZEOF(*ptr))
455
456#define ecs_os_memdup_t(ptr, T) ecs_os_memdup(ptr, ECS_SIZEOF(T))
457#define ecs_os_memdup_n(ptr, T, count) ecs_os_memdup(ptr, ECS_SIZEOF(T) * count)
458
459#define ecs_offset(ptr, T, index)\
460 ECS_CAST(T*, ECS_OFFSET(ptr, ECS_SIZEOF(T) * index))
461
462#if !defined(ECS_TARGET_POSIX) && !defined(ECS_TARGET_MINGW)
463#define ecs_os_strcat(str1, str2) strcat_s(str1, INT_MAX, str2)
464#define ecs_os_snprintf(ptr, len, ...) sprintf_s(ptr, ECS_CAST(size_t, len), __VA_ARGS__)
465#define ecs_os_vsnprintf(ptr, len, fmt, args) vsnprintf(ptr, ECS_CAST(size_t, len), fmt, args)
466#define ecs_os_strcpy(str1, str2) strcpy_s(str1, INT_MAX, str2)
467#define ecs_os_strncpy(str1, str2, len) strncpy_s(str1, INT_MAX, str2, ECS_CAST(size_t, len))
468#else
469#define ecs_os_strcat(str1, str2) strcat(str1, str2)
470#define ecs_os_snprintf(ptr, len, ...) snprintf(ptr, ECS_CAST(size_t, len), __VA_ARGS__)
471#define ecs_os_vsnprintf(ptr, len, fmt, args) vsnprintf(ptr, ECS_CAST(size_t, len), fmt, args)
472#define ecs_os_strcpy(str1, str2) strcpy(str1, str2)
473#define ecs_os_strncpy(str1, str2, len) strncpy(str1, str2, ECS_CAST(size_t, len))
474#endif
475
476/* Files */
477#ifndef ECS_TARGET_POSIX
478#define ecs_os_fopen(result, file, mode) fopen_s(result, file, mode)
479#else
480#define ecs_os_fopen(result, file, mode) (*(result)) = fopen(file, mode)
481#endif
482
483/* Threads */
484#define ecs_os_thread_new(callback, param) ecs_os_api.thread_new_(callback, param)
485#define ecs_os_thread_join(thread) ecs_os_api.thread_join_(thread)
486#define ecs_os_thread_self() ecs_os_api.thread_self_()
487
488/* Tasks */
489#define ecs_os_task_new(callback, param) ecs_os_api.task_new_(callback, param)
490#define ecs_os_task_join(thread) ecs_os_api.task_join_(thread)
491
492/* Atomic increment / decrement */
493#define ecs_os_ainc(value) ecs_os_api.ainc_(value)
494#define ecs_os_adec(value) ecs_os_api.adec_(value)
495#define ecs_os_lainc(value) ecs_os_api.lainc_(value)
496#define ecs_os_ladec(value) ecs_os_api.ladec_(value)
497
498/* Mutex */
499#define ecs_os_mutex_new() ecs_os_api.mutex_new_()
500#define ecs_os_mutex_free(mutex) ecs_os_api.mutex_free_(mutex)
501#define ecs_os_mutex_lock(mutex) ecs_os_api.mutex_lock_(mutex)
502#define ecs_os_mutex_unlock(mutex) ecs_os_api.mutex_unlock_(mutex)
503
504/* Condition variable */
505#define ecs_os_cond_new() ecs_os_api.cond_new_()
506#define ecs_os_cond_free(cond) ecs_os_api.cond_free_(cond)
507#define ecs_os_cond_signal(cond) ecs_os_api.cond_signal_(cond)
508#define ecs_os_cond_broadcast(cond) ecs_os_api.cond_broadcast_(cond)
509#define ecs_os_cond_wait(cond, mutex) ecs_os_api.cond_wait_(cond, mutex)
510
511/* Time */
512#define ecs_os_sleep(sec, nanosec) ecs_os_api.sleep_(sec, nanosec)
513#define ecs_os_now() ecs_os_api.now_()
514#define ecs_os_get_time(time_out) ecs_os_api.get_time_(time_out)
515
516#ifndef FLECS_DISABLE_COUNTERS
517#ifdef FLECS_ACCURATE_COUNTERS
518#define ecs_os_inc(v) (ecs_os_ainc(v))
519#define ecs_os_linc(v) (ecs_os_lainc(v))
520#define ecs_os_dec(v) (ecs_os_adec(v))
521#define ecs_os_ldec(v) (ecs_os_ladec(v))
522#else
523#define ecs_os_inc(v) (++(*v))
524#define ecs_os_linc(v) (++(*v))
525#define ecs_os_dec(v) (--(*v))
526#define ecs_os_ldec(v) (--(*v))
527#endif
528#else
529#define ecs_os_inc(v)
530#define ecs_os_linc(v)
531#define ecs_os_dec(v)
532#define ecs_os_ldec(v)
533#endif
534
535
536#ifdef ECS_TARGET_MINGW
537/* mingw bug: without this a conversion error is thrown, but isnan/isinf should
538 * accept float, double and long double. */
539#define ecs_os_isnan(val) (isnan((float)val))
540#define ecs_os_isinf(val) (isinf((float)val))
541#else
542#define ecs_os_isnan(val) (isnan(val))
543#define ecs_os_isinf(val) (isinf(val))
544#endif
545
546/* Application termination */
547#define ecs_os_abort() ecs_os_api.abort_()
548
549/* Dynamic libraries */
550#define ecs_os_dlopen(libname) ecs_os_api.dlopen_(libname)
551#define ecs_os_dlproc(lib, procname) ecs_os_api.dlproc_(lib, procname)
552#define ecs_os_dlclose(lib) ecs_os_api.dlclose_(lib)
553
554/* Module id translation */
555#define ecs_os_module_to_dl(lib) ecs_os_api.module_to_dl_(lib)
556#define ecs_os_module_to_etc(lib) ecs_os_api.module_to_etc_(lib)
557
561
562
563/* Logging */
564
571FLECS_API
572 void ecs_os_dbg(
573 const char *file,
574 int32_t line,
575 const char *msg);
576
583FLECS_API
584 void ecs_os_trace(
585 const char *file,
586 int32_t line,
587 const char *msg);
588
595FLECS_API
596 void ecs_os_warn(
597 const char *file,
598 int32_t line,
599 const char *msg);
600
607FLECS_API
608 void ecs_os_err(
609 const char *file,
610 int32_t line,
611 const char *msg);
612
619FLECS_API
620 void ecs_os_fatal(
621 const char *file,
622 int32_t line,
623 const char *msg);
624
630FLECS_API
631 const char* ecs_os_strerror(
632 int err);
633
640FLECS_API
641 void ecs_os_strset(
642 char **str,
643 const char *value);
644
645/* Profile tracing */
646#ifdef FLECS_PERF_TRACE
647#define ecs_os_perf_trace_push(name) ecs_os_perf_trace_push_(__FILE__, __LINE__, name)
648#define ecs_os_perf_trace_pop(name) ecs_os_perf_trace_pop_(__FILE__, __LINE__, name)
649#else
650#define ecs_os_perf_trace_push(name)
651#define ecs_os_perf_trace_pop(name)
652#endif
653
654void ecs_os_perf_trace_push_(
655 const char *file,
656 size_t line,
657 const char *name);
658
659void ecs_os_perf_trace_pop_(
660 const char *file,
661 size_t line,
662 const char *name);
663
668FLECS_API
669 void ecs_sleepf(
670 double t);
671
687FLECS_API
688 double ecs_time_measure(
689 ecs_time_t *start);
690
697FLECS_API
698 ecs_time_t ecs_time_sub(
699 ecs_time_t t1,
700 ecs_time_t t2);
701
707FLECS_API
708 double ecs_time_to_double(
709 ecs_time_t t);
710
717FLECS_API
718 void* ecs_os_memdup(
719 const void *src,
720 ecs_size_t size);
721
723FLECS_API
724 bool ecs_os_has_heap(void);
725
727FLECS_API
728 bool ecs_os_has_threading(void);
729
731FLECS_API
732 bool ecs_os_has_task_support(void);
733
735FLECS_API
736 bool ecs_os_has_time(void);
737
739FLECS_API
740 bool ecs_os_has_logging(void);
741
743FLECS_API
744 bool ecs_os_has_dl(void);
745
747FLECS_API
748 bool ecs_os_has_modules(void);
749
750#ifdef __cplusplus
751}
752#endif
753
755
756#endif
ecs_os_api_task_new_t
ecs_os_thread_t(* ecs_os_api_task_new_t)(ecs_os_thread_callback_t callback, void *param)
OS API task_new function type.
Definition os_api.h:117
ecs_os_api_calloc_t
void *(* ecs_os_api_calloc_t)(ecs_size_t size)
OS API calloc function type.
Definition os_api.h:87
ecs_os_api_cond_signal_t
void(* ecs_os_api_cond_signal_t)(ecs_os_cond_t cond)
OS API cond_signal function type.
Definition os_api.h:171
ecs_os_err
FLECS_API void ecs_os_err(const char *file, int32_t line, const char *msg)
Log at error level.
ecs_os_api_cond_free_t
void(* ecs_os_api_cond_free_t)(ecs_os_cond_t cond)
OS API cond_free function type.
Definition os_api.h:166
ecs_os_api_thread_join_t
void *(* ecs_os_api_thread_join_t)(ecs_os_thread_t thread)
OS API thread_join function type.
Definition os_api.h:108
ecs_os_api_dlopen_t
ecs_os_dl_t(* ecs_os_api_dlopen_t)(const char *libname)
OS API dlopen function type.
Definition os_api.h:220
ecs_os_dl_t
uintptr_t ecs_os_dl_t
OS dynamic library.
Definition os_api.h:52
ecs_os_thread_id_t
uint64_t ecs_os_thread_id_t
64 bit thread id.
Definition os_api.h:56
ecs_os_api
FLECS_API ecs_os_api_t ecs_os_api
Static OS API variable with configured callbacks.
ecs_os_api_get_time_t
void(* ecs_os_api_get_time_t)(ecs_time_t *time_out)
OS API get_time function type.
Definition os_api.h:198
ecs_os_api_realloc_count
int64_t ecs_os_api_realloc_count
realloc count.
ecs_os_api_free_count
int64_t ecs_os_api_free_count
free count.
ecs_os_api_thread_new_t
ecs_os_thread_t(* ecs_os_api_thread_new_t)(ecs_os_thread_callback_t callback, void *param)
OS API thread_new function type.
Definition os_api.h:102
ecs_os_thread_callback_t
void *(* ecs_os_thread_callback_t)(void *)
OS API thread_callback function type.
Definition os_api.h:97
ecs_time_measure
FLECS_API double ecs_time_measure(ecs_time_t *start)
Measure time since provided timestamp.
ecs_os_has_time
FLECS_API bool ecs_os_has_time(void)
Are time functions available?
ecs_os_has_dl
FLECS_API bool ecs_os_has_dl(void)
Are dynamic library functions available?
ecs_os_api_thread_self_t
ecs_os_thread_id_t(* ecs_os_api_thread_self_t)(void)
OS API thread_self function type.
Definition os_api.h:113
ecs_os_has_logging
FLECS_API bool ecs_os_has_logging(void)
Are logging functions available?
ecs_os_has_modules
FLECS_API bool ecs_os_has_modules(void)
Are module path functions available?
ecs_os_thread_t
uintptr_t ecs_os_thread_t
OS thread.
Definition os_api.h:49
ecs_os_api_mutex_free_t
void(* ecs_os_api_mutex_free_t)(ecs_os_mutex_t mutex)
OS API mutex_free function type.
Definition os_api.h:155
ecs_os_sock_t
uintptr_t ecs_os_sock_t
OS socket.
Definition os_api.h:53
ecs_os_set_api
FLECS_API void ecs_os_set_api(ecs_os_api_t *os_api)
Override OS API.
ecs_os_api_module_to_path_t
char *(* ecs_os_api_module_to_path_t)(const char *module_id)
OS API module_to_path function type.
Definition os_api.h:236
ecs_os_api_mutex_lock_t
void(* ecs_os_api_mutex_lock_t)(ecs_os_mutex_t mutex)
OS API mutex_lock function type.
Definition os_api.h:145
ecs_os_api_init_t
void(* ecs_os_api_init_t)(void)
OS API init.
Definition os_api.h:63
ecs_os_warn
FLECS_API void ecs_os_warn(const char *file, int32_t line, const char *msg)
Log at warning level.
ecs_os_trace
FLECS_API void ecs_os_trace(const char *file, int32_t line, const char *msg)
Log at trace level.
ecs_os_api_dlproc_t
ecs_os_proc_t(* ecs_os_api_dlproc_t)(ecs_os_dl_t lib, const char *procname)
OS API dlproc function type.
Definition os_api.h:225
ecs_os_has_task_support
FLECS_API bool ecs_os_has_task_support(void)
Are task functions available?
ecs_os_get_api
FLECS_API ecs_os_api_t ecs_os_get_api(void)
Get OS API.
ecs_os_api_dlclose_t
void(* ecs_os_api_dlclose_t)(ecs_os_dl_t lib)
OS API dlclose function type.
Definition os_api.h:231
ecs_os_api_mutex_new_t
ecs_os_mutex_t(* ecs_os_api_mutex_new_t)(void)
OS API mutex_new function type.
Definition os_api.h:140
ecs_os_api_enable_high_timer_resolution_t
void(* ecs_os_api_enable_high_timer_resolution_t)(bool enable)
OS API enable_high_timer_resolution function type.
Definition os_api.h:193
ecs_time_to_double
FLECS_API double ecs_time_to_double(ecs_time_t t)
Convert time value to a double.
ecs_os_api_now_t
uint64_t(* ecs_os_api_now_t)(void)
OS API now function type.
Definition os_api.h:203
ecs_os_api_cond_new_t
ecs_os_cond_t(* ecs_os_api_cond_new_t)(void)
OS API cond_new function type.
Definition os_api.h:161
ecs_os_api_cond_broadcast_t
void(* ecs_os_api_cond_broadcast_t)(ecs_os_cond_t cond)
OS API cond_broadcast function type.
Definition os_api.h:176
ecs_os_api_realloc_t
void *(* ecs_os_api_realloc_t)(void *ptr, ecs_size_t size)
OS API realloc function type.
Definition os_api.h:81
ecs_os_strset
FLECS_API void ecs_os_strset(char **str, const char *value)
Utility for assigning strings.
ecs_os_api_ainc_t
int32_t(* ecs_os_api_ainc_t)(int32_t *value)
OS API ainc function type.
Definition os_api.h:129
ecs_os_dbg
FLECS_API void ecs_os_dbg(const char *file, int32_t line, const char *msg)
Macro utilities.
ecs_os_proc_t
void(* ecs_os_proc_t)(void)
Generic function pointer type.
Definition os_api.h:59
ecs_os_api_strdup_t
char *(* ecs_os_api_strdup_t)(const char *str)
OS API strdup function type.
Definition os_api.h:92
ecs_os_mutex_t
uintptr_t ecs_os_mutex_t
OS mutex.
Definition os_api.h:51
ecs_time_sub
FLECS_API ecs_time_t ecs_time_sub(ecs_time_t t1, ecs_time_t t2)
Calculate difference between two timestamps.
ecs_os_api_mutex_unlock_t
void(* ecs_os_api_mutex_unlock_t)(ecs_os_mutex_t mutex)
OS API mutex_unlock function type.
Definition os_api.h:150
ecs_os_api_fini_t
void(* ecs_os_api_fini_t)(void)
OS API deinit.
Definition os_api.h:67
ecs_os_api_sleep_t
void(* ecs_os_api_sleep_t)(int32_t sec, int32_t nanosec)
OS API sleep function type.
Definition os_api.h:187
ecs_os_cond_t
uintptr_t ecs_os_cond_t
OS cond.
Definition os_api.h:50
ecs_os_api_free_t
void(* ecs_os_api_free_t)(void *ptr)
OS API free function type.
Definition os_api.h:76
ecs_os_api_malloc_count
int64_t ecs_os_api_malloc_count
malloc count.
ecs_os_has_threading
FLECS_API bool ecs_os_has_threading(void)
Are threading functions available?
ecs_os_memdup
FLECS_API void * ecs_os_memdup(const void *src, ecs_size_t size)
Return newly allocated memory that contains a copy of src.
ecs_os_api_cond_wait_t
void(* ecs_os_api_cond_wait_t)(ecs_os_cond_t cond, ecs_os_mutex_t mutex)
OS API cond_wait function type.
Definition os_api.h:181
ecs_os_set_api_defaults
FLECS_API void ecs_os_set_api_defaults(void)
Set default values for OS API.
ecs_os_fatal
FLECS_API void ecs_os_fatal(const char *file, int32_t line, const char *msg)
Log at fatal level.
ecs_os_api_abort_t
void(* ecs_os_api_abort_t)(void)
OS API abort function type.
Definition os_api.h:215
ecs_os_api_lainc_t
int64_t(* ecs_os_api_lainc_t)(int64_t *value)
OS API lainc function type.
Definition os_api.h:134
ecs_os_init
FLECS_API void ecs_os_init(void)
Initialize OS API.
ecs_os_has_heap
FLECS_API bool ecs_os_has_heap(void)
Are heap functions available?
ecs_os_api_log_t
void(* ecs_os_api_log_t)(int32_t level, const char *file, int32_t line, const char *msg)
OS API log function type.
Definition os_api.h:207
ecs_os_api_calloc_count
int64_t ecs_os_api_calloc_count
calloc count.
ecs_os_fini
FLECS_API void ecs_os_fini(void)
Deinitialize OS API.
ecs_os_strerror
FLECS_API const char * ecs_os_strerror(int err)
Convert errno to string.
ecs_sleepf
FLECS_API void ecs_sleepf(double t)
Sleep with floating point time.
ecs_os_api_malloc_t
void *(* ecs_os_api_malloc_t)(ecs_size_t size)
OS API malloc function type.
Definition os_api.h:71
ecs_os_api_t
OS API interface.
Definition os_api.h:249
ecs_os_api_t::cond_wait_
ecs_os_api_cond_wait_t cond_wait_
cond_wait callback.
Definition os_api.h:289
ecs_os_api_t::thread_new_
ecs_os_api_thread_new_t thread_new_
thread_new callback.
Definition os_api.h:264
ecs_os_api_t::free_
ecs_os_api_free_t free_
free callback.
Definition os_api.h:258
ecs_os_api_t::log_last_error_
int32_t log_last_error_
Last logged error code.
Definition os_api.h:329
ecs_os_api_t::sleep_
ecs_os_api_sleep_t sleep_
sleep callback.
Definition os_api.h:292
ecs_os_api_t::realloc_
ecs_os_api_realloc_t realloc_
realloc callback.
Definition os_api.h:256
ecs_os_api_t::mutex_unlock_
ecs_os_api_mutex_lock_t mutex_unlock_
mutex_unlock callback.
Definition os_api.h:282
ecs_os_api_t::abort_
ecs_os_api_abort_t abort_
abort callback.
Definition os_api.h:306
ecs_os_api_t::lainc_
ecs_os_api_lainc_t lainc_
lainc callback.
Definition os_api.h:275
ecs_os_api_t::init_
ecs_os_api_init_t init_
init callback.
Definition os_api.h:251
ecs_os_api_t::get_time_
ecs_os_api_get_time_t get_time_
get_time callback.
Definition os_api.h:294
ecs_os_api_t::cond_broadcast_
ecs_os_api_cond_broadcast_t cond_broadcast_
cond_broadcast callback.
Definition os_api.h:288
ecs_os_api_t::calloc_
ecs_os_api_calloc_t calloc_
calloc callback.
Definition os_api.h:257
ecs_os_api_t::dlopen_
ecs_os_api_dlopen_t dlopen_
dlopen callback.
Definition os_api.h:309
ecs_os_api_t::thread_self_
ecs_os_api_thread_self_t thread_self_
thread_self callback.
Definition os_api.h:266
ecs_os_api_t::thread_join_
ecs_os_api_thread_join_t thread_join_
thread_join callback.
Definition os_api.h:265
ecs_os_api_t::module_to_dl_
ecs_os_api_module_to_path_t module_to_dl_
module_to_dl callback.
Definition os_api.h:315
ecs_os_api_t::log_indent_
int32_t log_indent_
Tracing indentation level.
Definition os_api.h:328
ecs_os_api_t::malloc_
ecs_os_api_malloc_t malloc_
malloc callback.
Definition os_api.h:255
ecs_os_api_t::log_
ecs_os_api_log_t log_
log callback.
Definition os_api.h:297
ecs_os_api_t::task_join_
ecs_os_api_thread_join_t task_join_
task_join callback.
Definition os_api.h:270
ecs_os_api_t::log_last_timestamp_
int64_t log_last_timestamp_
Last logged timestamp.
Definition os_api.h:330
ecs_os_api_t::mutex_new_
ecs_os_api_mutex_new_t mutex_new_
mutex_new callback.
Definition os_api.h:279
ecs_os_api_t::ladec_
ecs_os_api_lainc_t ladec_
ladec callback.
Definition os_api.h:276
ecs_os_api_t::log_out_
void * log_out_
File used for logging output (type is FILE*) (hint, log_ decides where to write)
Definition os_api.h:334
ecs_os_api_t::cond_new_
ecs_os_api_cond_new_t cond_new_
cond_new callback.
Definition os_api.h:285
ecs_os_api_t::task_new_
ecs_os_api_thread_new_t task_new_
task_new callback.
Definition os_api.h:269
ecs_os_api_t::log_level_
int32_t log_level_
Tracing level.
Definition os_api.h:327
ecs_os_api_t::fini_
ecs_os_api_fini_t fini_
fini callback.
Definition os_api.h:252
ecs_os_api_t::cond_signal_
ecs_os_api_cond_signal_t cond_signal_
cond_signal callback.
Definition os_api.h:287
ecs_os_api_t::cond_free_
ecs_os_api_cond_free_t cond_free_
cond_free callback.
Definition os_api.h:286
ecs_os_api_t::strdup_
ecs_os_api_strdup_t strdup_
strdup callback.
Definition os_api.h:261
ecs_os_api_t::mutex_free_
ecs_os_api_mutex_free_t mutex_free_
mutex_free callback.
Definition os_api.h:280
ecs_os_api_t::module_to_etc_
ecs_os_api_module_to_path_t module_to_etc_
module_to_etc callback.
Definition os_api.h:319
ecs_os_api_t::flags_
ecs_flags32_t flags_
OS API flags.
Definition os_api.h:332
ecs_os_api_t::now_
ecs_os_api_now_t now_
now callback.
Definition os_api.h:293
ecs_os_api_t::mutex_lock_
ecs_os_api_mutex_lock_t mutex_lock_
mutex_lock callback.
Definition os_api.h:281
ecs_os_api_t::ainc_
ecs_os_api_ainc_t ainc_
ainc callback.
Definition os_api.h:273
ecs_os_api_t::adec_
ecs_os_api_ainc_t adec_
adec callback.
Definition os_api.h:274
ecs_os_api_t::dlproc_
ecs_os_api_dlproc_t dlproc_
dlproc callback.
Definition os_api.h:310
ecs_os_api_t::dlclose_
ecs_os_api_dlclose_t dlclose_
dlclose callback.
Definition os_api.h:311
ecs_time_t
Time type.
Definition os_api.h:37
ecs_time_t::sec
uint32_t sec
Second part.
Definition os_api.h:38
ecs_time_t::nanosec
uint32_t nanosec
Nanosecond part.
Definition os_api.h:39