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#include <stdio.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
39 typedef struct ecs_time_t {
40 uint32_t sec;
41 uint32_t nanosec;
42} ecs_time_t;
43
45FLECS_API extern int64_t ecs_os_api_malloc_count;
46FLECS_API extern int64_t ecs_os_api_realloc_count;
47FLECS_API extern int64_t ecs_os_api_calloc_count;
48FLECS_API extern int64_t ecs_os_api_free_count;
49
50/* Enabling this flag will add a header to each allocation that allows the code
51 * to track exactly how much memory has been allocated. Increases memory
52 * utilization by 16 bytes per allocation, and is not thread-safe. */
53// #define FLECS_TRACK_OS_ALLOC
54#ifdef FLECS_TRACK_OS_ALLOC
55FLECS_API extern ecs_size_t ecs_os_allocated_bytes;
56#endif
57
59 typedef uintptr_t ecs_os_thread_t;
60 typedef uintptr_t ecs_os_cond_t;
61 typedef uintptr_t ecs_os_mutex_t;
62 typedef uintptr_t ecs_os_dl_t;
63 typedef uintptr_t ecs_os_sock_t;
64
66 typedef uint64_t ecs_os_thread_id_t;
67
69 typedef void (*ecs_os_proc_t)(void);
70
72typedef
73void (*ecs_os_api_init_t)(void);
74
76typedef
77void (*ecs_os_api_fini_t)(void);
78
80typedef
81 void* (*ecs_os_api_malloc_t)(
82 ecs_size_t size);
83
85typedef
86void (*ecs_os_api_free_t)(
87 void *ptr);
88
90typedef
91 void* (*ecs_os_api_realloc_t)(
92 void *ptr,
93 ecs_size_t size);
94
96typedef
97 void* (*ecs_os_api_calloc_t)(
98 ecs_size_t size);
99
101typedef
102 char* (*ecs_os_api_strdup_t)(
103 const char *str);
104
106typedef
107 void* (*ecs_os_thread_callback_t)(
108 void*);
109
111typedef
112 ecs_os_thread_t (*ecs_os_api_thread_new_t)(
113 ecs_os_thread_callback_t callback,
114 void *param);
115
117typedef
118 void* (*ecs_os_api_thread_join_t)(
119 ecs_os_thread_t thread);
120
122typedef
123 ecs_os_thread_id_t (*ecs_os_api_thread_self_t)(void);
124
126typedef
127 ecs_os_thread_t (*ecs_os_api_task_new_t)(
128 ecs_os_thread_callback_t callback,
129 void *param);
130
132typedef
133 void* (*ecs_os_api_task_join_t)(
134 ecs_os_thread_t thread);
135
138typedef
139int32_t (*ecs_os_api_ainc_t)(
140 int32_t *value);
141
143typedef
144int64_t (*ecs_os_api_lainc_t)(
145 int64_t *value);
146
149typedef
150 ecs_os_mutex_t (*ecs_os_api_mutex_new_t)(
151 void);
152
154typedef
155void (*ecs_os_api_mutex_lock_t)(
156 ecs_os_mutex_t mutex);
157
159typedef
160void (*ecs_os_api_mutex_unlock_t)(
161 ecs_os_mutex_t mutex);
162
164typedef
165void (*ecs_os_api_mutex_free_t)(
166 ecs_os_mutex_t mutex);
167
170typedef
171 ecs_os_cond_t (*ecs_os_api_cond_new_t)(
172 void);
173
175typedef
176void (*ecs_os_api_cond_free_t)(
177 ecs_os_cond_t cond);
178
180typedef
181void (*ecs_os_api_cond_signal_t)(
182 ecs_os_cond_t cond);
183
185typedef
186void (*ecs_os_api_cond_broadcast_t)(
187 ecs_os_cond_t cond);
188
190typedef
191void (*ecs_os_api_cond_wait_t)(
192 ecs_os_cond_t cond,
193 ecs_os_mutex_t mutex);
194
196typedef
197void (*ecs_os_api_sleep_t)(
198 int32_t sec,
199 int32_t nanosec);
200
202typedef
203void (*ecs_os_api_enable_high_timer_resolution_t)(
204 bool enable);
205
207typedef
208void (*ecs_os_api_get_time_t)(
209 ecs_time_t *time_out);
210
212typedef
213uint64_t (*ecs_os_api_now_t)(void);
214
222typedef
223void (*ecs_os_api_log_t)(
224 int32_t level,
225 const char *file,
226 int32_t line,
227 const char *msg);
228
230typedef
231void (*ecs_os_api_abort_t)(
232 void);
233
235typedef
236 ecs_os_dl_t (*ecs_os_api_dlopen_t)(
237 const char *libname);
238
240typedef
241 ecs_os_proc_t (*ecs_os_api_dlproc_t)(
242 ecs_os_dl_t lib,
243 const char *procname);
244
246typedef
247void (*ecs_os_api_dlclose_t)(
248 ecs_os_dl_t lib);
249
251typedef
252 char* (*ecs_os_api_module_to_path_t)(
253 const char *module_id);
254
256typedef
257FILE* (*ecs_os_api_fopen_t)(
258 const char *file,
259 const char *mode);
260
262typedef
263void (*ecs_os_api_fclose_t)(
264 FILE *file);
265
272 typedef void (*ecs_os_api_perf_trace_t)(
273 const char *filename,
274 size_t line,
275 const char *name);
276
277/* Prefix members of the struct with 'ecs_' as some system headers may define
278 * macros for functions like "strdup", "log", or "_free". */
279
281 typedef struct ecs_os_api_t {
282 /* API init and deinit */
283 ecs_os_api_init_t init_;
284 ecs_os_api_fini_t fini_;
285
286 /* Memory management */
287 ecs_os_api_malloc_t malloc_;
288 ecs_os_api_realloc_t realloc_;
289 ecs_os_api_calloc_t calloc_;
290 ecs_os_api_free_t free_;
291
292 /* Strings */
293 ecs_os_api_strdup_t strdup_;
294
295 /* Threads */
296 ecs_os_api_thread_new_t thread_new_;
297 ecs_os_api_thread_join_t thread_join_;
298 ecs_os_api_thread_self_t thread_self_;
299
300 /* Tasks */
301 ecs_os_api_thread_new_t task_new_;
302 ecs_os_api_thread_join_t task_join_;
303
304 /* Atomic increment and decrement */
305 ecs_os_api_ainc_t ainc_;
306 ecs_os_api_ainc_t adec_;
307 ecs_os_api_lainc_t lainc_;
308 ecs_os_api_lainc_t ladec_;
309
310 /* Mutex */
311 ecs_os_api_mutex_new_t mutex_new_;
312 ecs_os_api_mutex_free_t mutex_free_;
313 ecs_os_api_mutex_lock_t mutex_lock_;
314 ecs_os_api_mutex_lock_t mutex_unlock_;
315
316 /* Condition variable */
317 ecs_os_api_cond_new_t cond_new_;
318 ecs_os_api_cond_free_t cond_free_;
319 ecs_os_api_cond_signal_t cond_signal_;
320 ecs_os_api_cond_broadcast_t cond_broadcast_;
321 ecs_os_api_cond_wait_t cond_wait_;
322
323 /* Time */
324 ecs_os_api_sleep_t sleep_;
325 ecs_os_api_now_t now_;
326 ecs_os_api_get_time_t get_time_;
327
328 /* Logging */
329 ecs_os_api_log_t log_;
336
337 /* Application termination */
338 ecs_os_api_abort_t abort_;
339
340 /* Dynamic library loading */
341 ecs_os_api_dlopen_t dlopen_;
342 ecs_os_api_dlproc_t dlproc_;
343 ecs_os_api_dlclose_t dlclose_;
344
345 /* Overridable function that translates from a logical module ID to a
346 * shared library filename. */
347 ecs_os_api_module_to_path_t module_to_dl_;
348
349 /* Overridable function that translates from a logical module ID to a
350 * path that contains module-specific resources or assets. */
351 ecs_os_api_module_to_path_t module_to_etc_;
352
353 /* File I/O */
354 ecs_os_api_fopen_t fopen_;
355 ecs_os_api_fclose_t fclose_;
356
357 /* Performance tracing */
358 ecs_os_api_perf_trace_t perf_trace_push_;
359 ecs_os_api_perf_trace_t perf_trace_pop_;
360
361 int32_t log_level_;
362 int32_t log_indent_;
363 int32_t log_last_error_;
364 int64_t log_last_timestamp_;
365
366 ecs_flags32_t flags_;
367
368 void *log_out_;
370} ecs_os_api_t;
371
373FLECS_API
374extern ecs_os_api_t ecs_os_api;
375
387FLECS_API
388 void ecs_os_init(void);
389
393FLECS_API
394 void ecs_os_fini(void);
395
402FLECS_API
403 void ecs_os_set_api(
404 ecs_os_api_t *os_api);
405
411FLECS_API
412 ecs_os_api_t ecs_os_get_api(void);
413
420FLECS_API
421 void ecs_os_set_api_defaults(void);
422
426
427/* Memory management */
428#ifndef ecs_os_malloc
429#define ecs_os_malloc(size) ecs_os_api.malloc_(size)
430#endif
431#ifndef ecs_os_free
432#define ecs_os_free(ptr) ecs_os_api.free_(ptr)
433#endif
434#ifndef ecs_os_realloc
435#define ecs_os_realloc(ptr, size) ecs_os_api.realloc_(ptr, size)
436#endif
437#ifndef ecs_os_calloc
438#define ecs_os_calloc(size) ecs_os_api.calloc_(size)
439#endif
440#if defined(ECS_TARGET_WINDOWS)
441#define ecs_os_alloca(size) _alloca((size_t)(size))
442#else
443#define ecs_os_alloca(size) alloca((size_t)(size))
444#endif
445
446#define ecs_os_malloc_t(T) ECS_CAST(T*, ecs_os_malloc(ECS_SIZEOF(T)))
447#define ecs_os_malloc_n(T, count) ECS_CAST(T*, ecs_os_malloc(ECS_SIZEOF(T) * (count)))
448#define ecs_os_calloc_t(T) ECS_CAST(T*, ecs_os_calloc(ECS_SIZEOF(T)))
449#define ecs_os_calloc_n(T, count) ECS_CAST(T*, ecs_os_calloc(ECS_SIZEOF(T) * (count)))
450
451#define ecs_os_realloc_t(ptr, T) ECS_CAST(T*, ecs_os_realloc(ptr, ECS_SIZEOF(T)))
452#define ecs_os_realloc_n(ptr, T, count) ECS_CAST(T*, ecs_os_realloc(ptr, ECS_SIZEOF(T) * (count)))
453#define ecs_os_alloca_t(T) ECS_CAST(T*, ecs_os_alloca(ECS_SIZEOF(T)))
454#define ecs_os_alloca_n(T, count) ECS_CAST(T*, ecs_os_alloca(ECS_SIZEOF(T) * (count)))
455
456/* Strings */
457#ifndef ecs_os_strdup
458#define ecs_os_strdup(str) ecs_os_api.strdup_(str)
459#endif
460
461#ifdef __cplusplus
462#define ecs_os_strlen(str) static_cast<ecs_size_t>(strlen(str))
463#define ecs_os_strncmp(str1, str2, num) strncmp(str1, str2, static_cast<size_t>(num))
464#define ecs_os_memcmp(ptr1, ptr2, num) memcmp(ptr1, ptr2, static_cast<size_t>(num))
465#define ecs_os_memcpy(ptr1, ptr2, num) memcpy(ptr1, ptr2, static_cast<size_t>(num))
466#define ecs_os_memset(ptr, value, num) memset(ptr, value, static_cast<size_t>(num))
467#define ecs_os_memmove(dst, src, size) memmove(dst, src, static_cast<size_t>(size))
468#else
469#define ecs_os_strlen(str) (ecs_size_t)strlen(str)
470#define ecs_os_strncmp(str1, str2, num) strncmp(str1, str2, (size_t)(num))
471#define ecs_os_memcmp(ptr1, ptr2, num) memcmp(ptr1, ptr2, (size_t)(num))
472#define ecs_os_memcpy(ptr1, ptr2, num) memcpy(ptr1, ptr2, (size_t)(num))
473#define ecs_os_memset(ptr, value, num) memset(ptr, value, (size_t)(num))
474#define ecs_os_memmove(dst, src, size) memmove(dst, src, (size_t)(size))
475#endif
476
477#define ecs_os_memcpy_t(ptr1, ptr2, T) ecs_os_memcpy(ptr1, ptr2, ECS_SIZEOF(T))
478#define ecs_os_memcpy_n(ptr1, ptr2, T, count) ecs_os_memcpy(ptr1, ptr2, ECS_SIZEOF(T) * (size_t)count)
479#define ecs_os_memcmp_t(ptr1, ptr2, T) ecs_os_memcmp(ptr1, ptr2, ECS_SIZEOF(T))
480
481#define ecs_os_memmove_t(ptr1, ptr2, T) ecs_os_memmove(ptr1, ptr2, ECS_SIZEOF(T))
482#define ecs_os_memmove_n(ptr1, ptr2, T, count) ecs_os_memmove(ptr1, ptr2, ECS_SIZEOF(T) * (size_t)count)
483
484#define ecs_os_strcmp(str1, str2) strcmp(str1, str2)
485#define ecs_os_memset_t(ptr, value, T) ecs_os_memset(ptr, value, ECS_SIZEOF(T))
486#define ecs_os_memset_n(ptr, value, T, count) ecs_os_memset(ptr, value, ECS_SIZEOF(T) * (size_t)count)
487#define ecs_os_zeromem(ptr) ecs_os_memset(ptr, 0, ECS_SIZEOF(*ptr))
488
489#define ecs_os_memdup_t(ptr, T) ecs_os_memdup(ptr, ECS_SIZEOF(T))
490#define ecs_os_memdup_n(ptr, T, count) ecs_os_memdup(ptr, ECS_SIZEOF(T) * count)
491
492#define ecs_offset(ptr, T, index)\
493 ECS_CAST(T*, ECS_OFFSET(ptr, ECS_SIZEOF(T) * index))
494
495#if !defined(ECS_TARGET_POSIX) && !defined(ECS_TARGET_MINGW)
496#define ecs_os_strcat(str1, str2) strcat_s(str1, INT_MAX, str2)
497#define ecs_os_snprintf(ptr, len, ...) sprintf_s(ptr, ECS_CAST(size_t, len), __VA_ARGS__)
498#define ecs_os_vsnprintf(ptr, len, fmt, args) vsnprintf(ptr, ECS_CAST(size_t, len), fmt, args)
499#define ecs_os_strcpy(str1, str2) strcpy_s(str1, INT_MAX, str2)
500#define ecs_os_strncpy(str1, str2, len) strncpy_s(str1, INT_MAX, str2, ECS_CAST(size_t, len))
501#else
502#define ecs_os_strcat(str1, str2) strcat(str1, str2)
503#define ecs_os_snprintf(ptr, len, ...) snprintf(ptr, ECS_CAST(size_t, len), __VA_ARGS__)
504#define ecs_os_vsnprintf(ptr, len, fmt, args) vsnprintf(ptr, ECS_CAST(size_t, len), fmt, args)
505#define ecs_os_strcpy(str1, str2) strcpy(str1, str2)
506#define ecs_os_strncpy(str1, str2, len) strncpy(str1, str2, ECS_CAST(size_t, len))
507#endif
508
509/* Files */
510#define ecs_os_fopen(file, mode) ecs_os_api.fopen_(file, mode)
511#define ecs_os_fclose(file) ecs_os_api.fclose_(file)
512
513/* Threads */
514#define ecs_os_thread_new(callback, param) ecs_os_api.thread_new_(callback, param)
515#define ecs_os_thread_join(thread) ecs_os_api.thread_join_(thread)
516#define ecs_os_thread_self() ecs_os_api.thread_self_()
517
518/* Tasks */
519#define ecs_os_task_new(callback, param) ecs_os_api.task_new_(callback, param)
520#define ecs_os_task_join(thread) ecs_os_api.task_join_(thread)
521
522/* Atomic increment and decrement */
523#define ecs_os_ainc(value) ecs_os_api.ainc_(value)
524#define ecs_os_adec(value) ecs_os_api.adec_(value)
525#define ecs_os_lainc(value) ecs_os_api.lainc_(value)
526#define ecs_os_ladec(value) ecs_os_api.ladec_(value)
527
528/* Mutex */
529#define ecs_os_mutex_new() ecs_os_api.mutex_new_()
530#define ecs_os_mutex_free(mutex) ecs_os_api.mutex_free_(mutex)
531#define ecs_os_mutex_lock(mutex) ecs_os_api.mutex_lock_(mutex)
532#define ecs_os_mutex_unlock(mutex) ecs_os_api.mutex_unlock_(mutex)
533
534/* Condition variable */
535#define ecs_os_cond_new() ecs_os_api.cond_new_()
536#define ecs_os_cond_free(cond) ecs_os_api.cond_free_(cond)
537#define ecs_os_cond_signal(cond) ecs_os_api.cond_signal_(cond)
538#define ecs_os_cond_broadcast(cond) ecs_os_api.cond_broadcast_(cond)
539#define ecs_os_cond_wait(cond, mutex) ecs_os_api.cond_wait_(cond, mutex)
540
541/* Time */
542#define ecs_os_sleep(sec, nanosec) ecs_os_api.sleep_(sec, nanosec)
543#define ecs_os_now() ecs_os_api.now_()
544#define ecs_os_get_time(time_out) ecs_os_api.get_time_(time_out)
545
546#ifndef FLECS_DISABLE_COUNTERS
547#ifdef FLECS_ACCURATE_COUNTERS
548#define ecs_os_inc(v) (ecs_os_ainc(v))
549#define ecs_os_linc(v) (ecs_os_lainc(v))
550#define ecs_os_dec(v) (ecs_os_adec(v))
551#define ecs_os_ldec(v) (ecs_os_ladec(v))
552#else
553#define ecs_os_inc(v) (++(*v))
554#define ecs_os_linc(v) (++(*v))
555#define ecs_os_dec(v) (--(*v))
556#define ecs_os_ldec(v) (--(*v))
557#endif
558#else
559#define ecs_os_inc(v)
560#define ecs_os_linc(v)
561#define ecs_os_dec(v)
562#define ecs_os_ldec(v)
563#endif
564
565
566#ifdef ECS_TARGET_MINGW
567/* mingw bug: without this, a conversion error is thrown, but isnan/isinf should
568 * accept float, double, and long double. */
569#define ecs_os_isnan(val) (isnan((float)val))
570#define ecs_os_isinf(val) (isinf((float)val))
571#else
572#define ecs_os_isnan(val) (isnan(val))
573#define ecs_os_isinf(val) (isinf(val))
574#endif
575
576/* Application termination */
577#define ecs_os_abort() ecs_os_api.abort_()
578
579/* Dynamic libraries */
580#define ecs_os_dlopen(libname) ecs_os_api.dlopen_(libname)
581#define ecs_os_dlproc(lib, procname) ecs_os_api.dlproc_(lib, procname)
582#define ecs_os_dlclose(lib) ecs_os_api.dlclose_(lib)
583
584/* Module ID translation */
585#define ecs_os_module_to_dl(lib) ecs_os_api.module_to_dl_(lib)
586#define ecs_os_module_to_etc(lib) ecs_os_api.module_to_etc_(lib)
587
591
592
593/* Logging */
594
601FLECS_API
602 void ecs_os_dbg(
603 const char *file,
604 int32_t line,
605 const char *msg);
606
613FLECS_API
614 void ecs_os_trace(
615 const char *file,
616 int32_t line,
617 const char *msg);
618
625FLECS_API
626 void ecs_os_warn(
627 const char *file,
628 int32_t line,
629 const char *msg);
630
637FLECS_API
638 void ecs_os_err(
639 const char *file,
640 int32_t line,
641 const char *msg);
642
649FLECS_API
650 void ecs_os_fatal(
651 const char *file,
652 int32_t line,
653 const char *msg);
654
660FLECS_API
661 const char* ecs_os_strerror(
662 int err);
663
670FLECS_API
671 void ecs_os_strset(
672 char **str,
673 const char *value);
674
675/* Profile tracing */
676#ifdef FLECS_PERF_TRACE
677#define ecs_os_perf_trace_push(name) ecs_os_perf_trace_push_(__FILE__, __LINE__, name)
678#define ecs_os_perf_trace_pop(name) ecs_os_perf_trace_pop_(__FILE__, __LINE__, name)
679#else
680#define ecs_os_perf_trace_push(name)
681#define ecs_os_perf_trace_pop(name)
682#endif
683
690 void ecs_os_perf_trace_push_(
691 const char *file,
692 size_t line,
693 const char *name);
694
701 void ecs_os_perf_trace_pop_(
702 const char *file,
703 size_t line,
704 const char *name);
705
710FLECS_API
711 void ecs_sleepf(
712 double t);
713
729FLECS_API
730 double ecs_time_measure(
731 ecs_time_t *start);
732
739FLECS_API
740 ecs_time_t ecs_time_sub(
741 ecs_time_t t1,
742 ecs_time_t t2);
743
749FLECS_API
750 double ecs_time_to_double(
751 ecs_time_t t);
752
759FLECS_API
760 void* ecs_os_memdup(
761 const void *src,
762 ecs_size_t size);
763
765FLECS_API
766 bool ecs_os_has_heap(void);
767
769FLECS_API
770 bool ecs_os_has_threading(void);
771
773FLECS_API
774 bool ecs_os_has_task_support(void);
775
777FLECS_API
778 bool ecs_os_has_time(void);
779
781FLECS_API
782 bool ecs_os_has_logging(void);
783
785FLECS_API
786 bool ecs_os_has_dl(void);
787
789FLECS_API
790 bool ecs_os_has_modules(void);
791
792#ifdef __cplusplus
793}
794#endif
795
797
798#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:127
ecs_os_api_calloc_t
void *(* ecs_os_api_calloc_t)(ecs_size_t size)
OS API calloc function type.
Definition os_api.h:97
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:181
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:176
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:118
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:236
ecs_os_dl_t
uintptr_t ecs_os_dl_t
OS dynamic library.
Definition os_api.h:62
ecs_os_thread_id_t
uint64_t ecs_os_thread_id_t
64-bit thread ID.
Definition os_api.h:66
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:208
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:112
ecs_os_thread_callback_t
void *(* ecs_os_thread_callback_t)(void *)
OS API thread_callback function type.
Definition os_api.h:107
ecs_os_api_realloc_count
FLECS_API int64_t ecs_os_api_realloc_count
realloc count.
ecs_time_measure
FLECS_API double ecs_time_measure(ecs_time_t *start)
Measure time since the 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:123
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
Use handle types that at least can store pointers.
Definition os_api.h:59
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:165
ecs_os_sock_t
uintptr_t ecs_os_sock_t
OS socket.
Definition os_api.h:63
ecs_os_api_malloc_count
FLECS_API int64_t ecs_os_api_malloc_count
Allocation counters.
ecs_os_set_api
FLECS_API void ecs_os_set_api(ecs_os_api_t *os_api)
Override the 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:252
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:155
ecs_os_api_init_t
void(* ecs_os_api_init_t)(void)
OS API init.
Definition os_api.h:73
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:241
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 the 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:247
ecs_os_api_mutex_new_t
ecs_os_mutex_t(* ecs_os_api_mutex_new_t)(void)
Mutex.
Definition os_api.h:150
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:203
ecs_time_to_double
FLECS_API double ecs_time_to_double(ecs_time_t t)
Convert a 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:213
ecs_os_api_cond_new_t
ecs_os_cond_t(* ecs_os_api_cond_new_t)(void)
Condition variable.
Definition os_api.h:171
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:186
ecs_os_api_free_count
FLECS_API int64_t ecs_os_api_free_count
free count.
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:91
ecs_os_strset
FLECS_API void ecs_os_strset(char **str, const char *value)
A utility for assigning strings.
ecs_os_api_ainc_t
int32_t(* ecs_os_api_ainc_t)(int32_t *value)
Atomic increment and decrement.
Definition os_api.h:139
ecs_os_dbg
FLECS_API void ecs_os_dbg(const char *file, int32_t line, const char *msg)
Macro utilities.
ecs_os_api_fopen_t
FILE *(* ecs_os_api_fopen_t)(const char *file, const char *mode)
OS API fopen function type.
Definition os_api.h:257
ecs_os_perf_trace_push_
void ecs_os_perf_trace_push_(const char *file, size_t line, const char *name)
Push a performance trace region.
ecs_os_proc_t
void(* ecs_os_proc_t)(void)
Generic function pointer type.
Definition os_api.h:69
ecs_os_api_strdup_t
char *(* ecs_os_api_strdup_t)(const char *str)
OS API strdup function type.
Definition os_api.h:102
ecs_os_mutex_t
uintptr_t ecs_os_mutex_t
OS mutex.
Definition os_api.h:61
ecs_time_sub
FLECS_API ecs_time_t ecs_time_sub(ecs_time_t t1, ecs_time_t t2)
Calculate the 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:160
ecs_os_api_fini_t
void(* ecs_os_api_fini_t)(void)
OS API deinit.
Definition os_api.h:77
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:197
ecs_os_cond_t
uintptr_t ecs_os_cond_t
OS cond.
Definition os_api.h:60
ecs_os_api_free_t
void(* ecs_os_api_free_t)(void *ptr)
OS API free function type.
Definition os_api.h:86
ecs_os_has_threading
FLECS_API bool ecs_os_has_threading(void)
Are threading functions available?
ecs_os_api_perf_trace_t
void(* ecs_os_api_perf_trace_t)(const char *filename, size_t line, const char *name)
OS API performance tracing function type.
Definition os_api.h:272
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:191
ecs_os_set_api_defaults
FLECS_API void ecs_os_set_api_defaults(void)
Set default values for the 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:231
ecs_os_api_lainc_t
int64_t(* ecs_os_api_lainc_t)(int64_t *value)
OS API lainc function type.
Definition os_api.h:144
ecs_os_init
FLECS_API void ecs_os_init(void)
Initialize the 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:223
ecs_os_fini
FLECS_API void ecs_os_fini(void)
Deinitialize the OS API.
ecs_os_perf_trace_pop_
void ecs_os_perf_trace_pop_(const char *file, size_t line, const char *name)
Pop a performance trace region.
ecs_os_strerror
FLECS_API const char * ecs_os_strerror(int err)
Convert errno to a string.
ecs_os_api_fclose_t
void(* ecs_os_api_fclose_t)(FILE *file)
OS API fclose function type.
Definition os_api.h:263
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:81
ecs_os_api_calloc_count
FLECS_API int64_t ecs_os_api_calloc_count
calloc count.
ecs_os_api_t
OS API interface.
Definition os_api.h:281
ecs_os_api_t::fopen_
ecs_os_api_fopen_t fopen_
fopen callback.
Definition os_api.h:354
ecs_os_api_t::cond_wait_
ecs_os_api_cond_wait_t cond_wait_
cond_wait callback.
Definition os_api.h:321
ecs_os_api_t::thread_new_
ecs_os_api_thread_new_t thread_new_
thread_new callback.
Definition os_api.h:296
ecs_os_api_t::free_
ecs_os_api_free_t free_
free callback.
Definition os_api.h:290
ecs_os_api_t::log_last_error_
int32_t log_last_error_
Last logged error code.
Definition os_api.h:363
ecs_os_api_t::sleep_
ecs_os_api_sleep_t sleep_
sleep callback.
Definition os_api.h:324
ecs_os_api_t::realloc_
ecs_os_api_realloc_t realloc_
realloc callback.
Definition os_api.h:288
ecs_os_api_t::mutex_unlock_
ecs_os_api_mutex_lock_t mutex_unlock_
mutex_unlock callback.
Definition os_api.h:314
ecs_os_api_t::abort_
ecs_os_api_abort_t abort_
abort callback.
Definition os_api.h:338
ecs_os_api_t::lainc_
ecs_os_api_lainc_t lainc_
lainc callback.
Definition os_api.h:307
ecs_os_api_t::init_
ecs_os_api_init_t init_
init callback.
Definition os_api.h:283
ecs_os_api_t::get_time_
ecs_os_api_get_time_t get_time_
get_time callback.
Definition os_api.h:326
ecs_os_api_t::cond_broadcast_
ecs_os_api_cond_broadcast_t cond_broadcast_
cond_broadcast callback.
Definition os_api.h:320
ecs_os_api_t::calloc_
ecs_os_api_calloc_t calloc_
calloc callback.
Definition os_api.h:289
ecs_os_api_t::dlopen_
ecs_os_api_dlopen_t dlopen_
dlopen callback.
Definition os_api.h:341
ecs_os_api_t::perf_trace_push_
ecs_os_api_perf_trace_t perf_trace_push_
perf_trace_push callback.
Definition os_api.h:358
ecs_os_api_t::thread_self_
ecs_os_api_thread_self_t thread_self_
thread_self callback.
Definition os_api.h:298
ecs_os_api_t::fclose_
ecs_os_api_fclose_t fclose_
fclose callback.
Definition os_api.h:355
ecs_os_api_t::thread_join_
ecs_os_api_thread_join_t thread_join_
thread_join callback.
Definition os_api.h:297
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:347
ecs_os_api_t::log_indent_
int32_t log_indent_
Tracing indentation level.
Definition os_api.h:362
ecs_os_api_t::malloc_
ecs_os_api_malloc_t malloc_
malloc callback.
Definition os_api.h:287
ecs_os_api_t::log_
ecs_os_api_log_t log_
log callback.
Definition os_api.h:329
ecs_os_api_t::task_join_
ecs_os_api_thread_join_t task_join_
task_join callback.
Definition os_api.h:302
ecs_os_api_t::log_last_timestamp_
int64_t log_last_timestamp_
Last logged timestamp.
Definition os_api.h:364
ecs_os_api_t::mutex_new_
ecs_os_api_mutex_new_t mutex_new_
mutex_new callback.
Definition os_api.h:311
ecs_os_api_t::ladec_
ecs_os_api_lainc_t ladec_
ladec callback.
Definition os_api.h:308
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:368
ecs_os_api_t::cond_new_
ecs_os_api_cond_new_t cond_new_
cond_new callback.
Definition os_api.h:317
ecs_os_api_t::perf_trace_pop_
ecs_os_api_perf_trace_t perf_trace_pop_
perf_trace_pop callback.
Definition os_api.h:359
ecs_os_api_t::task_new_
ecs_os_api_thread_new_t task_new_
task_new callback.
Definition os_api.h:301
ecs_os_api_t::log_level_
int32_t log_level_
Tracing level.
Definition os_api.h:361
ecs_os_api_t::fini_
ecs_os_api_fini_t fini_
fini callback.
Definition os_api.h:284
ecs_os_api_t::cond_signal_
ecs_os_api_cond_signal_t cond_signal_
cond_signal callback.
Definition os_api.h:319
ecs_os_api_t::cond_free_
ecs_os_api_cond_free_t cond_free_
cond_free callback.
Definition os_api.h:318
ecs_os_api_t::strdup_
ecs_os_api_strdup_t strdup_
strdup callback.
Definition os_api.h:293
ecs_os_api_t::mutex_free_
ecs_os_api_mutex_free_t mutex_free_
mutex_free callback.
Definition os_api.h:312
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:351
ecs_os_api_t::flags_
ecs_flags32_t flags_
OS API flags.
Definition os_api.h:366
ecs_os_api_t::now_
ecs_os_api_now_t now_
now callback.
Definition os_api.h:325
ecs_os_api_t::mutex_lock_
ecs_os_api_mutex_lock_t mutex_lock_
mutex_lock callback.
Definition os_api.h:313
ecs_os_api_t::ainc_
ecs_os_api_ainc_t ainc_
ainc callback.
Definition os_api.h:305
ecs_os_api_t::adec_
ecs_os_api_ainc_t adec_
adec callback.
Definition os_api.h:306
ecs_os_api_t::dlproc_
ecs_os_api_dlproc_t dlproc_
dlproc callback.
Definition os_api.h:342
ecs_os_api_t::dlclose_
ecs_os_api_dlclose_t dlclose_
dlclose callback.
Definition os_api.h:343
ecs_time_t
Time type.
Definition os_api.h:39
ecs_time_t::sec
uint32_t sec
Second part.
Definition os_api.h:40
ecs_time_t::nanosec
uint32_t nanosec
Nanosecond part.
Definition os_api.h:41