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

| Flecs v4.1 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/* Enabling this flag will add a header to each allocation that allows the code
49 * to track exactly how much memory has been allocated. Increases memory
50 * utilization by 16 bytes per allocation, and is not thread safe. */
51// #define FLECS_TRACK_OS_ALLOC
52#ifdef FLECS_TRACK_OS_ALLOC
53FLECS_API extern ecs_size_t ecs_os_allocated_bytes;
54#endif
55
56/* Use handle types that _at least_ can store pointers */
57 typedef uintptr_t ecs_os_thread_t;
58 typedef uintptr_t ecs_os_cond_t;
59 typedef uintptr_t ecs_os_mutex_t;
60 typedef uintptr_t ecs_os_dl_t;
61 typedef uintptr_t ecs_os_sock_t;
62
64 typedef uint64_t ecs_os_thread_id_t;
65
67 typedef void (*ecs_os_proc_t)(void);
68
70typedef
71void (*ecs_os_api_init_t)(void);
72
74typedef
75void (*ecs_os_api_fini_t)(void);
76
78typedef
79 void* (*ecs_os_api_malloc_t)(
80 ecs_size_t size);
81
83typedef
84void (*ecs_os_api_free_t)(
85 void *ptr);
86
88typedef
89 void* (*ecs_os_api_realloc_t)(
90 void *ptr,
91 ecs_size_t size);
92
94typedef
95 void* (*ecs_os_api_calloc_t)(
96 ecs_size_t size);
97
99typedef
100 char* (*ecs_os_api_strdup_t)(
101 const char *str);
102
104typedef
105 void* (*ecs_os_thread_callback_t)(
106 void*);
107
109typedef
110 ecs_os_thread_t (*ecs_os_api_thread_new_t)(
111 ecs_os_thread_callback_t callback,
112 void *param);
113
115typedef
116 void* (*ecs_os_api_thread_join_t)(
117 ecs_os_thread_t thread);
118
120typedef
121 ecs_os_thread_id_t (*ecs_os_api_thread_self_t)(void);
122
124typedef
125 ecs_os_thread_t (*ecs_os_api_task_new_t)(
126 ecs_os_thread_callback_t callback,
127 void *param);
128
130typedef
131 void* (*ecs_os_api_task_join_t)(
132 ecs_os_thread_t thread);
133
134/* Atomic increment / decrement */
136typedef
137int32_t (*ecs_os_api_ainc_t)(
138 int32_t *value);
139
141typedef
142int64_t (*ecs_os_api_lainc_t)(
143 int64_t *value);
144
145/* Mutex */
147typedef
148 ecs_os_mutex_t (*ecs_os_api_mutex_new_t)(
149 void);
150
152typedef
153void (*ecs_os_api_mutex_lock_t)(
154 ecs_os_mutex_t mutex);
155
157typedef
158void (*ecs_os_api_mutex_unlock_t)(
159 ecs_os_mutex_t mutex);
160
162typedef
163void (*ecs_os_api_mutex_free_t)(
164 ecs_os_mutex_t mutex);
165
166/* Condition variable */
168typedef
169 ecs_os_cond_t (*ecs_os_api_cond_new_t)(
170 void);
171
173typedef
174void (*ecs_os_api_cond_free_t)(
175 ecs_os_cond_t cond);
176
178typedef
179void (*ecs_os_api_cond_signal_t)(
180 ecs_os_cond_t cond);
181
183typedef
184void (*ecs_os_api_cond_broadcast_t)(
185 ecs_os_cond_t cond);
186
188typedef
189void (*ecs_os_api_cond_wait_t)(
190 ecs_os_cond_t cond,
191 ecs_os_mutex_t mutex);
192
194typedef
195void (*ecs_os_api_sleep_t)(
196 int32_t sec,
197 int32_t nanosec);
198
200typedef
201void (*ecs_os_api_enable_high_timer_resolution_t)(
202 bool enable);
203
205typedef
206void (*ecs_os_api_get_time_t)(
207 ecs_time_t *time_out);
208
210typedef
211uint64_t (*ecs_os_api_now_t)(void);
212
214typedef
215void (*ecs_os_api_log_t)(
216 int32_t level, /* Logging level */
217 const char *file, /* File where message was logged */
218 int32_t line, /* Line it was logged */
219 const char *msg);
220
222typedef
223void (*ecs_os_api_abort_t)(
224 void);
225
227typedef
228 ecs_os_dl_t (*ecs_os_api_dlopen_t)(
229 const char *libname);
230
232typedef
233 ecs_os_proc_t (*ecs_os_api_dlproc_t)(
234 ecs_os_dl_t lib,
235 const char *procname);
236
238typedef
239void (*ecs_os_api_dlclose_t)(
240 ecs_os_dl_t lib);
241
243typedef
244 char* (*ecs_os_api_module_to_path_t)(
245 const char *module_id);
246
247/* Performance tracing */
248typedef void (*ecs_os_api_perf_trace_t)(
249 const char *filename,
250 size_t line,
251 const char *name);
252
253/* Prefix members of struct with 'ecs_' as some system headers may define
254 * macros for functions like "strdup", "log" or "_free" */
255
257 typedef struct ecs_os_api_t {
258 /* API init / deinit */
259 ecs_os_api_init_t init_;
260 ecs_os_api_fini_t fini_;
261
262 /* Memory management */
263 ecs_os_api_malloc_t malloc_;
264 ecs_os_api_realloc_t realloc_;
265 ecs_os_api_calloc_t calloc_;
266 ecs_os_api_free_t free_;
267
268 /* Strings */
269 ecs_os_api_strdup_t strdup_;
270
271 /* Threads */
272 ecs_os_api_thread_new_t thread_new_;
273 ecs_os_api_thread_join_t thread_join_;
274 ecs_os_api_thread_self_t thread_self_;
275
276 /* Tasks */
277 ecs_os_api_thread_new_t task_new_;
278 ecs_os_api_thread_join_t task_join_;
279
280 /* Atomic increment / decrement */
281 ecs_os_api_ainc_t ainc_;
282 ecs_os_api_ainc_t adec_;
283 ecs_os_api_lainc_t lainc_;
284 ecs_os_api_lainc_t ladec_;
285
286 /* Mutex */
287 ecs_os_api_mutex_new_t mutex_new_;
288 ecs_os_api_mutex_free_t mutex_free_;
289 ecs_os_api_mutex_lock_t mutex_lock_;
290 ecs_os_api_mutex_lock_t mutex_unlock_;
291
292 /* Condition variable */
293 ecs_os_api_cond_new_t cond_new_;
294 ecs_os_api_cond_free_t cond_free_;
295 ecs_os_api_cond_signal_t cond_signal_;
296 ecs_os_api_cond_broadcast_t cond_broadcast_;
297 ecs_os_api_cond_wait_t cond_wait_;
298
299 /* Time */
300 ecs_os_api_sleep_t sleep_;
301 ecs_os_api_now_t now_;
302 ecs_os_api_get_time_t get_time_;
303
304 /* Logging */
305 ecs_os_api_log_t log_;
312
313 /* Application termination */
314 ecs_os_api_abort_t abort_;
315
316 /* Dynamic library loading */
317 ecs_os_api_dlopen_t dlopen_;
318 ecs_os_api_dlproc_t dlproc_;
319 ecs_os_api_dlclose_t dlclose_;
320
321 /* Overridable function that translates from a logical module id to a
322 * shared library filename */
323 ecs_os_api_module_to_path_t module_to_dl_;
324
325 /* Overridable function that translates from a logical module id to a
326 * path that contains module-specif resources or assets */
327 ecs_os_api_module_to_path_t module_to_etc_;
328
329 /* Performance tracing */
330 ecs_os_api_perf_trace_t perf_trace_push_;
331
332 /* Performance tracing */
333 ecs_os_api_perf_trace_t perf_trace_pop_;
334
335 int32_t log_level_;
336 int32_t log_indent_;
337 int32_t log_last_error_;
338 int64_t log_last_timestamp_;
339
340 ecs_flags32_t flags_;
341
342 void *log_out_;
344} ecs_os_api_t;
345
347FLECS_API
348extern ecs_os_api_t ecs_os_api;
349
361FLECS_API
362 void ecs_os_init(void);
363
367FLECS_API
368 void ecs_os_fini(void);
369
376FLECS_API
377 void ecs_os_set_api(
378 ecs_os_api_t *os_api);
379
385FLECS_API
386 ecs_os_api_t ecs_os_get_api(void);
387
394FLECS_API
395 void ecs_os_set_api_defaults(void);
396
400
401/* Memory management */
402#ifndef ecs_os_malloc
403#define ecs_os_malloc(size) ecs_os_api.malloc_(size)
404#endif
405#ifndef ecs_os_free
406#define ecs_os_free(ptr) ecs_os_api.free_(ptr)
407#endif
408#ifndef ecs_os_realloc
409#define ecs_os_realloc(ptr, size) ecs_os_api.realloc_(ptr, size)
410#endif
411#ifndef ecs_os_calloc
412#define ecs_os_calloc(size) ecs_os_api.calloc_(size)
413#endif
414#if defined(ECS_TARGET_WINDOWS)
415#define ecs_os_alloca(size) _alloca((size_t)(size))
416#else
417#define ecs_os_alloca(size) alloca((size_t)(size))
418#endif
419
420#define ecs_os_malloc_t(T) ECS_CAST(T*, ecs_os_malloc(ECS_SIZEOF(T)))
421#define ecs_os_malloc_n(T, count) ECS_CAST(T*, ecs_os_malloc(ECS_SIZEOF(T) * (count)))
422#define ecs_os_calloc_t(T) ECS_CAST(T*, ecs_os_calloc(ECS_SIZEOF(T)))
423#define ecs_os_calloc_n(T, count) ECS_CAST(T*, ecs_os_calloc(ECS_SIZEOF(T) * (count)))
424
425#define ecs_os_realloc_t(ptr, T) ECS_CAST(T*, ecs_os_realloc(ptr, ECS_SIZEOF(T)))
426#define ecs_os_realloc_n(ptr, T, count) ECS_CAST(T*, ecs_os_realloc(ptr, ECS_SIZEOF(T) * (count)))
427#define ecs_os_alloca_t(T) ECS_CAST(T*, ecs_os_alloca(ECS_SIZEOF(T)))
428#define ecs_os_alloca_n(T, count) ECS_CAST(T*, ecs_os_alloca(ECS_SIZEOF(T) * (count)))
429
430/* Strings */
431#ifndef ecs_os_strdup
432#define ecs_os_strdup(str) ecs_os_api.strdup_(str)
433#endif
434
435#ifdef __cplusplus
436#define ecs_os_strlen(str) static_cast<ecs_size_t>(strlen(str))
437#define ecs_os_strncmp(str1, str2, num) strncmp(str1, str2, static_cast<size_t>(num))
438#define ecs_os_memcmp(ptr1, ptr2, num) memcmp(ptr1, ptr2, static_cast<size_t>(num))
439#define ecs_os_memcpy(ptr1, ptr2, num) memcpy(ptr1, ptr2, static_cast<size_t>(num))
440#define ecs_os_memset(ptr, value, num) memset(ptr, value, static_cast<size_t>(num))
441#define ecs_os_memmove(dst, src, size) memmove(dst, src, static_cast<size_t>(size))
442#else
443#define ecs_os_strlen(str) (ecs_size_t)strlen(str)
444#define ecs_os_strncmp(str1, str2, num) strncmp(str1, str2, (size_t)(num))
445#define ecs_os_memcmp(ptr1, ptr2, num) memcmp(ptr1, ptr2, (size_t)(num))
446#define ecs_os_memcpy(ptr1, ptr2, num) memcpy(ptr1, ptr2, (size_t)(num))
447#define ecs_os_memset(ptr, value, num) memset(ptr, value, (size_t)(num))
448#define ecs_os_memmove(dst, src, size) memmove(dst, src, (size_t)(size))
449#endif
450
451#define ecs_os_memcpy_t(ptr1, ptr2, T) ecs_os_memcpy(ptr1, ptr2, ECS_SIZEOF(T))
452#define ecs_os_memcpy_n(ptr1, ptr2, T, count) ecs_os_memcpy(ptr1, ptr2, ECS_SIZEOF(T) * (size_t)count)
453#define ecs_os_memcmp_t(ptr1, ptr2, T) ecs_os_memcmp(ptr1, ptr2, ECS_SIZEOF(T))
454
455#define ecs_os_memmove_t(ptr1, ptr2, T) ecs_os_memmove(ptr1, ptr2, ECS_SIZEOF(T))
456#define ecs_os_memmove_n(ptr1, ptr2, T, count) ecs_os_memmove(ptr1, ptr2, ECS_SIZEOF(T) * (size_t)count)
457#define ecs_os_memmove_t(ptr1, ptr2, T) ecs_os_memmove(ptr1, ptr2, ECS_SIZEOF(T))
458
459#define ecs_os_strcmp(str1, str2) strcmp(str1, str2)
460#define ecs_os_memset_t(ptr, value, T) ecs_os_memset(ptr, value, ECS_SIZEOF(T))
461#define ecs_os_memset_n(ptr, value, T, count) ecs_os_memset(ptr, value, ECS_SIZEOF(T) * (size_t)count)
462#define ecs_os_zeromem(ptr) ecs_os_memset(ptr, 0, ECS_SIZEOF(*ptr))
463
464#define ecs_os_memdup_t(ptr, T) ecs_os_memdup(ptr, ECS_SIZEOF(T))
465#define ecs_os_memdup_n(ptr, T, count) ecs_os_memdup(ptr, ECS_SIZEOF(T) * count)
466
467#define ecs_offset(ptr, T, index)\
468 ECS_CAST(T*, ECS_OFFSET(ptr, ECS_SIZEOF(T) * index))
469
470#if !defined(ECS_TARGET_POSIX) && !defined(ECS_TARGET_MINGW)
471#define ecs_os_strcat(str1, str2) strcat_s(str1, INT_MAX, str2)
472#define ecs_os_snprintf(ptr, len, ...) sprintf_s(ptr, ECS_CAST(size_t, len), __VA_ARGS__)
473#define ecs_os_vsnprintf(ptr, len, fmt, args) vsnprintf(ptr, ECS_CAST(size_t, len), fmt, args)
474#define ecs_os_strcpy(str1, str2) strcpy_s(str1, INT_MAX, str2)
475#define ecs_os_strncpy(str1, str2, len) strncpy_s(str1, INT_MAX, str2, ECS_CAST(size_t, len))
476#else
477#define ecs_os_strcat(str1, str2) strcat(str1, str2)
478#define ecs_os_snprintf(ptr, len, ...) snprintf(ptr, ECS_CAST(size_t, len), __VA_ARGS__)
479#define ecs_os_vsnprintf(ptr, len, fmt, args) vsnprintf(ptr, ECS_CAST(size_t, len), fmt, args)
480#define ecs_os_strcpy(str1, str2) strcpy(str1, str2)
481#define ecs_os_strncpy(str1, str2, len) strncpy(str1, str2, ECS_CAST(size_t, len))
482#endif
483
484/* Files */
485#ifndef ECS_TARGET_POSIX
486#define ecs_os_fopen(result, file, mode) fopen_s(result, file, mode)
487#else
488#define ecs_os_fopen(result, file, mode) (*(result)) = fopen(file, mode)
489#endif
490
491/* Threads */
492#define ecs_os_thread_new(callback, param) ecs_os_api.thread_new_(callback, param)
493#define ecs_os_thread_join(thread) ecs_os_api.thread_join_(thread)
494#define ecs_os_thread_self() ecs_os_api.thread_self_()
495
496/* Tasks */
497#define ecs_os_task_new(callback, param) ecs_os_api.task_new_(callback, param)
498#define ecs_os_task_join(thread) ecs_os_api.task_join_(thread)
499
500/* Atomic increment / decrement */
501#define ecs_os_ainc(value) ecs_os_api.ainc_(value)
502#define ecs_os_adec(value) ecs_os_api.adec_(value)
503#define ecs_os_lainc(value) ecs_os_api.lainc_(value)
504#define ecs_os_ladec(value) ecs_os_api.ladec_(value)
505
506/* Mutex */
507#define ecs_os_mutex_new() ecs_os_api.mutex_new_()
508#define ecs_os_mutex_free(mutex) ecs_os_api.mutex_free_(mutex)
509#define ecs_os_mutex_lock(mutex) ecs_os_api.mutex_lock_(mutex)
510#define ecs_os_mutex_unlock(mutex) ecs_os_api.mutex_unlock_(mutex)
511
512/* Condition variable */
513#define ecs_os_cond_new() ecs_os_api.cond_new_()
514#define ecs_os_cond_free(cond) ecs_os_api.cond_free_(cond)
515#define ecs_os_cond_signal(cond) ecs_os_api.cond_signal_(cond)
516#define ecs_os_cond_broadcast(cond) ecs_os_api.cond_broadcast_(cond)
517#define ecs_os_cond_wait(cond, mutex) ecs_os_api.cond_wait_(cond, mutex)
518
519/* Time */
520#define ecs_os_sleep(sec, nanosec) ecs_os_api.sleep_(sec, nanosec)
521#define ecs_os_now() ecs_os_api.now_()
522#define ecs_os_get_time(time_out) ecs_os_api.get_time_(time_out)
523
524#ifndef FLECS_DISABLE_COUNTERS
525#ifdef FLECS_ACCURATE_COUNTERS
526#define ecs_os_inc(v) (ecs_os_ainc(v))
527#define ecs_os_linc(v) (ecs_os_lainc(v))
528#define ecs_os_dec(v) (ecs_os_adec(v))
529#define ecs_os_ldec(v) (ecs_os_ladec(v))
530#else
531#define ecs_os_inc(v) (++(*v))
532#define ecs_os_linc(v) (++(*v))
533#define ecs_os_dec(v) (--(*v))
534#define ecs_os_ldec(v) (--(*v))
535#endif
536#else
537#define ecs_os_inc(v)
538#define ecs_os_linc(v)
539#define ecs_os_dec(v)
540#define ecs_os_ldec(v)
541#endif
542
543
544#ifdef ECS_TARGET_MINGW
545/* mingw bug: without this a conversion error is thrown, but isnan/isinf should
546 * accept float, double and long double. */
547#define ecs_os_isnan(val) (isnan((float)val))
548#define ecs_os_isinf(val) (isinf((float)val))
549#else
550#define ecs_os_isnan(val) (isnan(val))
551#define ecs_os_isinf(val) (isinf(val))
552#endif
553
554/* Application termination */
555#define ecs_os_abort() ecs_os_api.abort_()
556
557/* Dynamic libraries */
558#define ecs_os_dlopen(libname) ecs_os_api.dlopen_(libname)
559#define ecs_os_dlproc(lib, procname) ecs_os_api.dlproc_(lib, procname)
560#define ecs_os_dlclose(lib) ecs_os_api.dlclose_(lib)
561
562/* Module id translation */
563#define ecs_os_module_to_dl(lib) ecs_os_api.module_to_dl_(lib)
564#define ecs_os_module_to_etc(lib) ecs_os_api.module_to_etc_(lib)
565
569
570
571/* Logging */
572
579FLECS_API
580 void ecs_os_dbg(
581 const char *file,
582 int32_t line,
583 const char *msg);
584
591FLECS_API
592 void ecs_os_trace(
593 const char *file,
594 int32_t line,
595 const char *msg);
596
603FLECS_API
604 void ecs_os_warn(
605 const char *file,
606 int32_t line,
607 const char *msg);
608
615FLECS_API
616 void ecs_os_err(
617 const char *file,
618 int32_t line,
619 const char *msg);
620
627FLECS_API
628 void ecs_os_fatal(
629 const char *file,
630 int32_t line,
631 const char *msg);
632
638FLECS_API
639 const char* ecs_os_strerror(
640 int err);
641
648FLECS_API
649 void ecs_os_strset(
650 char **str,
651 const char *value);
652
653/* Profile tracing */
654#ifdef FLECS_PERF_TRACE
655#define ecs_os_perf_trace_push(name) ecs_os_perf_trace_push_(__FILE__, __LINE__, name)
656#define ecs_os_perf_trace_pop(name) ecs_os_perf_trace_pop_(__FILE__, __LINE__, name)
657#else
658#define ecs_os_perf_trace_push(name)
659#define ecs_os_perf_trace_pop(name)
660#endif
661
662void ecs_os_perf_trace_push_(
663 const char *file,
664 size_t line,
665 const char *name);
666
667void ecs_os_perf_trace_pop_(
668 const char *file,
669 size_t line,
670 const char *name);
671
676FLECS_API
677 void ecs_sleepf(
678 double t);
679
695FLECS_API
696 double ecs_time_measure(
697 ecs_time_t *start);
698
705FLECS_API
706 ecs_time_t ecs_time_sub(
707 ecs_time_t t1,
708 ecs_time_t t2);
709
715FLECS_API
716 double ecs_time_to_double(
717 ecs_time_t t);
718
725FLECS_API
726 void* ecs_os_memdup(
727 const void *src,
728 ecs_size_t size);
729
731FLECS_API
732 bool ecs_os_has_heap(void);
733
735FLECS_API
736 bool ecs_os_has_threading(void);
737
739FLECS_API
740 bool ecs_os_has_task_support(void);
741
743FLECS_API
744 bool ecs_os_has_time(void);
745
747FLECS_API
748 bool ecs_os_has_logging(void);
749
751FLECS_API
752 bool ecs_os_has_dl(void);
753
755FLECS_API
756 bool ecs_os_has_modules(void);
757
758#ifdef __cplusplus
759}
760#endif
761
763
764#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:125
ecs_os_api_calloc_t
void *(* ecs_os_api_calloc_t)(ecs_size_t size)
OS API calloc function type.
Definition os_api.h:95
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:179
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:174
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:116
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:228
ecs_os_dl_t
uintptr_t ecs_os_dl_t
OS dynamic library.
Definition os_api.h:60
ecs_os_thread_id_t
uint64_t ecs_os_thread_id_t
64 bit thread id.
Definition os_api.h:64
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:206
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:110
ecs_os_thread_callback_t
void *(* ecs_os_thread_callback_t)(void *)
OS API thread_callback function type.
Definition os_api.h:105
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:121
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:57
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:163
ecs_os_sock_t
uintptr_t ecs_os_sock_t
OS socket.
Definition os_api.h:61
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:244
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:153
ecs_os_api_init_t
void(* ecs_os_api_init_t)(void)
OS API init.
Definition os_api.h:71
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:233
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:239
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:148
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:201
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:211
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:169
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:184
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:89
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:137
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:67
ecs_os_api_strdup_t
char *(* ecs_os_api_strdup_t)(const char *str)
OS API strdup function type.
Definition os_api.h:100
ecs_os_mutex_t
uintptr_t ecs_os_mutex_t
OS mutex.
Definition os_api.h:59
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:158
ecs_os_api_fini_t
void(* ecs_os_api_fini_t)(void)
OS API deinit.
Definition os_api.h:75
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:195
ecs_os_cond_t
uintptr_t ecs_os_cond_t
OS cond.
Definition os_api.h:58
ecs_os_api_free_t
void(* ecs_os_api_free_t)(void *ptr)
OS API free function type.
Definition os_api.h:84
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:189
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:223
ecs_os_api_lainc_t
int64_t(* ecs_os_api_lainc_t)(int64_t *value)
OS API lainc function type.
Definition os_api.h:142
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:215
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:79
ecs_os_api_t
OS API interface.
Definition os_api.h:257
ecs_os_api_t::cond_wait_
ecs_os_api_cond_wait_t cond_wait_
cond_wait callback.
Definition os_api.h:297
ecs_os_api_t::thread_new_
ecs_os_api_thread_new_t thread_new_
thread_new callback.
Definition os_api.h:272
ecs_os_api_t::free_
ecs_os_api_free_t free_
free callback.
Definition os_api.h:266
ecs_os_api_t::log_last_error_
int32_t log_last_error_
Last logged error code.
Definition os_api.h:337
ecs_os_api_t::sleep_
ecs_os_api_sleep_t sleep_
sleep callback.
Definition os_api.h:300
ecs_os_api_t::realloc_
ecs_os_api_realloc_t realloc_
realloc callback.
Definition os_api.h:264
ecs_os_api_t::mutex_unlock_
ecs_os_api_mutex_lock_t mutex_unlock_
mutex_unlock callback.
Definition os_api.h:290
ecs_os_api_t::abort_
ecs_os_api_abort_t abort_
abort callback.
Definition os_api.h:314
ecs_os_api_t::lainc_
ecs_os_api_lainc_t lainc_
lainc callback.
Definition os_api.h:283
ecs_os_api_t::init_
ecs_os_api_init_t init_
init callback.
Definition os_api.h:259
ecs_os_api_t::get_time_
ecs_os_api_get_time_t get_time_
get_time callback.
Definition os_api.h:302
ecs_os_api_t::cond_broadcast_
ecs_os_api_cond_broadcast_t cond_broadcast_
cond_broadcast callback.
Definition os_api.h:296
ecs_os_api_t::calloc_
ecs_os_api_calloc_t calloc_
calloc callback.
Definition os_api.h:265
ecs_os_api_t::dlopen_
ecs_os_api_dlopen_t dlopen_
dlopen callback.
Definition os_api.h:317
ecs_os_api_t::thread_self_
ecs_os_api_thread_self_t thread_self_
thread_self callback.
Definition os_api.h:274
ecs_os_api_t::thread_join_
ecs_os_api_thread_join_t thread_join_
thread_join callback.
Definition os_api.h:273
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:323
ecs_os_api_t::log_indent_
int32_t log_indent_
Tracing indentation level.
Definition os_api.h:336
ecs_os_api_t::malloc_
ecs_os_api_malloc_t malloc_
malloc callback.
Definition os_api.h:263
ecs_os_api_t::log_
ecs_os_api_log_t log_
log callback.
Definition os_api.h:305
ecs_os_api_t::task_join_
ecs_os_api_thread_join_t task_join_
task_join callback.
Definition os_api.h:278
ecs_os_api_t::log_last_timestamp_
int64_t log_last_timestamp_
Last logged timestamp.
Definition os_api.h:338
ecs_os_api_t::mutex_new_
ecs_os_api_mutex_new_t mutex_new_
mutex_new callback.
Definition os_api.h:287
ecs_os_api_t::ladec_
ecs_os_api_lainc_t ladec_
ladec callback.
Definition os_api.h:284
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:342
ecs_os_api_t::cond_new_
ecs_os_api_cond_new_t cond_new_
cond_new callback.
Definition os_api.h:293
ecs_os_api_t::task_new_
ecs_os_api_thread_new_t task_new_
task_new callback.
Definition os_api.h:277
ecs_os_api_t::log_level_
int32_t log_level_
Tracing level.
Definition os_api.h:335
ecs_os_api_t::fini_
ecs_os_api_fini_t fini_
fini callback.
Definition os_api.h:260
ecs_os_api_t::cond_signal_
ecs_os_api_cond_signal_t cond_signal_
cond_signal callback.
Definition os_api.h:295
ecs_os_api_t::cond_free_
ecs_os_api_cond_free_t cond_free_
cond_free callback.
Definition os_api.h:294
ecs_os_api_t::strdup_
ecs_os_api_strdup_t strdup_
strdup callback.
Definition os_api.h:269
ecs_os_api_t::mutex_free_
ecs_os_api_mutex_free_t mutex_free_
mutex_free callback.
Definition os_api.h:288
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:327
ecs_os_api_t::flags_
ecs_flags32_t flags_
OS API flags.
Definition os_api.h:340
ecs_os_api_t::now_
ecs_os_api_now_t now_
now callback.
Definition os_api.h:301
ecs_os_api_t::mutex_lock_
ecs_os_api_mutex_lock_t mutex_lock_
mutex_lock callback.
Definition os_api.h:289
ecs_os_api_t::ainc_
ecs_os_api_ainc_t ainc_
ainc callback.
Definition os_api.h:281
ecs_os_api_t::adec_
ecs_os_api_ainc_t adec_
adec callback.
Definition os_api.h:282
ecs_os_api_t::dlproc_
ecs_os_api_dlproc_t dlproc_
dlproc callback.
Definition os_api.h:318
ecs_os_api_t::dlclose_
ecs_os_api_dlclose_t dlclose_
dlclose callback.
Definition os_api.h:319
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