base_platform.h (2875B)
1 /* See LICENSE for license details. */ 2 #ifndef BASE_PLATFORM_H 3 #define BASE_PLATFORM_H 4 5 /* 6 * CONFIGURATION 7 * 8 * BASE_EXPORT 9 * the attributes for functions defined by the platfom layer. for example 10 * `#define BASE_EXPORT static` in a single translation unit build 11 * 12 * BASE_IMPORT 13 * the attributes to apply on the entry_point() called from main() 14 * 15 * BASE_PLATFORM_NO_MAIN: 16 * define if you do not want a main() function (useful for library code) 17 * 18 */ 19 20 #ifndef BASE_EXPORT 21 #define BASE_EXPORT 22 #endif 23 24 #ifndef BASE_IMPORT 25 #define BASE_IMPORT 26 #endif 27 28 #ifndef BASE_PLATFORM_NO_MAIN 29 #define BASE_PLATFORM_NO_MAIN 0 30 #else 31 #undef BASE_PLATFORM_NO_MAIN 32 #define BASE_PLATFORM_NO_MAIN 1 33 #endif 34 35 #include "base_types.h" 36 #include "base_intrinsics.h" 37 38 #define OSInvalidHandleValue ((u64)-1) 39 typedef struct { u64 value[1]; } OSBarrier; 40 typedef struct { u64 value[1]; } OSHandle; 41 typedef struct { u64 value[1]; } OSLibrary; 42 typedef struct { u64 value[1]; } OSThread; 43 typedef struct { u64 value[1]; } OSWindow; 44 typedef struct { u64 value[1]; } OSW32Semaphore; 45 46 typedef u64 os_thread_entry_point_fn(void *user_context); 47 48 typedef struct { 49 u64 timer_frequency; 50 51 u32 logical_processor_count; 52 u32 page_size; 53 54 u8 path_separator_byte; 55 } OSSystemInfo; 56 57 BASE_EXPORT OSSystemInfo * os_system_info(void); 58 59 BASE_EXPORT void no_return os_exit(i32 code); 60 61 BASE_EXPORT void * os_memory_reserve(u64 size); 62 BASE_EXPORT void os_memory_release(void *base, u64 size); 63 BASE_EXPORT u32 os_memory_commit(void *base, u64 size); 64 BASE_EXPORT void os_memory_uncommit(void *base, u64 size); 65 BASE_EXPORT void os_memory_seal(void *base, u64 size); 66 67 BASE_EXPORT u64 os_timer_count(void); 68 69 BASE_EXPORT str8 os_read_entire_file(Arena *arena, const char *file); 70 71 BASE_EXPORT OSThread os_create_thread(const char *name, void *user_context, os_thread_entry_point_fn *fn); 72 BASE_EXPORT OSBarrier os_barrier_alloc(u32 thread_count); 73 BASE_EXPORT void os_barrier_enter(OSBarrier); 74 75 /* NOTE(rnp): memory watch timed waiting functions. (-1) is an infinite timeout. 76 * Used with the intention of yielding the thread back to the OS. */ 77 BASE_EXPORT u32 os_wait_on_address(i32 *lock, i32 current, u32 timeout_ms); 78 BASE_EXPORT void os_wake_all_waiters(i32 *lock); 79 80 /* NOTE(rnp): this functionality is only needed on win32 to provide cross process 81 * synchronization. While posix has equivalent functionality there is no reason to 82 * use it over a value located in shared memory. */ 83 #if OS_WINDOWS 84 BASE_EXPORT OSW32Semaphore os_w32_create_semaphore(const char *name, i32 initial_count, i32 maximum_count); 85 BASE_EXPORT u32 os_w32_semaphore_wait(OSW32Semaphore, u32 timeout_ms); 86 BASE_EXPORT void os_w32_semaphore_release(OSW32Semaphore, i32 count); 87 #endif 88 89 #endif /* BASE_PLATFORM_H */