base_platform.h (2194B)
1 /* See LICENSE for license details. */ 2 #ifndef BASE_PLATFORM_H 3 #define BASE_PLATFORM_H 4 5 #ifndef BASE_EXPORT 6 #define BASE_EXPORT 7 #endif 8 9 #ifndef BASE_IMPORT 10 #define BASE_IMPORT 11 #endif 12 13 #ifndef BASE_PLATFORM_NO_MAIN 14 #define BASE_PLATFORM_NO_MAIN 0 15 #endif 16 17 #include "base_types.h" 18 #include "base_intrinsics.h" 19 20 #define OSInvalidHandleValue ((u64)-1) 21 typedef struct { u64 value[1]; } OSBarrier; 22 typedef struct { u64 value[1]; } OSHandle; 23 typedef struct { u64 value[1]; } OSLibrary; 24 typedef struct { u64 value[1]; } OSThread; 25 typedef struct { u64 value[1]; } OSWindow; 26 typedef struct { u64 value[1]; } OSW32Semaphore; 27 28 typedef u64 os_thread_entry_point_fn(void *user_context); 29 30 typedef struct { 31 u64 timer_frequency; 32 33 u32 logical_processor_count; 34 u32 page_size; 35 36 u8 path_separator_byte; 37 } OSSystemInfo; 38 39 BASE_EXPORT OSSystemInfo * os_system_info(void); 40 41 BASE_EXPORT void no_return os_exit(i32 code); 42 43 BASE_EXPORT void * os_memory_reserve(u64 size); 44 BASE_EXPORT void os_memory_release(void *base, u64 size); 45 BASE_EXPORT u32 os_memory_commit(void *base, u64 size); 46 BASE_EXPORT void os_memory_uncommit(void *base, u64 size); 47 BASE_EXPORT void os_memory_seal(void *base, u64 size); 48 49 BASE_EXPORT u64 os_timer_count(void); 50 51 BASE_EXPORT str8 os_read_entire_file(Arena *arena, const char *file); 52 53 /* NOTE(rnp): memory watch timed waiting functions. (-1) is an infinite timeout. 54 * Used with the intention of yielding the thread back to the OS. */ 55 BASE_EXPORT u32 os_wait_on_address(i32 *lock, i32 current, u32 timeout_ms); 56 BASE_EXPORT void os_wake_all_waiters(i32 *lock); 57 58 59 /* NOTE(rnp): this functionality is only needed on win32 to provide cross process 60 * synchronization. While posix has equivalent functionality there is no reason to 61 * use it over a value located in shared memory. */ 62 #if OS_WINDOWS 63 BASE_EXPORT OSW32Semaphore os_w32_create_semaphore(const char *name, i32 initial_count, i32 maximum_count); 64 BASE_EXPORT u32 os_w32_semaphore_wait(OSW32Semaphore, u32 timeout_ms); 65 BASE_EXPORT void os_w32_semaphore_release(OSW32Semaphore, i32 count); 66 #endif 67 68 #endif /* BASE_PLATFORM_H */