mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-13 07:32:23 -07:00
define synchronization primitive interface in base layer, implement using os layer; convert all usage -> base layer; use base sync primitives in lane tctx info
This commit is contained in:
+13
-13
@@ -18,11 +18,11 @@ async_init(CmdLine *cmdline)
|
||||
ASYNC_Ring *ring = &async_shared->rings[p];
|
||||
ring->ring_size = MB(8);
|
||||
ring->ring_base = push_array_no_zero(arena, U8, ring->ring_size);
|
||||
ring->ring_mutex = os_mutex_alloc();
|
||||
ring->ring_cv = os_condition_variable_alloc();
|
||||
ring->ring_mutex = mutex_alloc();
|
||||
ring->ring_cv = cond_var_alloc();
|
||||
}
|
||||
async_shared->ring_mutex = os_mutex_alloc();
|
||||
async_shared->ring_cv = os_condition_variable_alloc();
|
||||
async_shared->ring_mutex = mutex_alloc();
|
||||
async_shared->ring_cv = cond_var_alloc();
|
||||
String8 work_thread_count_string = cmd_line_string(cmdline, str8_lit("work_threads_count"));
|
||||
if(work_thread_count_string.size == 0 || !try_u64_from_str8_c_rules(work_thread_count_string, &async_shared->work_threads_count))
|
||||
{
|
||||
@@ -81,7 +81,7 @@ async_push_work_(ASYNC_WorkFunctionType *work_function, ASYNC_WorkParams *params
|
||||
if(available_size >= sizeof(work))
|
||||
{
|
||||
queued_in_ring_buffer = 1;
|
||||
if(!os_handle_match(params->semaphore, os_handle_zero()))
|
||||
if(!MemoryIsZeroStruct(¶ms->semaphore))
|
||||
{
|
||||
os_semaphore_take(params->semaphore, max_U64);
|
||||
}
|
||||
@@ -92,14 +92,14 @@ async_push_work_(ASYNC_WorkFunctionType *work_function, ASYNC_WorkParams *params
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(ring->ring_cv, ring->ring_mutex, params->endt_us);
|
||||
cond_var_wait(ring->ring_cv, ring->ring_mutex, params->endt_us);
|
||||
}
|
||||
|
||||
// rjf: broadcast ring buffer cv if we wrote successfully
|
||||
if(queued_in_ring_buffer)
|
||||
{
|
||||
os_condition_variable_broadcast(ring->ring_cv);
|
||||
os_condition_variable_broadcast(async_shared->ring_cv);
|
||||
cond_var_broadcast(ring->ring_cv);
|
||||
cond_var_broadcast(async_shared->ring_cv);
|
||||
}
|
||||
|
||||
// rjf: if we did not queue successfully, and we have determined that
|
||||
@@ -148,7 +148,7 @@ internal void *
|
||||
async_task_join(ASYNC_Task *task)
|
||||
{
|
||||
void *result = 0;
|
||||
if(task != 0 && !os_handle_match(task->semaphore, os_handle_zero()))
|
||||
if(task != 0 && !MemoryIsZeroStruct(&task->semaphore))
|
||||
{
|
||||
os_semaphore_take(task->semaphore, max_U64);
|
||||
os_semaphore_release(task->semaphore);
|
||||
@@ -193,11 +193,11 @@ async_pop_work(void)
|
||||
}
|
||||
if(!done)
|
||||
{
|
||||
os_condition_variable_wait(async_shared->ring_cv, async_shared->ring_mutex, max_U64);
|
||||
cond_var_wait(async_shared->ring_cv, async_shared->ring_mutex, max_U64);
|
||||
}
|
||||
}
|
||||
os_condition_variable_broadcast(async_shared->ring_cv);
|
||||
os_condition_variable_broadcast(async_shared->rings[taken_priority].ring_cv);
|
||||
cond_var_broadcast(async_shared->ring_cv);
|
||||
cond_var_broadcast(async_shared->rings[taken_priority].ring_cv);
|
||||
return work;
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ async_execute_work(ASYNC_Work work)
|
||||
}
|
||||
|
||||
//- rjf: release semaphore
|
||||
if(!os_handle_match(work.semaphore, os_handle_zero()))
|
||||
if(!MemoryIsZeroStruct(&work.semaphore))
|
||||
{
|
||||
os_semaphore_drop(work.semaphore);
|
||||
}
|
||||
|
||||
+7
-7
@@ -27,7 +27,7 @@ struct ASYNC_WorkParams
|
||||
{
|
||||
void *input;
|
||||
void **output;
|
||||
OS_Handle semaphore;
|
||||
Semaphore semaphore;
|
||||
U64 *completion_counter;
|
||||
U64 *working_counter;
|
||||
U64 endt_us;
|
||||
@@ -40,7 +40,7 @@ struct ASYNC_Work
|
||||
ASYNC_WorkFunctionType *work_function;
|
||||
void *input;
|
||||
void **output;
|
||||
OS_Handle semaphore;
|
||||
Semaphore semaphore;
|
||||
U64 *completion_counter;
|
||||
U64 *working_counter;
|
||||
};
|
||||
@@ -51,7 +51,7 @@ struct ASYNC_Work
|
||||
typedef struct ASYNC_Task ASYNC_Task;
|
||||
struct ASYNC_Task
|
||||
{
|
||||
OS_Handle semaphore;
|
||||
Semaphore semaphore;
|
||||
void *output;
|
||||
};
|
||||
|
||||
@@ -89,8 +89,8 @@ struct ASYNC_Ring
|
||||
U8 *ring_base;
|
||||
U64 ring_write_pos;
|
||||
U64 ring_read_pos;
|
||||
OS_Handle ring_mutex;
|
||||
OS_Handle ring_cv;
|
||||
Mutex ring_mutex;
|
||||
CondVar ring_cv;
|
||||
};
|
||||
|
||||
typedef struct ASYNC_Shared ASYNC_Shared;
|
||||
@@ -100,8 +100,8 @@ struct ASYNC_Shared
|
||||
|
||||
// rjf: user -> work thread ring buffers
|
||||
ASYNC_Ring rings[ASYNC_Priority_COUNT];
|
||||
OS_Handle ring_mutex;
|
||||
OS_Handle ring_cv;
|
||||
Mutex ring_mutex;
|
||||
CondVar ring_cv;
|
||||
|
||||
// rjf: work threads
|
||||
OS_Handle *work_threads;
|
||||
|
||||
@@ -5,13 +5,10 @@
|
||||
#define BASE_ARENA_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Constants
|
||||
//~ rjf: Arena Types
|
||||
|
||||
#define ARENA_HEADER_SIZE 128
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Types
|
||||
|
||||
typedef U64 ArenaFlags;
|
||||
enum
|
||||
{
|
||||
@@ -59,15 +56,12 @@ struct Temp
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Global Defaults
|
||||
//~ rjf: Arena Functions
|
||||
|
||||
global U64 arena_default_reserve_size = MB(64);
|
||||
global U64 arena_default_commit_size = KB(64);
|
||||
global ArenaFlags arena_default_flags = 0;
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Arena Functions
|
||||
|
||||
//- rjf: arena creation/destruction
|
||||
internal Arena *arena_alloc_(ArenaParams *params);
|
||||
#define arena_alloc(...) arena_alloc_(&(ArenaParams){.reserve_size = arena_default_reserve_size, .commit_size = arena_default_commit_size, .flags = arena_default_flags, .allocation_site_file = __FILE__, .allocation_site_line = __LINE__, __VA_ARGS__})
|
||||
|
||||
@@ -104,7 +104,7 @@ cmd_line_from_string_list(Arena *arena, String8List command_line)
|
||||
{
|
||||
option_name = str8_skip(option_name, 1);
|
||||
}
|
||||
else if(operating_system_from_context() == OperatingSystem_Windows &&
|
||||
else if(OperatingSystem_CURRENT == OperatingSystem_Windows &&
|
||||
str8_match(str8_prefix(node->string, 1), str8_lit("/"), 0))
|
||||
{
|
||||
option_name = str8_skip(option_name, 1);
|
||||
|
||||
+66
-47
@@ -246,7 +246,8 @@ sign_from_side_F32(Side side){
|
||||
//~ rjf: Memory Functions
|
||||
|
||||
internal B32
|
||||
memory_is_zero(void *ptr, U64 size){
|
||||
memory_is_zero(void *ptr, U64 size)
|
||||
{
|
||||
B32 result = 1;
|
||||
|
||||
// break down size
|
||||
@@ -257,8 +258,10 @@ memory_is_zero(void *ptr, U64 size){
|
||||
U64 *p64 = (U64*)ptr;
|
||||
if(result)
|
||||
{
|
||||
for (U64 i = 0; i < count8; i += 1, p64 += 1){
|
||||
if (*p64 != 0){
|
||||
for(U64 i = 0; i < count8; i += 1, p64 += 1)
|
||||
{
|
||||
if(*p64 != 0)
|
||||
{
|
||||
result = 0;
|
||||
goto done;
|
||||
}
|
||||
@@ -269,8 +272,10 @@ memory_is_zero(void *ptr, U64 size){
|
||||
if(result)
|
||||
{
|
||||
U8 *p8 = (U8*)p64;
|
||||
for (U64 i = 0; i < extra; i += 1, p8 += 1){
|
||||
if (*p8 != 0){
|
||||
for(U64 i = 0; i < extra; i += 1, p8 += 1)
|
||||
{
|
||||
if(*p8 != 0)
|
||||
{
|
||||
result = 0;
|
||||
goto done;
|
||||
}
|
||||
@@ -278,7 +283,7 @@ memory_is_zero(void *ptr, U64 size){
|
||||
}
|
||||
|
||||
done:;
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -409,47 +414,6 @@ max_instruction_size_from_arch(Arch arch)
|
||||
return 64;
|
||||
}
|
||||
|
||||
internal OperatingSystem
|
||||
operating_system_from_context(void){
|
||||
OperatingSystem os = OperatingSystem_Null;
|
||||
#if OS_WINDOWS
|
||||
os = OperatingSystem_Windows;
|
||||
#elif OS_LINUX
|
||||
os = OperatingSystem_Linux;
|
||||
#elif OS_MAC
|
||||
os = OperatingSystem_Mac;
|
||||
#endif
|
||||
return os;
|
||||
}
|
||||
|
||||
internal Arch
|
||||
arch_from_context(void){
|
||||
Arch arch = Arch_Null;
|
||||
#if ARCH_X64
|
||||
arch = Arch_x64;
|
||||
#elif ARCH_X86
|
||||
arch = Arch_x86;
|
||||
#elif ARCH_ARM64
|
||||
arch = Arch_arm64;
|
||||
#elif ARCH_ARM32
|
||||
arch = Arch_arm32;
|
||||
#endif
|
||||
return arch;
|
||||
}
|
||||
|
||||
internal Compiler
|
||||
compiler_from_context(void){
|
||||
Compiler compiler = Compiler_Null;
|
||||
#if COMPILER_MSVC
|
||||
compiler = Compiler_msvc;
|
||||
#elif COMPILER_GCC
|
||||
compiler = Compiler_gcc;
|
||||
#elif COMPILER_CLANG
|
||||
compiler = Compiler_clang;
|
||||
#endif
|
||||
return compiler;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Time Functions
|
||||
|
||||
@@ -659,3 +623,58 @@ index_of_zero_u64(U64 *ptr, U64 count)
|
||||
}
|
||||
return max_U64;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Third Party Includes
|
||||
|
||||
#define STB_SPRINTF_DECORATE(name) raddbg_##name
|
||||
#include "third_party/stb/stb_sprintf.h"
|
||||
|
||||
#if !BUILD_SUPPLEMENTARY_UNIT
|
||||
# define STB_SPRINTF_IMPLEMENTATION
|
||||
# define STB_SPRINTF_STATIC
|
||||
# include "third_party/stb/stb_sprintf.h"
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String <-> Integer Tables
|
||||
|
||||
read_only global U8 integer_symbols[16] =
|
||||
{
|
||||
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',
|
||||
};
|
||||
|
||||
// NOTE(rjf): Includes reverses for uppercase and lowercase hex.
|
||||
read_only global U8 integer_symbol_reverse[128] =
|
||||
{
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
};
|
||||
|
||||
read_only global U8 base64[64] =
|
||||
{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'_', '$',
|
||||
};
|
||||
|
||||
read_only global U8 base64_reverse[128] =
|
||||
{
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
|
||||
0xFF,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,
|
||||
0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0xFF,0xFF,0xFF,0xFF,0x3E,
|
||||
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,
|
||||
0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
};
|
||||
|
||||
+66
-36
@@ -160,6 +160,8 @@
|
||||
#define MemoryMatchStruct(a,b) MemoryMatch((a),(b),sizeof(*(a)))
|
||||
#define MemoryMatchArray(a,b) MemoryMatch((a),(b),sizeof(a))
|
||||
|
||||
#define MemoryIsZeroStruct(ptr) memory_is_zero((ptr), sizeof(*(ptr)))
|
||||
|
||||
#define MemoryRead(T,p,e) ( ((p)+sizeof(T)<=(e))?(*(T*)(p)):(0) )
|
||||
#define MemoryConsume(T,p,e) ( ((p)+sizeof(T)<=(e))?((p)+=sizeof(T),*(T*)((p)-sizeof(T))):((p)=(e),0) )
|
||||
|
||||
@@ -420,6 +422,37 @@ union U512
|
||||
U256 u256[2];
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Type Structures
|
||||
|
||||
typedef struct U16Array U16Array;
|
||||
struct U16Array
|
||||
{
|
||||
U64 count;
|
||||
U16 *v;
|
||||
};
|
||||
|
||||
typedef struct U32Array U32Array;
|
||||
struct U32Array
|
||||
{
|
||||
U64 count;
|
||||
U32 *v;
|
||||
};
|
||||
|
||||
typedef struct U64Array U64Array;
|
||||
struct U64Array
|
||||
{
|
||||
U64 count;
|
||||
U64 *v;
|
||||
};
|
||||
|
||||
typedef struct U128Array U128Array;
|
||||
struct U128Array
|
||||
{
|
||||
U64 count;
|
||||
U128 *v;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Types & Spaces
|
||||
|
||||
@@ -486,6 +519,15 @@ typedef enum OperatingSystem
|
||||
OperatingSystem_Linux,
|
||||
OperatingSystem_Mac,
|
||||
OperatingSystem_COUNT,
|
||||
#if OS_WINDOWS
|
||||
OperatingSystem_CURRENT = OperatingSystem_Windows,
|
||||
#elif OS_LINUX
|
||||
OperatingSystem_CURRENT = OperatingSystem_Linux,
|
||||
#elif OS_MAC
|
||||
OperatingSystem_CURRENT = OperatingSystem_Mac,
|
||||
#else
|
||||
OperatingSystem_CURRENT = OperatingSystem_Null,
|
||||
#endif
|
||||
}
|
||||
OperatingSystem;
|
||||
|
||||
@@ -508,6 +550,17 @@ typedef enum Arch
|
||||
Arch_arm64,
|
||||
Arch_arm32,
|
||||
Arch_COUNT,
|
||||
#if ARCH_X64
|
||||
Arch_CURRENT = Arch_x64,
|
||||
#elif ARCH_X86
|
||||
Arch_CURRENT = Arch_x86,
|
||||
#elif ARCH_ARM64
|
||||
Arch_CURRENT = Arch_arm64,
|
||||
#elif ARCH_ARM32
|
||||
Arch_CURRENT = Arch_arm32,
|
||||
#else
|
||||
Arch_CURRENT = Arch_Null,
|
||||
#endif
|
||||
}
|
||||
Arch;
|
||||
|
||||
@@ -518,6 +571,15 @@ typedef enum Compiler
|
||||
Compiler_gcc,
|
||||
Compiler_clang,
|
||||
Compiler_COUNT,
|
||||
#if COMPILER_MSVC
|
||||
Compiler_CURRENT = Compiler_msvc,
|
||||
#elif COMPILER_GCC
|
||||
Compiler_CURRENT = Compiler_gcc,
|
||||
#elif COMPILER_CLANG
|
||||
Compiler_CURRENT = Compiler_clang,
|
||||
#else
|
||||
Compiler_CURRENT = Compiler_Null,
|
||||
#endif
|
||||
}
|
||||
Compiler;
|
||||
|
||||
@@ -539,7 +601,7 @@ struct TxtRng
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Globally Unique Ids
|
||||
//~ rjf: Globally Unique Ids
|
||||
|
||||
typedef union Guid Guid;
|
||||
union Guid
|
||||
@@ -556,35 +618,7 @@ union Guid
|
||||
StaticAssert(sizeof(Guid) == 16, g_guid_size_check);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Arrays
|
||||
|
||||
typedef struct U16Array U16Array;
|
||||
struct U16Array
|
||||
{
|
||||
U64 count;
|
||||
U16 *v;
|
||||
};
|
||||
typedef struct U32Array U32Array;
|
||||
struct U32Array
|
||||
{
|
||||
U64 count;
|
||||
U32 *v;
|
||||
};
|
||||
typedef struct U64Array U64Array;
|
||||
struct U64Array
|
||||
{
|
||||
U64 count;
|
||||
U64 *v;
|
||||
};
|
||||
typedef struct U128Array U128Array;
|
||||
struct U128Array
|
||||
{
|
||||
U64 count;
|
||||
U128 *v;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ NOTE(allen): Constants
|
||||
//~ rjf: Basic Constants
|
||||
|
||||
global U32 sign32 = 0x80000000;
|
||||
global U32 exponent32 = 0x7F800000;
|
||||
@@ -745,7 +779,7 @@ global const U64 bit63 = (1ull<<62);
|
||||
global const U64 bit64 = (1ull<<63);
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: Time
|
||||
//~ rjf: Time Types
|
||||
|
||||
typedef enum WeekDay
|
||||
{
|
||||
@@ -803,7 +837,7 @@ struct DateTime
|
||||
typedef U64 DenseTime;
|
||||
|
||||
////////////////////////////////
|
||||
//~ allen: Files
|
||||
//~ rjf: File Types
|
||||
|
||||
typedef U32 FilePropertyFlags;
|
||||
enum
|
||||
@@ -897,10 +931,6 @@ internal B32 txt_rng_contains(TxtRng r, TxtPt pt);
|
||||
internal U64 bit_size_from_arch(Arch arch);
|
||||
internal U64 max_instruction_size_from_arch(Arch arch);
|
||||
|
||||
internal OperatingSystem operating_system_from_context(void);
|
||||
internal Arch arch_from_context(void);
|
||||
internal Compiler compiler_from_context(void);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Time Functions
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "base_arena.c"
|
||||
#include "base_math.c"
|
||||
#include "base_strings.c"
|
||||
#include "base_sync.c"
|
||||
#include "base_thread_context.c"
|
||||
#include "base_command_line.c"
|
||||
#include "base_markup.c"
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "base_arena.h"
|
||||
#include "base_math.h"
|
||||
#include "base_strings.h"
|
||||
#include "base_sync.h"
|
||||
#include "base_thread_context.h"
|
||||
#include "base_command_line.h"
|
||||
#include "base_markup.h"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Scalar Ops
|
||||
//~ rjf: Scalar Math Ops
|
||||
|
||||
internal F32
|
||||
mix_1f32(F32 a, F32 b, F32 t)
|
||||
@@ -809,4 +809,3 @@ rng1s64_array_from_list(Arena *arena, Rng1S64List *list)
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
+694
-694
File diff suppressed because it is too large
Load Diff
+117
-128
@@ -1,215 +1,196 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Third Party Includes
|
||||
|
||||
#if !BUILD_SUPPLEMENTARY_UNIT
|
||||
# define STB_SPRINTF_IMPLEMENTATION
|
||||
# define STB_SPRINTF_STATIC
|
||||
# include "third_party/stb/stb_sprintf.h"
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ NOTE(allen): String <-> Integer Tables
|
||||
|
||||
read_only global U8 integer_symbols[16] = {
|
||||
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',
|
||||
};
|
||||
|
||||
// NOTE(allen): Includes reverses for uppercase and lowercase hex.
|
||||
read_only global U8 integer_symbol_reverse[128] = {
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
};
|
||||
|
||||
read_only global U8 base64[64] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'_', '$',
|
||||
};
|
||||
|
||||
read_only global U8 base64_reverse[128] = {
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
|
||||
0xFF,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,
|
||||
0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0xFF,0xFF,0xFF,0xFF,0x3E,
|
||||
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,
|
||||
0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Character Classification & Conversion Functions
|
||||
|
||||
internal B32
|
||||
char_is_space(U8 c){
|
||||
return(c == ' ' || c == '\n' || c == '\t' || c == '\r' || c == '\f' || c == '\v');
|
||||
char_is_space(U8 c)
|
||||
{
|
||||
return (c == ' ' || c == '\n' || c == '\t' || c == '\r' || c == '\f' || c == '\v');
|
||||
}
|
||||
|
||||
internal B32
|
||||
char_is_upper(U8 c){
|
||||
return('A' <= c && c <= 'Z');
|
||||
char_is_upper(U8 c)
|
||||
{
|
||||
return ('A' <= c && c <= 'Z');
|
||||
}
|
||||
|
||||
internal B32
|
||||
char_is_lower(U8 c){
|
||||
return('a' <= c && c <= 'z');
|
||||
char_is_lower(U8 c)
|
||||
{
|
||||
return ('a' <= c && c <= 'z');
|
||||
}
|
||||
|
||||
internal B32
|
||||
char_is_alpha(U8 c){
|
||||
return(char_is_upper(c) || char_is_lower(c));
|
||||
char_is_alpha(U8 c)
|
||||
{
|
||||
return (char_is_upper(c) || char_is_lower(c));
|
||||
}
|
||||
|
||||
internal B32
|
||||
char_is_slash(U8 c){
|
||||
return(c == '/' || c == '\\');
|
||||
char_is_slash(U8 c)
|
||||
{
|
||||
return (c == '/' || c == '\\');
|
||||
}
|
||||
|
||||
internal B32
|
||||
char_is_digit(U8 c, U32 base){
|
||||
char_is_digit(U8 c, U32 base)
|
||||
{
|
||||
B32 result = 0;
|
||||
if (0 < base && base <= 16){
|
||||
if(0 < base && base <= 16)
|
||||
{
|
||||
U8 val = integer_symbol_reverse[c];
|
||||
if (val < base){
|
||||
if(val < base)
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal U8
|
||||
char_to_lower(U8 c){
|
||||
if (char_is_upper(c)){
|
||||
char_to_lower(U8 c)
|
||||
{
|
||||
if(char_is_upper(c))
|
||||
{
|
||||
c += ('a' - 'A');
|
||||
}
|
||||
return(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
internal U8
|
||||
char_to_upper(U8 c){
|
||||
if (char_is_lower(c)){
|
||||
char_to_upper(U8 c)
|
||||
{
|
||||
if(char_is_lower(c))
|
||||
{
|
||||
c += ('A' - 'a');
|
||||
}
|
||||
return(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
internal U8
|
||||
char_to_correct_slash(U8 c){
|
||||
if(char_is_slash(c)){
|
||||
char_to_correct_slash(U8 c)
|
||||
{
|
||||
if(char_is_slash(c))
|
||||
{
|
||||
c = '/';
|
||||
}
|
||||
return(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: C-String Measurement
|
||||
|
||||
internal U64
|
||||
cstring8_length(U8 *c){
|
||||
cstring8_length(U8 *c)
|
||||
{
|
||||
U8 *p = c;
|
||||
for (;*p != 0; p += 1);
|
||||
return(p - c);
|
||||
return (p - c);
|
||||
}
|
||||
|
||||
internal U64
|
||||
cstring16_length(U16 *c){
|
||||
cstring16_length(U16 *c)
|
||||
{
|
||||
U16 *p = c;
|
||||
for (;*p != 0; p += 1);
|
||||
return(p - c);
|
||||
return (p - c);
|
||||
}
|
||||
|
||||
internal U64
|
||||
cstring32_length(U32 *c){
|
||||
cstring32_length(U32 *c)
|
||||
{
|
||||
U32 *p = c;
|
||||
for (;*p != 0; p += 1);
|
||||
return(p - c);
|
||||
return (p - c);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String Constructors
|
||||
|
||||
internal String8
|
||||
str8(U8 *str, U64 size){
|
||||
str8(U8 *str, U64 size)
|
||||
{
|
||||
String8 result = {str, size};
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_range(U8 *first, U8 *one_past_last){
|
||||
str8_range(U8 *first, U8 *one_past_last)
|
||||
{
|
||||
String8 result = {first, (U64)(one_past_last - first)};
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_zero(void){
|
||||
str8_zero(void)
|
||||
{
|
||||
String8 result = {0};
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String16
|
||||
str16(U16 *str, U64 size){
|
||||
str16(U16 *str, U64 size)
|
||||
{
|
||||
String16 result = {str, size};
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String16
|
||||
str16_range(U16 *first, U16 *one_past_last){
|
||||
str16_range(U16 *first, U16 *one_past_last)
|
||||
{
|
||||
String16 result = {first, (U64)(one_past_last - first)};
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String16
|
||||
str16_zero(void){
|
||||
str16_zero(void)
|
||||
{
|
||||
String16 result = {0};
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String32
|
||||
str32(U32 *str, U64 size){
|
||||
str32(U32 *str, U64 size)
|
||||
{
|
||||
String32 result = {str, size};
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String32
|
||||
str32_range(U32 *first, U32 *one_past_last){
|
||||
str32_range(U32 *first, U32 *one_past_last)
|
||||
{
|
||||
String32 result = {first, (U64)(one_past_last - first)};
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String32
|
||||
str32_zero(void){
|
||||
str32_zero(void)
|
||||
{
|
||||
String32 result = {0};
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_cstring(char *c){
|
||||
str8_cstring(char *c)
|
||||
{
|
||||
String8 result = {(U8*)c, cstring8_length((U8*)c)};
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String16
|
||||
str16_cstring(U16 *c){
|
||||
str16_cstring(U16 *c)
|
||||
{
|
||||
String16 result = {(U16*)c, cstring16_length((U16*)c)};
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String32
|
||||
str32_cstring(U32 *c){
|
||||
str32_cstring(U32 *c)
|
||||
{
|
||||
String32 result = {(U32*)c, cstring32_length((U32*)c)};
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
@@ -242,7 +223,6 @@ str8_cstring_capped_reverse(void *raw_start, void *raw_cap)
|
||||
for(; ptr > start; )
|
||||
{
|
||||
ptr -= 1;
|
||||
|
||||
if (*ptr == '\0')
|
||||
{
|
||||
break;
|
||||
@@ -331,35 +311,43 @@ str8_match(String8 a, String8 b, StringMatchFlags flags)
|
||||
}
|
||||
|
||||
internal U64
|
||||
str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags){
|
||||
str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags)
|
||||
{
|
||||
U8 *p = string.str + start_pos;
|
||||
U64 stop_offset = Max(string.size + 1, needle.size) - needle.size;
|
||||
U8 *stop_p = string.str + stop_offset;
|
||||
if (needle.size > 0){
|
||||
if(needle.size > 0)
|
||||
{
|
||||
U8 *string_opl = string.str + string.size;
|
||||
String8 needle_tail = str8_skip(needle, 1);
|
||||
StringMatchFlags adjusted_flags = flags | StringMatchFlag_RightSideSloppy;
|
||||
U8 needle_first_char_adjusted = needle.str[0];
|
||||
if(adjusted_flags & StringMatchFlag_CaseInsensitive){
|
||||
if(adjusted_flags & StringMatchFlag_CaseInsensitive)
|
||||
{
|
||||
needle_first_char_adjusted = char_to_upper(needle_first_char_adjusted);
|
||||
}
|
||||
for (;p < stop_p; p += 1){
|
||||
for(;p < stop_p; p += 1)
|
||||
{
|
||||
U8 haystack_char_adjusted = *p;
|
||||
if(adjusted_flags & StringMatchFlag_CaseInsensitive){
|
||||
if(adjusted_flags & StringMatchFlag_CaseInsensitive)
|
||||
{
|
||||
haystack_char_adjusted = char_to_upper(haystack_char_adjusted);
|
||||
}
|
||||
if (haystack_char_adjusted == needle_first_char_adjusted){
|
||||
if (str8_match(str8_range(p + 1, string_opl), needle_tail, adjusted_flags)){
|
||||
if(haystack_char_adjusted == needle_first_char_adjusted)
|
||||
{
|
||||
if(str8_match(str8_range(p + 1, string_opl), needle_tail, adjusted_flags))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
U64 result = string.size;
|
||||
if (p < stop_p){
|
||||
if(p < stop_p)
|
||||
{
|
||||
result = (U64)(p - string.str);
|
||||
}
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal U64
|
||||
@@ -578,7 +566,7 @@ str8_is_integer(String8 string, U32 radix){
|
||||
}
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal U64
|
||||
@@ -1046,7 +1034,7 @@ str8_list_pushf(Arena *arena, String8List *list, char *fmt, ...){
|
||||
String8 string = push_str8fv(arena, fmt, args);
|
||||
String8Node *result = str8_list_push(arena, list, string);
|
||||
va_end(args);
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8Node*
|
||||
@@ -1056,7 +1044,7 @@ str8_list_push_frontf(Arena *arena, String8List *list, char *fmt, ...){
|
||||
String8 string = push_str8fv(arena, fmt, args);
|
||||
String8Node *result = str8_list_push_front(arena, list, string);
|
||||
va_end(args);
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8List
|
||||
@@ -1069,7 +1057,7 @@ str8_list_copy(Arena *arena, String8List *list){
|
||||
String8 new_string = push_str8_copy(arena, node->string);
|
||||
str8_list_push_node_set_string(&result, new_node, new_string);
|
||||
}
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8List
|
||||
@@ -1155,7 +1143,7 @@ str8_list_join(Arena *arena, String8List *list, StringJoin *optional_params){
|
||||
|
||||
*ptr = 0;
|
||||
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void
|
||||
@@ -1568,7 +1556,7 @@ path_relative_dst_from_absolute_dst_src(Arena *arena, String8 dst, String8 src)
|
||||
src_n != 0 && bp_n != 0;
|
||||
src_n = src_n->next, bp_n = bp_n->next)
|
||||
{
|
||||
if(str8_match(src_n->string, bp_n->string, path_match_flags_from_os(operating_system_from_context())))
|
||||
if(str8_match(src_n->string, bp_n->string, path_match_flags_from_os(OperatingSystem_CURRENT)))
|
||||
{
|
||||
num_backtracks -= 1;
|
||||
}
|
||||
@@ -1602,7 +1590,7 @@ path_relative_dst_from_absolute_dst_src(Arena *arena, String8 dst, String8 src)
|
||||
bp_n != 0;
|
||||
bp_n = bp_n->next)
|
||||
{
|
||||
if(!unique_from_src && (src_n == 0 || !str8_match(src_n->string, bp_n->string, path_match_flags_from_os(operating_system_from_context()))))
|
||||
if(!unique_from_src && (src_n == 0 || !str8_match(src_n->string, bp_n->string, path_match_flags_from_os(OperatingSystem_CURRENT))))
|
||||
{
|
||||
unique_from_src = 1;
|
||||
}
|
||||
@@ -1833,7 +1821,7 @@ utf8_decode(U8 *str, U64 max){
|
||||
}
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal UnicodeDecode
|
||||
@@ -1845,7 +1833,7 @@ utf16_decode(U16 *str, U64 max){
|
||||
result.codepoint = ((str[0] - 0xD800) << 10) | ((str[1] - 0xDC00) + 0x10000);
|
||||
result.inc = 2;
|
||||
}
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal U32
|
||||
@@ -2045,7 +2033,7 @@ string_from_dimension(Dimension dimension){
|
||||
if ((U32)dimension < 4){
|
||||
result = strings[dimension];
|
||||
}
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
@@ -2058,7 +2046,7 @@ string_from_side(Side side){
|
||||
if ((U32)side < 2){
|
||||
result = strings[side];
|
||||
}
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
@@ -2085,7 +2073,7 @@ string_from_arch(Arch arch){
|
||||
if (arch < Arch_COUNT){
|
||||
result = strings[arch];
|
||||
}
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -2106,7 +2094,7 @@ string_from_week_day(WeekDay week_day){
|
||||
if ((U32)week_day < WeekDay_COUNT){
|
||||
result = strings[week_day];
|
||||
}
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
@@ -2129,7 +2117,7 @@ string_from_month(Month month){
|
||||
if ((U32)month < Month_COUNT){
|
||||
result = strings[month];
|
||||
}
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
@@ -2146,7 +2134,7 @@ push_date_time_string(Arena *arena, DateTime *date_time){
|
||||
String8 result = push_str8f(arena, "%d %s %d, %02d:%02d:%02d %s",
|
||||
date_time->day, mon_str, date_time->year,
|
||||
adjusted_hour, date_time->min, date_time->sec, ampm);
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
@@ -2155,7 +2143,7 @@ push_file_name_date_time_string(Arena *arena, DateTime *date_time){
|
||||
String8 result = push_str8f(arena, "%d-%s-%0d--%02d-%02d-%02d",
|
||||
date_time->year, mon_str, date_time->day,
|
||||
date_time->hour, date_time->min, date_time->sec);
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
@@ -2176,7 +2164,7 @@ string_from_elapsed_time(Arena *arena, DateTime dt){
|
||||
StringJoin join = { str8_lit_comp(""), str8_lit_comp(" "), str8_lit_comp("") };
|
||||
String8 result = str8_list_join(arena, &list, &join);
|
||||
scratch_end(scratch);
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -2819,6 +2807,7 @@ str8_is_before_case_sensitive(const void *a, const void *b)
|
||||
return cmp < 0;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic String Hashes
|
||||
|
||||
#if !defined(XXH_IMPLEMENTATION)
|
||||
|
||||
+1
-10
@@ -4,12 +4,6 @@
|
||||
#ifndef BASE_STRINGS_H
|
||||
#define BASE_STRINGS_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Third Party Includes
|
||||
|
||||
#define STB_SPRINTF_DECORATE(name) raddbg_##name
|
||||
#include "third_party/stb/stb_sprintf.h"
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String Types
|
||||
|
||||
@@ -211,8 +205,6 @@ internal String8 backslashed_from_str8(Arena *arena, String8 string);
|
||||
internal B32 str8_match(String8 a, String8 b, StringMatchFlags flags);
|
||||
internal U64 str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
|
||||
internal U64 str8_find_needle_reverse(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
|
||||
internal B32 str8_ends_with(String8 string, String8 end, StringMatchFlags flags);
|
||||
#define str8_ends_with_lit(string, end_lit, flags) str8_ends_with((string), str8_lit(end_lit), (flags))
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String Slicing
|
||||
@@ -245,7 +237,6 @@ internal String8 push_cstr(Arena *arena, String8 str); // TODO(rjf): this is unn
|
||||
//- rjf: string -> integer
|
||||
internal S64 sign_from_str8(String8 string, String8 *string_tail);
|
||||
internal B32 str8_is_integer(String8 string, U32 radix);
|
||||
|
||||
internal U64 u64_from_str8(String8 string, U32 radix);
|
||||
internal S64 s64_from_str8(String8 string, U32 radix);
|
||||
internal U32 u32_from_str8(String8 string, U32 radix);
|
||||
@@ -474,4 +465,4 @@ internal U64 str8_deserial_read_block(String8 string, U64 off, U64 size, Stri
|
||||
internal U64 u64_hash_from_seed_str8(U64 seed, String8 string);
|
||||
internal U64 u64_hash_from_str8(String8 string);
|
||||
|
||||
#endif // BASE_STRINGS_H
|
||||
#endif //BASE_STRINGS_H
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Synchronization Primitive Functions
|
||||
|
||||
//- rjf: recursive mutexes
|
||||
|
||||
internal Mutex mutex_alloc(void) {return os_mutex_alloc();}
|
||||
internal void mutex_release(Mutex mutex) {os_mutex_release(mutex);}
|
||||
internal void mutex_take(Mutex mutex) {os_mutex_take(mutex);}
|
||||
internal void mutex_drop(Mutex mutex) {os_mutex_drop(mutex);}
|
||||
|
||||
//- rjf: reader/writer mutexes
|
||||
|
||||
internal RWMutex rw_mutex_alloc(void) {return os_rw_mutex_alloc();}
|
||||
internal void rw_mutex_release(RWMutex mutex) {os_rw_mutex_release(mutex);}
|
||||
internal void rw_mutex_take_r(RWMutex mutex) {os_rw_mutex_take_r(mutex);}
|
||||
internal void rw_mutex_drop_r(RWMutex mutex) {os_rw_mutex_drop_r(mutex);}
|
||||
internal void rw_mutex_take_w(RWMutex mutex) {os_rw_mutex_take_w(mutex);}
|
||||
internal void rw_mutex_drop_w(RWMutex mutex) {os_rw_mutex_drop_w(mutex);}
|
||||
|
||||
//- rjf: condition variables
|
||||
|
||||
internal CondVar cond_var_alloc(void) {return os_cond_var_alloc();}
|
||||
internal void cond_var_release(CondVar cv) {os_cond_var_release(cv);}
|
||||
internal B32 cond_var_wait(CondVar cv, Mutex mutex, U64 endt_us) {return os_cond_var_wait(cv, mutex, endt_us);}
|
||||
internal B32 cond_var_wait_rw_r(CondVar cv, RWMutex mutex_rw, U64 endt_us) {return os_cond_var_wait_rw_r(cv, mutex_rw, endt_us);}
|
||||
internal B32 cond_var_wait_rw_w(CondVar cv, RWMutex mutex_rw, U64 endt_us) {return os_cond_var_wait_rw_w(cv, mutex_rw, endt_us);}
|
||||
internal void cond_var_signal(CondVar cv) {os_cond_var_signal(cv);}
|
||||
internal void cond_var_broadcast(CondVar cv) {os_cond_var_broadcast(cv);}
|
||||
|
||||
//- rjf: cross-process semaphores
|
||||
|
||||
internal Semaphore semaphore_alloc(U32 initial_count, U32 max_count, String8 name) {return os_semaphore_alloc(initial_count, max_count, name);}
|
||||
internal void semaphore_release(Semaphore semaphore) {os_semaphore_release(semaphore);}
|
||||
internal Semaphore semaphore_open(String8 name) {return os_semaphore_open(name);}
|
||||
internal void semaphore_close(Semaphore semaphore) {os_semaphore_close(semaphore);}
|
||||
internal B32 semaphore_take(Semaphore semaphore, U64 endt_us) {return os_semaphore_take(semaphore, endt_us);}
|
||||
internal void semaphore_drop(Semaphore semaphore) {os_semaphore_drop(semaphore);}
|
||||
|
||||
//- rjf: barriers
|
||||
|
||||
internal Barrier barrier_alloc(U64 count) {return os_barrier_alloc(count);}
|
||||
internal void barrier_release(Barrier barrier) {os_barrier_release(barrier);}
|
||||
internal void barrier_wait(Barrier barrier) {os_barrier_wait(barrier);}
|
||||
@@ -0,0 +1,86 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef BASE_SYNC_H
|
||||
#define BASE_SYNC_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Synchronization Primitive Types
|
||||
|
||||
typedef struct Mutex Mutex;
|
||||
struct Mutex
|
||||
{
|
||||
U64 u64[1];
|
||||
};
|
||||
|
||||
typedef struct RWMutex RWMutex;
|
||||
struct RWMutex
|
||||
{
|
||||
U64 u64[1];
|
||||
};
|
||||
|
||||
typedef struct CondVar CondVar;
|
||||
struct CondVar
|
||||
{
|
||||
U64 u64[1];
|
||||
};
|
||||
|
||||
typedef struct Semaphore Semaphore;
|
||||
struct Semaphore
|
||||
{
|
||||
U64 u64[1];
|
||||
};
|
||||
|
||||
typedef struct Barrier Barrier;
|
||||
struct Barrier
|
||||
{
|
||||
U64 u64[1];
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Synchronization Primitive Functions
|
||||
|
||||
//- rjf: recursive mutexes
|
||||
internal Mutex mutex_alloc(void);
|
||||
internal void mutex_release(Mutex mutex);
|
||||
internal void mutex_take(Mutex mutex);
|
||||
internal void mutex_drop(Mutex mutex);
|
||||
|
||||
//- rjf: reader/writer mutexes
|
||||
internal RWMutex rw_mutex_alloc(void);
|
||||
internal void rw_mutex_release(RWMutex mutex);
|
||||
internal void rw_mutex_take_r(RWMutex mutex);
|
||||
internal void rw_mutex_drop_r(RWMutex mutex);
|
||||
internal void rw_mutex_take_w(RWMutex mutex);
|
||||
internal void rw_mutex_drop_w(RWMutex mutex);
|
||||
|
||||
//- rjf: condition variables
|
||||
internal CondVar cond_var_alloc(void);
|
||||
internal void cond_var_release(CondVar cv);
|
||||
// returns false on timeout, true on signal, (max_wait_ms = max_U64) -> no timeout
|
||||
internal B32 cond_var_wait(CondVar cv, Mutex mutex, U64 endt_us);
|
||||
internal B32 cond_var_wait_rw_r(CondVar cv, RWMutex mutex_rw, U64 endt_us);
|
||||
internal B32 cond_var_wait_rw_w(CondVar cv, RWMutex mutex_rw, U64 endt_us);
|
||||
internal void cond_var_signal(CondVar cv);
|
||||
internal void cond_var_broadcast(CondVar cv);
|
||||
|
||||
//- rjf: cross-process semaphores
|
||||
internal Semaphore semaphore_alloc(U32 initial_count, U32 max_count, String8 name);
|
||||
internal void semaphore_release(Semaphore semaphore);
|
||||
internal Semaphore semaphore_open(String8 name);
|
||||
internal void semaphore_close(Semaphore semaphore);
|
||||
internal B32 semaphore_take(Semaphore semaphore, U64 endt_us);
|
||||
internal void semaphore_drop(Semaphore semaphore);
|
||||
|
||||
//- rjf: barriers
|
||||
internal Barrier barrier_alloc(U64 count);
|
||||
internal void barrier_release(Barrier barrier);
|
||||
internal void barrier_wait(Barrier barrier);
|
||||
|
||||
//- rjf: scope macros
|
||||
#define MutexScope(mutex) DeferLoop(mutex_take(mutex), mutex_drop(mutex))
|
||||
#define MutexScopeR(mutex) DeferLoop(rw_mutex_take_r(mutex), rw_mutex_drop_r(mutex))
|
||||
#define MutexScopeW(mutex) DeferLoop(rw_mutex_take_w(mutex), rw_mutex_drop_w(mutex))
|
||||
#define MutexScopeRWPromote(mutex) DeferLoop((rw_mutex_drop_r(mutex), rw_mutex_take_w(mutex)), (rw_mutex_drop_w(mutex), rw_mutex_take_r(mutex)))
|
||||
|
||||
#endif // BASE_SYNC_H
|
||||
@@ -21,7 +21,7 @@ tctx_alloc(void)
|
||||
TCTX *tctx = push_array(arena, TCTX, 1);
|
||||
tctx->arenas[0] = arena;
|
||||
tctx->arenas[1] = arena_alloc();
|
||||
tctx->lane_count = 1;
|
||||
tctx->lane_ctx.lane_count = 1;
|
||||
return tctx;
|
||||
}
|
||||
|
||||
@@ -76,27 +76,23 @@ tctx_get_scratch(Arena **conflicts, U64 count)
|
||||
//- rjf: lane metadata
|
||||
|
||||
internal void
|
||||
tctx_set_lane_info(U64 lane_idx, U64 lane_count)
|
||||
tctx_set_lane_ctx(LaneCtx lane_ctx)
|
||||
{
|
||||
TCTX *tctx = tctx_selected();
|
||||
OS_Handle barrier = os_barrier_alloc(lane_count);
|
||||
tctx->lane_idx = lane_idx;
|
||||
tctx->lane_count = lane_count;
|
||||
tctx->lane_barrier_id = barrier.u64[0];
|
||||
tctx->lane_ctx = lane_ctx;
|
||||
}
|
||||
|
||||
internal void
|
||||
tctx_lane_barrier_wait(void)
|
||||
{
|
||||
TCTX *tctx = tctx_selected();
|
||||
OS_Handle barrier = {tctx->lane_barrier_id};
|
||||
os_barrier_wait(barrier);
|
||||
os_barrier_wait(tctx->lane_ctx.barrier);
|
||||
}
|
||||
|
||||
internal Rng1U64
|
||||
tctx_lane_idx_range_from_count(U64 count)
|
||||
{
|
||||
U64 idxes_per_lane = count/lane_count();
|
||||
U64 idxes_per_lane = (count + lane_count()-1) / lane_count();
|
||||
U64 lane_base_idx = lane_idx()*idxes_per_lane;
|
||||
U64 lane_opl_idx = lane_base_idx + idxes_per_lane;
|
||||
U64 lane_opl_idx__clamped = Min(lane_opl_idx, count);
|
||||
|
||||
@@ -4,6 +4,17 @@
|
||||
#ifndef BASE_THREAD_CONTEXT_H
|
||||
#define BASE_THREAD_CONTEXT_H
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Lane Group Context
|
||||
|
||||
typedef struct LaneCtx LaneCtx;
|
||||
struct LaneCtx
|
||||
{
|
||||
U64 lane_idx;
|
||||
U64 lane_count;
|
||||
Barrier barrier;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Base Per-Thread State Bundle
|
||||
|
||||
@@ -17,10 +28,8 @@ struct TCTX
|
||||
U8 thread_name[32];
|
||||
U64 thread_name_size;
|
||||
|
||||
// rjf: lane info
|
||||
U64 lane_idx;
|
||||
U64 lane_count;
|
||||
U64 lane_barrier_id;
|
||||
// rjf: lane context
|
||||
LaneCtx lane_ctx;
|
||||
|
||||
// rjf: source location info
|
||||
char *file_name;
|
||||
@@ -42,13 +51,13 @@ internal Arena *tctx_get_scratch(Arena **conflicts, U64 count);
|
||||
#define scratch_end(scratch) temp_end(scratch)
|
||||
|
||||
//- rjf: lane metadata
|
||||
internal void tctx_set_lane_info(U64 lane_idx, U64 lane_count);
|
||||
internal void tctx_set_lane_ctx(LaneCtx lane_ctx);
|
||||
internal void tctx_lane_barrier_wait(void);
|
||||
internal Rng1U64 tctx_lane_idx_range_from_count(U64 count);
|
||||
#define lane_idx() (tctx_selected()->lane_idx)
|
||||
#define lane_count() (tctx_selected()->lane_count)
|
||||
#define lane_idx() (tctx_selected()->lane_ctx.lane_idx)
|
||||
#define lane_count() (tctx_selected()->lane_ctx.lane_count)
|
||||
#define lane_from_task_idx(idx) ((idx)%lane_count())
|
||||
#define lane_thread(idx, count) tctx_set_lane_info((idx), (count))
|
||||
#define lane_ctx(ctx) tctx_set_lane_ctx((ctx))
|
||||
#define lane_sync() tctx_lane_barrier_wait()
|
||||
#define lane_range(count) tctx_lane_idx_range_from_count(count)
|
||||
|
||||
|
||||
+45
-45
@@ -875,7 +875,7 @@ ctrl_entity_ctx_rw_store_alloc(void)
|
||||
store->ctx.hash_slots_count = 1024;
|
||||
store->ctx.hash_slots = push_array(arena, CTRL_EntityHashSlot, store->ctx.hash_slots_count);
|
||||
CTRL_Entity *root = store->ctx.root = ctrl_entity_alloc(store, &ctrl_entity_nil, CTRL_EntityKind_Root, Arch_Null, ctrl_handle_zero(), 0);
|
||||
CTRL_Entity *local_machine = ctrl_entity_alloc(store, root, CTRL_EntityKind_Machine, arch_from_context(), ctrl_handle_make(CTRL_MachineID_Local, dmn_handle_zero()), 0);
|
||||
CTRL_Entity *local_machine = ctrl_entity_alloc(store, root, CTRL_EntityKind_Machine, Arch_CURRENT, ctrl_handle_make(CTRL_MachineID_Local, dmn_handle_zero()), 0);
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8 local_machine_name = push_str8f(scratch.arena, "This PC (%S)", os_get_system_info()->machine_name);
|
||||
ctrl_entity_equip_string(store, local_machine, local_machine_name);
|
||||
@@ -1464,7 +1464,7 @@ ctrl_scope_close(CTRL_Scope *scope)
|
||||
{
|
||||
next = t->next;
|
||||
ins_atomic_u64_dec_eval(&t->node->scope_touch_count);
|
||||
os_condition_variable_broadcast(t->stripe->cv);
|
||||
cond_var_broadcast(t->stripe->cv);
|
||||
SLLStackPush(ctrl_tctx->free_call_stack_touch, t);
|
||||
}
|
||||
for(U64 idx = 0; idx < scope->call_stack_tree_touch_count; idx += 1)
|
||||
@@ -1473,7 +1473,7 @@ ctrl_scope_close(CTRL_Scope *scope)
|
||||
}
|
||||
if(scope->call_stack_tree_touch_count != 0)
|
||||
{
|
||||
os_condition_variable_broadcast(ctrl_state->call_stack_tree_cache.cv);
|
||||
cond_var_broadcast(ctrl_state->call_stack_tree_cache.cv);
|
||||
}
|
||||
SLLStackPush(ctrl_tctx->free_scope, scope);
|
||||
}
|
||||
@@ -1528,8 +1528,8 @@ ctrl_init(void)
|
||||
ctrl_state->process_memory_cache.stripes = push_array(arena, CTRL_ProcessMemoryCacheStripe, ctrl_state->process_memory_cache.stripes_count);
|
||||
for(U64 idx = 0; idx < ctrl_state->process_memory_cache.stripes_count; idx += 1)
|
||||
{
|
||||
ctrl_state->process_memory_cache.stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
ctrl_state->process_memory_cache.stripes[idx].cv = os_condition_variable_alloc();
|
||||
ctrl_state->process_memory_cache.stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
ctrl_state->process_memory_cache.stripes[idx].cv = cond_var_alloc();
|
||||
}
|
||||
ctrl_state->thread_reg_cache.slots_count = 1024;
|
||||
ctrl_state->thread_reg_cache.slots = push_array(arena, CTRL_ThreadRegCacheSlot, ctrl_state->thread_reg_cache.slots_count);
|
||||
@@ -1538,7 +1538,7 @@ ctrl_init(void)
|
||||
for(U64 idx = 0; idx < ctrl_state->thread_reg_cache.stripes_count; idx += 1)
|
||||
{
|
||||
ctrl_state->thread_reg_cache.stripes[idx].arena = arena_alloc();
|
||||
ctrl_state->thread_reg_cache.stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
ctrl_state->thread_reg_cache.stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
}
|
||||
ctrl_state->call_stack_cache.slots_count = 1024;
|
||||
ctrl_state->call_stack_cache.slots = push_array(arena, CTRL_CallStackCacheSlot, ctrl_state->call_stack_cache.slots_count);
|
||||
@@ -1547,8 +1547,8 @@ ctrl_init(void)
|
||||
for(U64 idx = 0; idx < ctrl_state->call_stack_cache.stripes_count; idx += 1)
|
||||
{
|
||||
ctrl_state->call_stack_cache.stripes[idx].arena = arena_alloc();
|
||||
ctrl_state->call_stack_cache.stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
ctrl_state->call_stack_cache.stripes[idx].cv = os_condition_variable_alloc();
|
||||
ctrl_state->call_stack_cache.stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
ctrl_state->call_stack_cache.stripes[idx].cv = cond_var_alloc();
|
||||
}
|
||||
ctrl_state->module_image_info_cache.slots_count = 1024;
|
||||
ctrl_state->module_image_info_cache.slots = push_array(arena, CTRL_ModuleImageInfoCacheSlot, ctrl_state->module_image_info_cache.slots_count);
|
||||
@@ -1557,20 +1557,20 @@ ctrl_init(void)
|
||||
for(U64 idx = 0; idx < ctrl_state->module_image_info_cache.stripes_count; idx += 1)
|
||||
{
|
||||
ctrl_state->module_image_info_cache.stripes[idx].arena = arena_alloc();
|
||||
ctrl_state->module_image_info_cache.stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
ctrl_state->module_image_info_cache.stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
}
|
||||
ctrl_state->call_stack_tree_cache.tree.root = &ctrl_call_stack_tree_node_nil;
|
||||
ctrl_state->call_stack_tree_cache.cv = os_condition_variable_alloc();
|
||||
ctrl_state->call_stack_tree_cache.rw_mutex = os_rw_mutex_alloc();
|
||||
ctrl_state->call_stack_tree_cache.cv = cond_var_alloc();
|
||||
ctrl_state->call_stack_tree_cache.rw_mutex = rw_mutex_alloc();
|
||||
ctrl_state->u2c_ring_size = KB(64);
|
||||
ctrl_state->u2c_ring_base = push_array_no_zero(arena, U8, ctrl_state->u2c_ring_size);
|
||||
ctrl_state->u2c_ring_mutex = os_mutex_alloc();
|
||||
ctrl_state->u2c_ring_cv = os_condition_variable_alloc();
|
||||
ctrl_state->u2c_ring_mutex = mutex_alloc();
|
||||
ctrl_state->u2c_ring_cv = cond_var_alloc();
|
||||
ctrl_state->c2u_ring_size = KB(64);
|
||||
ctrl_state->c2u_ring_max_string_size = ctrl_state->c2u_ring_size/2;
|
||||
ctrl_state->c2u_ring_base = push_array_no_zero(arena, U8, ctrl_state->c2u_ring_size);
|
||||
ctrl_state->c2u_ring_mutex = os_mutex_alloc();
|
||||
ctrl_state->c2u_ring_cv = os_condition_variable_alloc();
|
||||
ctrl_state->c2u_ring_mutex = mutex_alloc();
|
||||
ctrl_state->c2u_ring_cv = cond_var_alloc();
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8 user_program_data_path = os_get_process_info()->user_program_data_path;
|
||||
@@ -1580,7 +1580,7 @@ ctrl_init(void)
|
||||
os_write_data_to_file_path(ctrl_state->ctrl_thread_log_path, str8_zero());
|
||||
scratch_end(scratch);
|
||||
}
|
||||
ctrl_state->ctrl_thread_entity_ctx_rw_mutex = os_rw_mutex_alloc();
|
||||
ctrl_state->ctrl_thread_entity_ctx_rw_mutex = rw_mutex_alloc();
|
||||
ctrl_state->ctrl_thread_entity_store = ctrl_entity_ctx_rw_store_alloc();
|
||||
ctrl_state->ctrl_thread_eval_cache = e_cache_alloc();
|
||||
ctrl_state->ctrl_thread_msg_process_arena = arena_alloc();
|
||||
@@ -1596,12 +1596,12 @@ ctrl_init(void)
|
||||
}
|
||||
ctrl_state->u2ms_ring_size = KB(64);
|
||||
ctrl_state->u2ms_ring_base = push_array(arena, U8, ctrl_state->u2ms_ring_size);
|
||||
ctrl_state->u2ms_ring_mutex = os_mutex_alloc();
|
||||
ctrl_state->u2ms_ring_cv = os_condition_variable_alloc();
|
||||
ctrl_state->u2ms_ring_mutex = mutex_alloc();
|
||||
ctrl_state->u2ms_ring_cv = cond_var_alloc();
|
||||
ctrl_state->u2csb_ring_size = KB(64);
|
||||
ctrl_state->u2csb_ring_base = push_array(arena, U8, ctrl_state->u2csb_ring_size);
|
||||
ctrl_state->u2csb_ring_mutex = os_mutex_alloc();
|
||||
ctrl_state->u2csb_ring_cv = os_condition_variable_alloc();
|
||||
ctrl_state->u2csb_ring_mutex = mutex_alloc();
|
||||
ctrl_state->u2csb_ring_cv = cond_var_alloc();
|
||||
ctrl_state->ctrl_thread_log = log_alloc();
|
||||
ctrl_state->ctrl_thread = os_thread_launch(ctrl_thread__entry_point, 0, 0);
|
||||
}
|
||||
@@ -1726,7 +1726,7 @@ ctrl_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 vaddr_range, B32
|
||||
}
|
||||
else
|
||||
{
|
||||
os_condition_variable_wait_rw_r(process_stripe->cv, process_stripe->rw_mutex, endt_us);
|
||||
cond_var_wait_rw_r(process_stripe->cv, process_stripe->rw_mutex, endt_us);
|
||||
}
|
||||
}
|
||||
key_is_stale = id_stale;
|
||||
@@ -3482,7 +3482,7 @@ ctrl_call_stack_from_thread(CTRL_Scope *scope, CTRL_Handle thread_handle, B32 hi
|
||||
}
|
||||
else if(node_working)
|
||||
{
|
||||
os_condition_variable_wait_rw_r(stripe->cv, stripe->rw_mutex, endt_us);
|
||||
cond_var_wait_rw_r(stripe->cv, stripe->rw_mutex, endt_us);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3560,9 +3560,9 @@ ctrl_call_stack_tree(CTRL_Scope *scope, U64 endt_us)
|
||||
// rjf: is stale? -> request new calculation
|
||||
if(is_stale && !ins_atomic_u64_eval_cond_assign(&cache->request_count, 1, 0))
|
||||
{
|
||||
os_rw_mutex_drop_r(cache->rw_mutex);
|
||||
rw_mutex_drop_r(cache->rw_mutex);
|
||||
async_push_work(ctrl_call_stack_tree_build_work);
|
||||
os_rw_mutex_take_r(cache->rw_mutex);
|
||||
rw_mutex_take_r(cache->rw_mutex);
|
||||
}
|
||||
|
||||
// rjf: is not stale, or we're out of time? -> grab cached result & touch, exit
|
||||
@@ -3575,7 +3575,7 @@ ctrl_call_stack_tree(CTRL_Scope *scope, U64 endt_us)
|
||||
}
|
||||
|
||||
// rjf: wait for new results
|
||||
os_condition_variable_wait_rw_r(cache->cv, cache->rw_mutex, endt_us);
|
||||
cond_var_wait_rw_r(cache->cv, cache->rw_mutex, endt_us);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -3657,11 +3657,11 @@ ctrl_u2c_push_msgs(CTRL_MsgList *msgs, U64 endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(ctrl_state->u2c_ring_cv, ctrl_state->u2c_ring_mutex, endt_us);
|
||||
cond_var_wait(ctrl_state->u2c_ring_cv, ctrl_state->u2c_ring_mutex, endt_us);
|
||||
}
|
||||
if(good)
|
||||
{
|
||||
os_condition_variable_broadcast(ctrl_state->u2c_ring_cv);
|
||||
cond_var_broadcast(ctrl_state->u2c_ring_cv);
|
||||
}
|
||||
scratch_end(scratch);
|
||||
return good;
|
||||
@@ -3684,9 +3684,9 @@ ctrl_u2c_pop_msgs(Arena *arena)
|
||||
ctrl_state->u2c_ring_read_pos += ring_read(ctrl_state->u2c_ring_base, ctrl_state->u2c_ring_size, ctrl_state->u2c_ring_read_pos, msgs_srlzed_baked.str, size_to_decode);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(ctrl_state->u2c_ring_cv, ctrl_state->u2c_ring_mutex, max_U64);
|
||||
cond_var_wait(ctrl_state->u2c_ring_cv, ctrl_state->u2c_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(ctrl_state->u2c_ring_cv);
|
||||
cond_var_broadcast(ctrl_state->u2c_ring_cv);
|
||||
CTRL_MsgList msgs = ctrl_msg_list_from_serialized_string(arena, msgs_srlzed_baked);
|
||||
scratch_end(scratch);
|
||||
return msgs;
|
||||
@@ -3718,9 +3718,9 @@ ctrl_c2u_push_events(CTRL_EventList *events)
|
||||
ctrl_state->c2u_ring_write_pos += ring_write(ctrl_state->c2u_ring_base, ctrl_state->c2u_ring_size, ctrl_state->c2u_ring_write_pos, event_srlzed.str, event_srlzed.size);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(ctrl_state->c2u_ring_cv, ctrl_state->c2u_ring_mutex, os_now_microseconds()+100);
|
||||
cond_var_wait(ctrl_state->c2u_ring_cv, ctrl_state->c2u_ring_mutex, os_now_microseconds()+100);
|
||||
}
|
||||
os_condition_variable_broadcast(ctrl_state->c2u_ring_cv);
|
||||
cond_var_broadcast(ctrl_state->c2u_ring_cv);
|
||||
if(ctrl_state->wakeup_hook != 0)
|
||||
{
|
||||
ctrl_state->wakeup_hook();
|
||||
@@ -3755,7 +3755,7 @@ ctrl_c2u_pop_events(Arena *arena)
|
||||
break;
|
||||
}
|
||||
}
|
||||
os_condition_variable_broadcast(ctrl_state->c2u_ring_cv);
|
||||
cond_var_broadcast(ctrl_state->c2u_ring_cv);
|
||||
scratch_end(scratch);
|
||||
ProfEnd();
|
||||
return events;
|
||||
@@ -6880,9 +6880,9 @@ ctrl_u2ms_enqueue_req(HS_Key key, CTRL_Handle process, Rng1U64 vaddr_range, B32
|
||||
break;
|
||||
}
|
||||
if(os_now_microseconds() >= endt_us) {break;}
|
||||
os_condition_variable_wait(ctrl_state->u2ms_ring_cv, ctrl_state->u2ms_ring_mutex, endt_us);
|
||||
cond_var_wait(ctrl_state->u2ms_ring_cv, ctrl_state->u2ms_ring_mutex, endt_us);
|
||||
}
|
||||
os_condition_variable_broadcast(ctrl_state->u2ms_ring_cv);
|
||||
cond_var_broadcast(ctrl_state->u2ms_ring_cv);
|
||||
return good;
|
||||
}
|
||||
|
||||
@@ -6900,9 +6900,9 @@ ctrl_u2ms_dequeue_req(HS_Key *out_key, CTRL_Handle *out_process, Rng1U64 *out_va
|
||||
ctrl_state->u2ms_ring_read_pos += ring_read_struct(ctrl_state->u2ms_ring_base, ctrl_state->u2ms_ring_size, ctrl_state->u2ms_ring_read_pos, out_zero_terminated);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(ctrl_state->u2ms_ring_cv, ctrl_state->u2ms_ring_mutex, max_U64);
|
||||
cond_var_wait(ctrl_state->u2ms_ring_cv, ctrl_state->u2ms_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(ctrl_state->u2ms_ring_cv);
|
||||
cond_var_broadcast(ctrl_state->u2ms_ring_cv);
|
||||
}
|
||||
|
||||
//- rjf: entry point
|
||||
@@ -7068,7 +7068,7 @@ ASYNC_WORK_DEF(ctrl_mem_stream_work)
|
||||
}
|
||||
|
||||
//- rjf: broadcast changes
|
||||
os_condition_variable_broadcast(process_stripe->cv);
|
||||
cond_var_broadcast(process_stripe->cv);
|
||||
if(!u128_match(u128_zero(), hash))
|
||||
{
|
||||
if(ctrl_state->wakeup_hook != 0)
|
||||
@@ -7104,11 +7104,11 @@ ctrl_u2csb_enqueue_req(CTRL_Handle thread, U64 endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(ctrl_state->u2csb_ring_cv, ctrl_state->u2csb_ring_mutex, endt_us);
|
||||
cond_var_wait(ctrl_state->u2csb_ring_cv, ctrl_state->u2csb_ring_mutex, endt_us);
|
||||
}
|
||||
if(good)
|
||||
{
|
||||
os_condition_variable_broadcast(ctrl_state->u2csb_ring_cv);
|
||||
cond_var_broadcast(ctrl_state->u2csb_ring_cv);
|
||||
}
|
||||
return good;
|
||||
}
|
||||
@@ -7124,9 +7124,9 @@ ctrl_u2csb_dequeue_req(CTRL_Handle *out_thread)
|
||||
ctrl_state->u2csb_ring_read_pos += ring_read_struct(ctrl_state->u2csb_ring_base, ctrl_state->u2csb_ring_size, ctrl_state->u2csb_ring_read_pos, out_thread);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(ctrl_state->u2csb_ring_cv, ctrl_state->u2csb_ring_mutex, max_U64);
|
||||
cond_var_wait(ctrl_state->u2csb_ring_cv, ctrl_state->u2csb_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(ctrl_state->u2csb_ring_cv);
|
||||
cond_var_broadcast(ctrl_state->u2csb_ring_cv);
|
||||
}
|
||||
|
||||
//- rjf: entry point
|
||||
@@ -7296,7 +7296,7 @@ ASYNC_WORK_DEF(ctrl_call_stack_build_work)
|
||||
// rjf: found, not committed? -> wait & retry
|
||||
if(found && !committed)
|
||||
{
|
||||
os_condition_variable_wait_rw_w(stripe->cv, stripe->rw_mutex, os_now_microseconds()+10);
|
||||
cond_var_wait_rw_w(stripe->cv, stripe->rw_mutex, os_now_microseconds()+10);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7318,7 +7318,7 @@ ASYNC_WORK_DEF(ctrl_call_stack_build_work)
|
||||
}
|
||||
|
||||
//- rjf: broadcast update
|
||||
os_condition_variable_broadcast(stripe->cv);
|
||||
cond_var_broadcast(stripe->cv);
|
||||
if(ctrl_state->wakeup_hook != 0)
|
||||
{
|
||||
ctrl_state->wakeup_hook();
|
||||
@@ -7443,10 +7443,10 @@ ASYNC_WORK_DEF(ctrl_call_stack_tree_build_work)
|
||||
cache->request_count -= 1;
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait_rw_w(cache->cv, cache->rw_mutex, max_U64);
|
||||
cond_var_wait_rw_w(cache->cv, cache->rw_mutex, max_U64);
|
||||
}
|
||||
}
|
||||
os_condition_variable_broadcast(cache->cv);
|
||||
cond_var_broadcast(cache->cv);
|
||||
|
||||
//- rjf: release old arena
|
||||
if(old_arena)
|
||||
|
||||
+17
-17
@@ -585,8 +585,8 @@ struct CTRL_ProcessMemoryCacheSlot
|
||||
typedef struct CTRL_ProcessMemoryCacheStripe CTRL_ProcessMemoryCacheStripe;
|
||||
struct CTRL_ProcessMemoryCacheStripe
|
||||
{
|
||||
OS_Handle rw_mutex;
|
||||
OS_Handle cv;
|
||||
RWMutex rw_mutex;
|
||||
CondVar cv;
|
||||
};
|
||||
|
||||
typedef struct CTRL_ProcessMemoryCache CTRL_ProcessMemoryCache;
|
||||
@@ -634,7 +634,7 @@ typedef struct CTRL_ThreadRegCacheStripe CTRL_ThreadRegCacheStripe;
|
||||
struct CTRL_ThreadRegCacheStripe
|
||||
{
|
||||
Arena *arena;
|
||||
OS_Handle rw_mutex;
|
||||
RWMutex rw_mutex;
|
||||
};
|
||||
|
||||
typedef struct CTRL_ThreadRegCache CTRL_ThreadRegCache;
|
||||
@@ -680,8 +680,8 @@ typedef struct CTRL_CallStackCacheStripe CTRL_CallStackCacheStripe;
|
||||
struct CTRL_CallStackCacheStripe
|
||||
{
|
||||
Arena *arena;
|
||||
OS_Handle rw_mutex;
|
||||
OS_Handle cv;
|
||||
RWMutex rw_mutex;
|
||||
CondVar cv;
|
||||
};
|
||||
|
||||
typedef struct CTRL_CallStackCache CTRL_CallStackCache;
|
||||
@@ -723,7 +723,7 @@ typedef struct CTRL_ModuleImageInfoCacheStripe CTRL_ModuleImageInfoCacheStripe;
|
||||
struct CTRL_ModuleImageInfoCacheStripe
|
||||
{
|
||||
Arena *arena;
|
||||
OS_Handle rw_mutex;
|
||||
RWMutex rw_mutex;
|
||||
};
|
||||
|
||||
typedef struct CTRL_ModuleImageInfoCache CTRL_ModuleImageInfoCache;
|
||||
@@ -743,8 +743,8 @@ struct CTRL_CallStackTreeCache
|
||||
{
|
||||
Arena *arena;
|
||||
CTRL_CallStackTree tree;
|
||||
OS_Handle cv;
|
||||
OS_Handle rw_mutex;
|
||||
CondVar cv;
|
||||
RWMutex rw_mutex;
|
||||
U64 reg_gen;
|
||||
U64 mem_gen;
|
||||
U64 scope_touch_count;
|
||||
@@ -855,8 +855,8 @@ struct CTRL_State
|
||||
U8 *u2c_ring_base;
|
||||
U64 u2c_ring_write_pos;
|
||||
U64 u2c_ring_read_pos;
|
||||
OS_Handle u2c_ring_mutex;
|
||||
OS_Handle u2c_ring_cv;
|
||||
Mutex u2c_ring_mutex;
|
||||
CondVar u2c_ring_cv;
|
||||
|
||||
// rjf: ctrl -> user event ring buffer
|
||||
U64 c2u_ring_size;
|
||||
@@ -864,15 +864,15 @@ struct CTRL_State
|
||||
U8 *c2u_ring_base;
|
||||
U64 c2u_ring_write_pos;
|
||||
U64 c2u_ring_read_pos;
|
||||
OS_Handle c2u_ring_mutex;
|
||||
OS_Handle c2u_ring_cv;
|
||||
Mutex c2u_ring_mutex;
|
||||
CondVar c2u_ring_cv;
|
||||
|
||||
// rjf: ctrl thread state
|
||||
U64 ctrl_thread_run_state;
|
||||
String8 ctrl_thread_log_path;
|
||||
OS_Handle ctrl_thread;
|
||||
Log *ctrl_thread_log;
|
||||
OS_Handle ctrl_thread_entity_ctx_rw_mutex;
|
||||
RWMutex ctrl_thread_entity_ctx_rw_mutex;
|
||||
CTRL_EntityCtxRWStore *ctrl_thread_entity_store;
|
||||
E_Cache *ctrl_thread_eval_cache;
|
||||
Arena *ctrl_thread_msg_process_arena;
|
||||
@@ -896,16 +896,16 @@ struct CTRL_State
|
||||
U8 *u2ms_ring_base;
|
||||
U64 u2ms_ring_write_pos;
|
||||
U64 u2ms_ring_read_pos;
|
||||
OS_Handle u2ms_ring_mutex;
|
||||
OS_Handle u2ms_ring_cv;
|
||||
Mutex u2ms_ring_mutex;
|
||||
CondVar u2ms_ring_cv;
|
||||
|
||||
// rjf: user -> call stack builder ring buffer
|
||||
U64 u2csb_ring_size;
|
||||
U8 *u2csb_ring_base;
|
||||
U64 u2csb_ring_write_pos;
|
||||
U64 u2csb_ring_read_pos;
|
||||
OS_Handle u2csb_ring_mutex;
|
||||
OS_Handle u2csb_ring_cv;
|
||||
Mutex u2csb_ring_mutex;
|
||||
CondVar u2csb_ring_cv;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
@@ -270,13 +270,13 @@ dasm_init(void)
|
||||
for(U64 idx = 0; idx < dasm_shared->stripes_count; idx += 1)
|
||||
{
|
||||
dasm_shared->stripes[idx].arena = arena_alloc();
|
||||
dasm_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
dasm_shared->stripes[idx].cv = os_condition_variable_alloc();
|
||||
dasm_shared->stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
dasm_shared->stripes[idx].cv = cond_var_alloc();
|
||||
}
|
||||
dasm_shared->u2p_ring_size = KB(64);
|
||||
dasm_shared->u2p_ring_base = push_array_no_zero(arena, U8, dasm_shared->u2p_ring_size);
|
||||
dasm_shared->u2p_ring_cv = os_condition_variable_alloc();
|
||||
dasm_shared->u2p_ring_mutex = os_mutex_alloc();
|
||||
dasm_shared->u2p_ring_cv = cond_var_alloc();
|
||||
dasm_shared->u2p_ring_mutex = mutex_alloc();
|
||||
dasm_shared->evictor_detector_thread = os_thread_launch(dasm_evictor_detector_thread__entry_point, 0, 0);
|
||||
}
|
||||
|
||||
@@ -473,11 +473,11 @@ dasm_u2p_enqueue_req(HS_Root root, U128 hash, DASM_Params *params, U64 endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(dasm_shared->u2p_ring_cv, dasm_shared->u2p_ring_mutex, endt_us);
|
||||
cond_var_wait(dasm_shared->u2p_ring_cv, dasm_shared->u2p_ring_mutex, endt_us);
|
||||
}
|
||||
if(good)
|
||||
{
|
||||
os_condition_variable_broadcast(dasm_shared->u2p_ring_cv);
|
||||
cond_var_broadcast(dasm_shared->u2p_ring_cv);
|
||||
}
|
||||
return good;
|
||||
}
|
||||
@@ -503,9 +503,9 @@ dasm_u2p_dequeue_req(Arena *arena, HS_Root *root_out, U128 *hash_out, DASM_Param
|
||||
dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, ¶ms_out->dbgi_key.min_timestamp);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(dasm_shared->u2p_ring_cv, dasm_shared->u2p_ring_mutex, max_U64);
|
||||
cond_var_wait(dasm_shared->u2p_ring_cv, dasm_shared->u2p_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(dasm_shared->u2p_ring_cv);
|
||||
cond_var_broadcast(dasm_shared->u2p_ring_cv);
|
||||
}
|
||||
|
||||
ASYNC_WORK_DEF(dasm_parse_work)
|
||||
|
||||
@@ -207,8 +207,8 @@ typedef struct DASM_Stripe DASM_Stripe;
|
||||
struct DASM_Stripe
|
||||
{
|
||||
Arena *arena;
|
||||
OS_Handle rw_mutex;
|
||||
OS_Handle cv;
|
||||
RWMutex rw_mutex;
|
||||
CondVar cv;
|
||||
DASM_Node *free_node;
|
||||
};
|
||||
|
||||
@@ -259,8 +259,8 @@ struct DASM_Shared
|
||||
U8 *u2p_ring_base;
|
||||
U64 u2p_ring_write_pos;
|
||||
U64 u2p_ring_read_pos;
|
||||
OS_Handle u2p_ring_cv;
|
||||
OS_Handle u2p_ring_mutex;
|
||||
CondVar u2p_ring_cv;
|
||||
Mutex u2p_ring_mutex;
|
||||
|
||||
// rjf: evictor/detector thread
|
||||
OS_Handle evictor_detector_thread;
|
||||
|
||||
+44
-44
@@ -209,8 +209,8 @@ di_init(void)
|
||||
for(U64 idx = 0; idx < di_shared->stripes_count; idx += 1)
|
||||
{
|
||||
di_shared->stripes[idx].arena = arena_alloc();
|
||||
di_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
di_shared->stripes[idx].cv = os_condition_variable_alloc();
|
||||
di_shared->stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
di_shared->stripes[idx].cv = cond_var_alloc();
|
||||
}
|
||||
di_shared->search_slots_count = 512;
|
||||
di_shared->search_slots = push_array(arena, DI_SearchSlot, di_shared->search_slots_count);
|
||||
@@ -219,23 +219,23 @@ di_init(void)
|
||||
for(U64 idx = 0; idx < di_shared->search_stripes_count; idx += 1)
|
||||
{
|
||||
di_shared->search_stripes[idx].arena = arena_alloc();
|
||||
di_shared->search_stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
di_shared->search_stripes[idx].cv = os_condition_variable_alloc();
|
||||
di_shared->search_stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
di_shared->search_stripes[idx].cv = cond_var_alloc();
|
||||
}
|
||||
di_shared->u2p_ring_mutex = os_mutex_alloc();
|
||||
di_shared->u2p_ring_cv = os_condition_variable_alloc();
|
||||
di_shared->u2p_ring_mutex = mutex_alloc();
|
||||
di_shared->u2p_ring_cv = cond_var_alloc();
|
||||
di_shared->u2p_ring_size = KB(64);
|
||||
di_shared->u2p_ring_base = push_array_no_zero(arena, U8, di_shared->u2p_ring_size);
|
||||
di_shared->p2u_ring_mutex = os_mutex_alloc();
|
||||
di_shared->p2u_ring_cv = os_condition_variable_alloc();
|
||||
di_shared->p2u_ring_mutex = mutex_alloc();
|
||||
di_shared->p2u_ring_cv = cond_var_alloc();
|
||||
di_shared->p2u_ring_size = KB(64);
|
||||
di_shared->p2u_ring_base = push_array_no_zero(arena, U8, di_shared->p2u_ring_size);
|
||||
di_shared->search_threads_count = 1;
|
||||
di_shared->search_threads = push_array(arena, DI_SearchThread, di_shared->search_threads_count);
|
||||
for EachIndex(idx, di_shared->search_threads_count)
|
||||
{
|
||||
di_shared->search_threads[idx].ring_mutex = os_mutex_alloc();
|
||||
di_shared->search_threads[idx].ring_cv = os_condition_variable_alloc();
|
||||
di_shared->search_threads[idx].ring_mutex = mutex_alloc();
|
||||
di_shared->search_threads[idx].ring_cv = cond_var_alloc();
|
||||
di_shared->search_threads[idx].ring_size = KB(64);
|
||||
di_shared->search_threads[idx].ring_base = push_array_no_zero(arena, U8, di_shared->search_threads[idx].ring_size);
|
||||
di_shared->search_threads[idx].thread = os_thread_launch(di_search_thread__entry_point, (void *)idx, 0);
|
||||
@@ -279,12 +279,12 @@ di_scope_close(DI_Scope *scope)
|
||||
if(t->node != 0)
|
||||
{
|
||||
ins_atomic_u64_dec_eval(&t->node->touch_count);
|
||||
os_condition_variable_broadcast(t->stripe->cv);
|
||||
cond_var_broadcast(t->stripe->cv);
|
||||
}
|
||||
if(t->search_node != 0)
|
||||
{
|
||||
ins_atomic_u64_dec_eval(&t->search_node->scope_refcount);
|
||||
os_condition_variable_broadcast(t->search_stripe->cv);
|
||||
cond_var_broadcast(t->search_stripe->cv);
|
||||
}
|
||||
SLLStackPush(di_tctx->free_touch, t);
|
||||
}
|
||||
@@ -343,7 +343,7 @@ di_node_from_key_slot__stripe_mutex_r_guarded(DI_Slot *slot, DI_Key *key)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
DI_Node *node = 0;
|
||||
StringMatchFlags match_flags = path_match_flags_from_os(operating_system_from_context());
|
||||
StringMatchFlags match_flags = path_match_flags_from_os(OperatingSystem_CURRENT);
|
||||
U64 most_recent_timestamp = max_U64;
|
||||
for(DI_Node *n = slot->first; n != 0; n = n->next)
|
||||
{
|
||||
@@ -505,7 +505,7 @@ di_open(DI_Key *key)
|
||||
{
|
||||
di_u2p_enqueue_key(key, max_U64);
|
||||
ins_atomic_u64_eval_assign(&node->is_working, 1);
|
||||
DeferLoop(os_rw_mutex_drop_w(stripe->rw_mutex), os_rw_mutex_take_w(stripe->rw_mutex))
|
||||
DeferLoop(rw_mutex_drop_w(stripe->rw_mutex), rw_mutex_take_w(stripe->rw_mutex))
|
||||
{
|
||||
async_push_work(di_parse_work);
|
||||
}
|
||||
@@ -566,7 +566,7 @@ di_close(DI_Key *key)
|
||||
}
|
||||
|
||||
//- rjf: wait for touch count / working marker to go to 0
|
||||
os_condition_variable_wait_rw_w(stripe->cv, stripe->rw_mutex, max_U64);
|
||||
cond_var_wait_rw_w(stripe->cv, stripe->rw_mutex, max_U64);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -625,7 +625,7 @@ di_rdi_from_key(DI_Scope *scope, DI_Key *key, B32 high_priority, U64 endt_us)
|
||||
ProfScope("ask for parse")
|
||||
{
|
||||
ins_atomic_u64_eval_assign(&node->is_working, 1);
|
||||
DeferLoop(os_rw_mutex_drop_r(stripe->rw_mutex), os_rw_mutex_take_r(stripe->rw_mutex))
|
||||
DeferLoop(rw_mutex_drop_r(stripe->rw_mutex), rw_mutex_take_r(stripe->rw_mutex))
|
||||
{
|
||||
async_push_work(di_parse_work, .priority = high_priority ? ASYNC_Priority_High : ASYNC_Priority_Low);
|
||||
}
|
||||
@@ -640,7 +640,7 @@ di_rdi_from_key(DI_Scope *scope, DI_Key *key, B32 high_priority, U64 endt_us)
|
||||
|
||||
//- rjf: wait on this stripe
|
||||
{
|
||||
os_condition_variable_wait_rw_r(stripe->cv, stripe->rw_mutex, endt_us);
|
||||
cond_var_wait_rw_r(stripe->cv, stripe->rw_mutex, endt_us);
|
||||
}
|
||||
}
|
||||
scratch_end(scratch);
|
||||
@@ -740,7 +740,7 @@ di_search_items_from_key_params_query(DI_Scope *scope, U128 key, DI_SearchParams
|
||||
}
|
||||
|
||||
// rjf: no results, but have time to wait -> wait
|
||||
os_condition_variable_wait_rw_w(stripe->cv, stripe->rw_mutex, endt_us);
|
||||
cond_var_wait_rw_w(stripe->cv, stripe->rw_mutex, endt_us);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
@@ -770,11 +770,11 @@ di_u2p_enqueue_key(DI_Key *key, U64 endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(di_shared->u2p_ring_cv, di_shared->u2p_ring_mutex, endt_us);
|
||||
cond_var_wait(di_shared->u2p_ring_cv, di_shared->u2p_ring_mutex, endt_us);
|
||||
}
|
||||
if(sent)
|
||||
{
|
||||
os_condition_variable_broadcast(di_shared->u2p_ring_cv);
|
||||
cond_var_broadcast(di_shared->u2p_ring_cv);
|
||||
}
|
||||
return sent;
|
||||
}
|
||||
@@ -793,9 +793,9 @@ di_u2p_dequeue_key(Arena *arena, DI_Key *out_key)
|
||||
di_shared->u2p_ring_read_pos += ring_read(di_shared->u2p_ring_base, di_shared->u2p_ring_size, di_shared->u2p_ring_read_pos, out_key->path.str, out_key->path.size);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(di_shared->u2p_ring_cv, di_shared->u2p_ring_mutex, max_U64);
|
||||
cond_var_wait(di_shared->u2p_ring_cv, di_shared->u2p_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(di_shared->u2p_ring_cv);
|
||||
cond_var_broadcast(di_shared->u2p_ring_cv);
|
||||
}
|
||||
|
||||
internal void
|
||||
@@ -813,9 +813,9 @@ di_p2u_push_event(DI_Event *event)
|
||||
di_shared->p2u_ring_write_pos += ring_write(di_shared->p2u_ring_base, di_shared->p2u_ring_size, di_shared->p2u_ring_write_pos, event->string.str, event->string.size);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(di_shared->p2u_ring_cv, di_shared->p2u_ring_mutex, max_U64);
|
||||
cond_var_wait(di_shared->p2u_ring_cv, di_shared->p2u_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(di_shared->p2u_ring_cv);
|
||||
cond_var_broadcast(di_shared->p2u_ring_cv);
|
||||
}
|
||||
|
||||
internal DI_EventList
|
||||
@@ -839,9 +839,9 @@ di_p2u_pop_events(Arena *arena, U64 endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(di_shared->p2u_ring_cv, di_shared->p2u_ring_mutex, endt_us);
|
||||
cond_var_wait(di_shared->p2u_ring_cv, di_shared->p2u_ring_mutex, endt_us);
|
||||
}
|
||||
os_condition_variable_broadcast(di_shared->p2u_ring_cv);
|
||||
cond_var_broadcast(di_shared->p2u_ring_cv);
|
||||
return events;
|
||||
}
|
||||
|
||||
@@ -1136,7 +1136,7 @@ ASYNC_WORK_DEF(di_parse_work)
|
||||
os_file_close(file);
|
||||
}
|
||||
}
|
||||
os_condition_variable_broadcast(stripe->cv);
|
||||
cond_var_broadcast(stripe->cv);
|
||||
|
||||
scratch_end(scratch);
|
||||
ProfEnd();
|
||||
@@ -1167,11 +1167,11 @@ di_u2s_enqueue_req(U128 key, U64 endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(thread->ring_cv, thread->ring_mutex, endt_us);
|
||||
cond_var_wait(thread->ring_cv, thread->ring_mutex, endt_us);
|
||||
}
|
||||
if(result)
|
||||
{
|
||||
os_condition_variable_broadcast(thread->ring_cv);
|
||||
cond_var_broadcast(thread->ring_cv);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1189,9 +1189,9 @@ di_u2s_dequeue_req(U64 thread_idx)
|
||||
thread->ring_read_pos += ring_read_struct(thread->ring_base, thread->ring_size, thread->ring_read_pos, &key);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(thread->ring_cv, thread->ring_mutex, max_U64);
|
||||
cond_var_wait(thread->ring_cv, thread->ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(thread->ring_cv);
|
||||
cond_var_broadcast(thread->ring_cv);
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -1541,7 +1541,7 @@ di_search_thread__entry_point(void *p)
|
||||
}
|
||||
if(found && !done)
|
||||
{
|
||||
os_condition_variable_wait_rw_w(stripe->cv, stripe->rw_mutex, os_now_microseconds()+1000);
|
||||
cond_var_wait_rw_w(stripe->cv, stripe->rw_mutex, os_now_microseconds()+1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1610,17 +1610,17 @@ di_match_store_alloc(void)
|
||||
store->gen_arenas[idx] = arena_alloc();
|
||||
}
|
||||
store->params_arena = arena_alloc();
|
||||
store->params_rw_mutex = os_rw_mutex_alloc();
|
||||
store->params_rw_mutex = rw_mutex_alloc();
|
||||
store->match_name_slots_count = 4096;
|
||||
store->match_name_slots = push_array(arena, DI_MatchNameSlot, store->match_name_slots_count);
|
||||
store->match_rw_mutex = os_rw_mutex_alloc();
|
||||
store->match_cv = os_condition_variable_alloc();
|
||||
store->u2m_ring_cv = os_condition_variable_alloc();
|
||||
store->u2m_ring_mutex = os_mutex_alloc();
|
||||
store->match_rw_mutex = rw_mutex_alloc();
|
||||
store->match_cv = cond_var_alloc();
|
||||
store->u2m_ring_cv = cond_var_alloc();
|
||||
store->u2m_ring_mutex = mutex_alloc();
|
||||
store->u2m_ring_size = KB(2);
|
||||
store->u2m_ring_base = push_array_no_zero(arena, U8, store->u2m_ring_size);
|
||||
store->m2u_ring_cv = os_condition_variable_alloc();
|
||||
store->m2u_ring_mutex = os_mutex_alloc();
|
||||
store->m2u_ring_cv = cond_var_alloc();
|
||||
store->m2u_ring_mutex = mutex_alloc();
|
||||
store->m2u_ring_size = KB(2);
|
||||
store->m2u_ring_base = push_array_no_zero(arena, U8, store->m2u_ring_size);
|
||||
return store;
|
||||
@@ -1756,11 +1756,11 @@ di_match_from_name(DI_MatchStore *store, String8 name, U64 endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(store->u2m_ring_cv, store->u2m_ring_mutex, endt_us);
|
||||
cond_var_wait(store->u2m_ring_cv, store->u2m_ring_mutex, endt_us);
|
||||
}
|
||||
if(sent)
|
||||
{
|
||||
os_condition_variable_broadcast(store->u2m_ring_cv);
|
||||
cond_var_broadcast(store->u2m_ring_cv);
|
||||
async_push_work(di_match_work, .input = store, .priority = ASYNC_Priority_Low, .completion_counter = &node->cmp_count);
|
||||
node->req_params_hash = store->params_hash;
|
||||
node->req_count += 1;
|
||||
@@ -1780,7 +1780,7 @@ di_match_from_name(DI_MatchStore *store, String8 name, U64 endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait_rw_r(store->match_cv, store->match_rw_mutex, endt_us);
|
||||
cond_var_wait_rw_r(store->match_cv, store->match_rw_mutex, endt_us);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1817,9 +1817,9 @@ ASYNC_WORK_DEF(di_match_work)
|
||||
store->u2m_ring_read_pos += ring_read(store->u2m_ring_base, store->u2m_ring_size, store->u2m_ring_read_pos, name.str, name.size);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(store->u2m_ring_cv, store->u2m_ring_mutex, max_U64);
|
||||
cond_var_wait(store->u2m_ring_cv, store->u2m_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(store->u2m_ring_cv);
|
||||
cond_var_broadcast(store->u2m_ring_cv);
|
||||
|
||||
//- rjf: read parameters
|
||||
U64 params_hash = 0;
|
||||
|
||||
+17
-17
@@ -121,8 +121,8 @@ struct DI_Stripe
|
||||
Arena *arena;
|
||||
DI_Node *free_node;
|
||||
DI_StringChunkNode *free_string_chunks[8];
|
||||
OS_Handle rw_mutex;
|
||||
OS_Handle cv;
|
||||
RWMutex rw_mutex;
|
||||
CondVar cv;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -206,8 +206,8 @@ struct DI_SearchStripe
|
||||
{
|
||||
Arena *arena;
|
||||
DI_SearchNode *free_node;
|
||||
OS_Handle rw_mutex;
|
||||
OS_Handle cv;
|
||||
RWMutex rw_mutex;
|
||||
CondVar cv;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -249,8 +249,8 @@ typedef struct DI_SearchThread DI_SearchThread;
|
||||
struct DI_SearchThread
|
||||
{
|
||||
OS_Handle thread;
|
||||
OS_Handle ring_mutex;
|
||||
OS_Handle ring_cv;
|
||||
Mutex ring_mutex;
|
||||
CondVar ring_cv;
|
||||
U64 ring_size;
|
||||
U8 *ring_base;
|
||||
U64 ring_write_pos;
|
||||
@@ -315,7 +315,7 @@ struct DI_MatchStore
|
||||
|
||||
// rjf: parameters
|
||||
Arena *params_arena;
|
||||
OS_Handle params_rw_mutex;
|
||||
RWMutex params_rw_mutex;
|
||||
U64 params_hash;
|
||||
DI_KeyArray params_keys;
|
||||
|
||||
@@ -327,20 +327,20 @@ struct DI_MatchStore
|
||||
DI_MatchNameNode *first_lru_match_name;
|
||||
DI_MatchNameNode *last_lru_match_name;
|
||||
U64 active_match_name_nodes_count;
|
||||
OS_Handle match_rw_mutex;
|
||||
OS_Handle match_cv;
|
||||
RWMutex match_rw_mutex;
|
||||
CondVar match_cv;
|
||||
|
||||
// rjf: user -> match work ring buffer
|
||||
OS_Handle u2m_ring_cv;
|
||||
OS_Handle u2m_ring_mutex;
|
||||
CondVar u2m_ring_cv;
|
||||
Mutex u2m_ring_mutex;
|
||||
U64 u2m_ring_size;
|
||||
U8 *u2m_ring_base;
|
||||
U64 u2m_ring_write_pos;
|
||||
U64 u2m_ring_read_pos;
|
||||
|
||||
// rjf: match -> user work ring buffer
|
||||
OS_Handle m2u_ring_cv;
|
||||
OS_Handle m2u_ring_mutex;
|
||||
CondVar m2u_ring_cv;
|
||||
Mutex m2u_ring_mutex;
|
||||
U64 m2u_ring_size;
|
||||
U8 *m2u_ring_base;
|
||||
U64 m2u_ring_write_pos;
|
||||
@@ -368,16 +368,16 @@ struct DI_Shared
|
||||
DI_SearchStripe *search_stripes;
|
||||
|
||||
// rjf: user -> parse ring
|
||||
OS_Handle u2p_ring_mutex;
|
||||
OS_Handle u2p_ring_cv;
|
||||
Mutex u2p_ring_mutex;
|
||||
CondVar u2p_ring_cv;
|
||||
U64 u2p_ring_size;
|
||||
U8 *u2p_ring_base;
|
||||
U64 u2p_ring_write_pos;
|
||||
U64 u2p_ring_read_pos;
|
||||
|
||||
// rjf: parse -> user event ring
|
||||
OS_Handle p2u_ring_mutex;
|
||||
OS_Handle p2u_ring_cv;
|
||||
Mutex p2u_ring_mutex;
|
||||
CondVar p2u_ring_cv;
|
||||
U64 p2u_ring_size;
|
||||
U8 *p2u_ring_base;
|
||||
U64 p2u_ring_write_pos;
|
||||
|
||||
@@ -905,7 +905,7 @@ dmn_init(void)
|
||||
dmn_lnx_state->entities_arena = arena_alloc(.reserve_size = GB(32), .commit_size = KB(64), .flags = ArenaFlag_NoChain);
|
||||
dmn_lnx_state->entities_base = push_array(dmn_lnx_state->entities_arena, DMN_LNX_Entity, 0);
|
||||
dmn_lnx_entity_alloc(&dmn_lnx_nil_entity, DMN_LNX_EntityKind_Root);
|
||||
dmn_lnx_state->access_mutex = os_mutex_alloc();
|
||||
dmn_lnx_state->access_mutex = mutex_alloc();
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -1649,7 +1649,7 @@ dmn_access_open(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
os_mutex_take(dmn_lnx_state->access_mutex);
|
||||
mutex_take(dmn_lnx_state->access_mutex);
|
||||
result = !dmn_lnx_state->access_run_state;
|
||||
}
|
||||
return result;
|
||||
@@ -1660,7 +1660,7 @@ dmn_access_close(void)
|
||||
{
|
||||
if(!dmn_lnx_ctrl_thread)
|
||||
{
|
||||
os_mutex_drop(dmn_lnx_state->access_mutex);
|
||||
mutex_drop(dmn_lnx_state->access_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1142,7 +1142,7 @@ dmn_init(void)
|
||||
Arena *arena = arena_alloc();
|
||||
dmn_w32_shared = push_array(arena, DMN_W32_Shared, 1);
|
||||
dmn_w32_shared->arena = arena;
|
||||
dmn_w32_shared->access_mutex = os_mutex_alloc();
|
||||
dmn_w32_shared->access_mutex = mutex_alloc();
|
||||
dmn_w32_shared->detach_arena = arena_alloc();
|
||||
dmn_w32_shared->entities_arena = arena_alloc(.reserve_size = GB(8), .commit_size = KB(64));
|
||||
dmn_w32_shared->entities_base = dmn_w32_entity_alloc(&dmn_w32_entity_nil, DMN_W32_EntityKind_Root, 0);
|
||||
@@ -2977,7 +2977,7 @@ dmn_access_open(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
os_mutex_take(dmn_w32_shared->access_mutex);
|
||||
mutex_take(dmn_w32_shared->access_mutex);
|
||||
result = !dmn_w32_shared->access_run_state;
|
||||
}
|
||||
return result;
|
||||
@@ -2988,7 +2988,7 @@ dmn_access_close(void)
|
||||
{
|
||||
if(!dmn_w32_ctrl_thread)
|
||||
{
|
||||
os_mutex_drop(dmn_w32_shared->access_mutex);
|
||||
mutex_drop(dmn_w32_shared->access_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ struct DMN_W32_Shared
|
||||
String8List env_strings;
|
||||
|
||||
// rjf: access locking mechanism
|
||||
OS_Handle access_mutex;
|
||||
Mutex access_mutex;
|
||||
B32 access_run_state;
|
||||
|
||||
// rjf: detaching info
|
||||
|
||||
@@ -514,7 +514,7 @@ e_type_key_cons_base(Type *type)
|
||||
if(type->flags & TypeFlag_IsPlainText){ flags |= E_TypeFlag_IsPlainText; }
|
||||
if(type->flags & TypeFlag_IsCodeText) { flags |= E_TypeFlag_IsCodeText; }
|
||||
if(type->flags & TypeFlag_IsPathText) { flags |= E_TypeFlag_IsPathText; }
|
||||
result = e_type_key_cons_ptr(arch_from_context(), direct_type, 1, flags);
|
||||
result = e_type_key_cons_ptr(Arch_CURRENT, direct_type, 1, flags);
|
||||
}break;
|
||||
case TypeKind_Array:
|
||||
{
|
||||
@@ -531,7 +531,7 @@ e_type_key_cons_base(Type *type)
|
||||
e_member_list_push_new(scratch.arena, &members, .name = type->members[idx].name, .off = type->members[idx].value, .type_key = member_type_key);
|
||||
}
|
||||
E_MemberArray members_array = e_member_array_from_list(scratch.arena, &members);
|
||||
result = e_type_key_cons(.arch = arch_from_context(),
|
||||
result = e_type_key_cons(.arch = Arch_CURRENT,
|
||||
.kind = E_TypeKind_Struct,
|
||||
.name = type->name,
|
||||
.members = members_array.v,
|
||||
|
||||
@@ -49,13 +49,13 @@ fs_init(void)
|
||||
for(U64 idx = 0; idx < fs_shared->stripes_count; idx += 1)
|
||||
{
|
||||
fs_shared->stripes[idx].arena = arena_alloc();
|
||||
fs_shared->stripes[idx].cv = os_condition_variable_alloc();
|
||||
fs_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
fs_shared->stripes[idx].cv = cond_var_alloc();
|
||||
fs_shared->stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
}
|
||||
fs_shared->u2s_ring_size = KB(64);
|
||||
fs_shared->u2s_ring_base = push_array_no_zero(arena, U8, fs_shared->u2s_ring_size);
|
||||
fs_shared->u2s_ring_cv = os_condition_variable_alloc();
|
||||
fs_shared->u2s_ring_mutex = os_mutex_alloc();
|
||||
fs_shared->u2s_ring_cv = cond_var_alloc();
|
||||
fs_shared->u2s_ring_mutex = mutex_alloc();
|
||||
fs_shared->detector_thread = os_thread_launch(fs_detector_thread__entry_point, 0, 0);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ fs_key_from_path_range(String8 path, Rng1U64 range, U64 endt_us)
|
||||
fs_u2s_enqueue_req(key, range, path, endt_us))
|
||||
{
|
||||
ins_atomic_u64_inc_eval(&range_node->working_count);
|
||||
DeferLoop(os_rw_mutex_drop_w(path_stripe->rw_mutex), os_rw_mutex_take_w(path_stripe->rw_mutex))
|
||||
DeferLoop(rw_mutex_drop_w(path_stripe->rw_mutex), rw_mutex_take_w(path_stripe->rw_mutex))
|
||||
{
|
||||
async_push_work(fs_stream_work, .working_counter = &range_node->working_count);
|
||||
}
|
||||
@@ -187,7 +187,7 @@ fs_key_from_path_range(String8 path, Rng1U64 range, U64 endt_us)
|
||||
B32 have_results = !u128_match(hs_hash_from_key(key, 0), u128_zero());
|
||||
if(!have_results && os_now_microseconds() < endt_us)
|
||||
{
|
||||
os_condition_variable_wait_rw_w(path_stripe->cv, path_stripe->rw_mutex, endt_us);
|
||||
cond_var_wait_rw_w(path_stripe->cv, path_stripe->rw_mutex, endt_us);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -267,11 +267,11 @@ fs_u2s_enqueue_req(HS_Key key, Rng1U64 range, String8 path, U64 endt_us)
|
||||
fs_shared->u2s_ring_write_pos += ring_write(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_write_pos, path.str, path.size);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(fs_shared->u2s_ring_cv, fs_shared->u2s_ring_mutex, endt_us);
|
||||
cond_var_wait(fs_shared->u2s_ring_cv, fs_shared->u2s_ring_mutex, endt_us);
|
||||
}
|
||||
if(result)
|
||||
{
|
||||
os_condition_variable_broadcast(fs_shared->u2s_ring_cv);
|
||||
cond_var_broadcast(fs_shared->u2s_ring_cv);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -292,9 +292,9 @@ fs_u2s_dequeue_req(Arena *arena, HS_Key *key_out, Rng1U64 *range_out, String8 *p
|
||||
fs_shared->u2s_ring_read_pos += ring_read(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_read_pos, path_out->str, path_out->size);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(fs_shared->u2s_ring_cv, fs_shared->u2s_ring_mutex, max_U64);
|
||||
cond_var_wait(fs_shared->u2s_ring_cv, fs_shared->u2s_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(fs_shared->u2s_ring_cv);
|
||||
cond_var_broadcast(fs_shared->u2s_ring_cv);
|
||||
}
|
||||
|
||||
ASYNC_WORK_DEF(fs_stream_work)
|
||||
@@ -379,7 +379,7 @@ ASYNC_WORK_DEF(fs_stream_work)
|
||||
node->props = post_props;
|
||||
}
|
||||
}
|
||||
os_condition_variable_broadcast(path_stripe->cv);
|
||||
cond_var_broadcast(path_stripe->cv);
|
||||
|
||||
ProfEnd();
|
||||
scratch_end(scratch);
|
||||
|
||||
@@ -50,8 +50,8 @@ typedef struct FS_Stripe FS_Stripe;
|
||||
struct FS_Stripe
|
||||
{
|
||||
Arena *arena;
|
||||
OS_Handle cv;
|
||||
OS_Handle rw_mutex;
|
||||
CondVar cv;
|
||||
RWMutex rw_mutex;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -74,8 +74,8 @@ struct FS_Shared
|
||||
U8 *u2s_ring_base;
|
||||
U64 u2s_ring_write_pos;
|
||||
U64 u2s_ring_read_pos;
|
||||
OS_Handle u2s_ring_cv;
|
||||
OS_Handle u2s_ring_mutex;
|
||||
CondVar u2s_ring_cv;
|
||||
Mutex u2s_ring_mutex;
|
||||
|
||||
// rjf: change detector threads
|
||||
OS_Handle detector_thread;
|
||||
|
||||
@@ -21,13 +21,13 @@ geo_init(void)
|
||||
for(U64 idx = 0; idx < geo_shared->stripes_count; idx += 1)
|
||||
{
|
||||
geo_shared->stripes[idx].arena = arena_alloc();
|
||||
geo_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
geo_shared->stripes[idx].cv = os_condition_variable_alloc();
|
||||
geo_shared->stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
geo_shared->stripes[idx].cv = cond_var_alloc();
|
||||
}
|
||||
geo_shared->u2x_ring_size = KB(64);
|
||||
geo_shared->u2x_ring_base = push_array_no_zero(arena, U8, geo_shared->u2x_ring_size);
|
||||
geo_shared->u2x_ring_cv = os_condition_variable_alloc();
|
||||
geo_shared->u2x_ring_mutex = os_mutex_alloc();
|
||||
geo_shared->u2x_ring_cv = cond_var_alloc();
|
||||
geo_shared->u2x_ring_mutex = mutex_alloc();
|
||||
geo_shared->evictor_thread = os_thread_launch(geo_evictor_thread__entry_point, 0, 0);
|
||||
}
|
||||
|
||||
@@ -217,11 +217,11 @@ geo_u2x_enqueue_req(U128 hash, U64 endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(geo_shared->u2x_ring_cv, geo_shared->u2x_ring_mutex, endt_us);
|
||||
cond_var_wait(geo_shared->u2x_ring_cv, geo_shared->u2x_ring_mutex, endt_us);
|
||||
}
|
||||
if(good)
|
||||
{
|
||||
os_condition_variable_broadcast(geo_shared->u2x_ring_cv);
|
||||
cond_var_broadcast(geo_shared->u2x_ring_cv);
|
||||
}
|
||||
return good;
|
||||
}
|
||||
@@ -237,9 +237,9 @@ geo_u2x_dequeue_req(U128 *hash_out)
|
||||
geo_shared->u2x_ring_read_pos += ring_read_struct(geo_shared->u2x_ring_base, geo_shared->u2x_ring_size, geo_shared->u2x_ring_read_pos, hash_out);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(geo_shared->u2x_ring_cv, geo_shared->u2x_ring_mutex, max_U64);
|
||||
cond_var_wait(geo_shared->u2x_ring_cv, geo_shared->u2x_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(geo_shared->u2x_ring_cv);
|
||||
cond_var_broadcast(geo_shared->u2x_ring_cv);
|
||||
}
|
||||
|
||||
ASYNC_WORK_DEF(geo_xfer_work)
|
||||
|
||||
@@ -32,8 +32,8 @@ typedef struct GEO_Stripe GEO_Stripe;
|
||||
struct GEO_Stripe
|
||||
{
|
||||
Arena *arena;
|
||||
OS_Handle rw_mutex;
|
||||
OS_Handle cv;
|
||||
RWMutex rw_mutex;
|
||||
CondVar cv;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -84,8 +84,8 @@ struct GEO_Shared
|
||||
U8 *u2x_ring_base;
|
||||
U64 u2x_ring_write_pos;
|
||||
U64 u2x_ring_read_pos;
|
||||
OS_Handle u2x_ring_cv;
|
||||
OS_Handle u2x_ring_mutex;
|
||||
CondVar u2x_ring_cv;
|
||||
Mutex u2x_ring_mutex;
|
||||
|
||||
// rjf: evictor thread
|
||||
OS_Handle evictor_thread;
|
||||
|
||||
@@ -76,8 +76,8 @@ hs_init(void)
|
||||
{
|
||||
HS_Stripe *stripe = &hs_shared->stripes[idx];
|
||||
stripe->arena = arena_alloc();
|
||||
stripe->rw_mutex = os_rw_mutex_alloc();
|
||||
stripe->cv = os_condition_variable_alloc();
|
||||
stripe->rw_mutex = rw_mutex_alloc();
|
||||
stripe->cv = cond_var_alloc();
|
||||
}
|
||||
hs_shared->key_slots_count = 4096;
|
||||
hs_shared->key_stripes_count = Min(hs_shared->key_slots_count, os_get_system_info()->logical_processor_count);
|
||||
@@ -88,8 +88,8 @@ hs_init(void)
|
||||
{
|
||||
HS_Stripe *stripe = &hs_shared->key_stripes[idx];
|
||||
stripe->arena = arena_alloc();
|
||||
stripe->rw_mutex = os_rw_mutex_alloc();
|
||||
stripe->cv = os_condition_variable_alloc();
|
||||
stripe->rw_mutex = rw_mutex_alloc();
|
||||
stripe->cv = cond_var_alloc();
|
||||
}
|
||||
hs_shared->root_slots_count = 4096;
|
||||
hs_shared->root_stripes_count = Min(hs_shared->root_slots_count, os_get_system_info()->logical_processor_count);
|
||||
@@ -100,8 +100,8 @@ hs_init(void)
|
||||
{
|
||||
HS_Stripe *stripe = &hs_shared->root_stripes[idx];
|
||||
stripe->arena = arena_alloc();
|
||||
stripe->rw_mutex = os_rw_mutex_alloc();
|
||||
stripe->cv = os_condition_variable_alloc();
|
||||
stripe->rw_mutex = rw_mutex_alloc();
|
||||
stripe->cv = cond_var_alloc();
|
||||
}
|
||||
hs_shared->evictor_thread = os_thread_launch(hs_evictor_thread__entry_point, 0, 0);
|
||||
}
|
||||
|
||||
@@ -145,8 +145,8 @@ typedef struct HS_Stripe HS_Stripe;
|
||||
struct HS_Stripe
|
||||
{
|
||||
Arena *arena;
|
||||
OS_Handle rw_mutex;
|
||||
OS_Handle cv;
|
||||
RWMutex rw_mutex;
|
||||
CondVar cv;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
@@ -20,7 +20,7 @@ mtx_init(void)
|
||||
for(U64 idx = 0; idx < mtx_shared->stripes_count; idx += 1)
|
||||
{
|
||||
mtx_shared->stripes[idx].arena = arena_alloc();
|
||||
mtx_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
mtx_shared->stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
}
|
||||
mtx_shared->mut_threads_count = Min(os_get_system_info()->logical_processor_count, 4);
|
||||
mtx_shared->mut_threads = push_array(arena, MTX_MutThread, mtx_shared->mut_threads_count);
|
||||
@@ -28,8 +28,8 @@ mtx_init(void)
|
||||
{
|
||||
mtx_shared->mut_threads[idx].ring_size = KB(64);
|
||||
mtx_shared->mut_threads[idx].ring_base = push_array_no_zero(arena, U8, mtx_shared->mut_threads[idx].ring_size);
|
||||
mtx_shared->mut_threads[idx].cv = os_condition_variable_alloc();
|
||||
mtx_shared->mut_threads[idx].mutex = os_mutex_alloc();
|
||||
mtx_shared->mut_threads[idx].cv = cond_var_alloc();
|
||||
mtx_shared->mut_threads[idx].mutex = mutex_alloc();
|
||||
mtx_shared->mut_threads[idx].thread = os_thread_launch(mtx_mut_thread__entry_point, &mtx_shared->mut_threads[idx], 0);
|
||||
}
|
||||
}
|
||||
@@ -65,9 +65,9 @@ mtx_enqueue_op(MTX_MutThread *thread, HS_Key buffer_key, MTX_Op op)
|
||||
thread->ring_write_pos += ring_write(thread->ring_base, thread->ring_size, thread->ring_write_pos, op.replace.str, op.replace.size);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(thread->cv, thread->mutex, max_U64);
|
||||
cond_var_wait(thread->cv, thread->mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(thread->cv);
|
||||
cond_var_broadcast(thread->cv);
|
||||
}
|
||||
|
||||
internal void
|
||||
@@ -85,9 +85,9 @@ mtx_dequeue_op(Arena *arena, MTX_MutThread *thread, HS_Key *buffer_key_out, MTX_
|
||||
thread->ring_read_pos += ring_read(thread->ring_base, thread->ring_size, thread->ring_read_pos, op_out->replace.str, op_out->replace.size);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(thread->cv, thread->mutex, max_U64);
|
||||
cond_var_wait(thread->cv, thread->mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(thread->cv);
|
||||
cond_var_broadcast(thread->cv);
|
||||
}
|
||||
|
||||
internal void
|
||||
|
||||
@@ -27,7 +27,7 @@ struct MTX_Stripe
|
||||
{
|
||||
Arena *arena;
|
||||
MTX_Node *free_node;
|
||||
OS_Handle rw_mutex;
|
||||
RWMutex rw_mutex;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -47,8 +47,8 @@ struct MTX_MutThread
|
||||
U8 *ring_base;
|
||||
U64 ring_read_pos;
|
||||
U64 ring_write_pos;
|
||||
OS_Handle cv;
|
||||
OS_Handle mutex;
|
||||
CondVar cv;
|
||||
Mutex mutex;
|
||||
OS_Handle thread;
|
||||
};
|
||||
|
||||
|
||||
@@ -945,7 +945,7 @@ os_rw_mutex_drop_w(OS_Handle rw_mutex)
|
||||
//- rjf: condition variables
|
||||
|
||||
internal OS_Handle
|
||||
os_condition_variable_alloc(void)
|
||||
os_cond_var_alloc(void)
|
||||
{
|
||||
OS_LNX_Entity *entity = os_lnx_entity_alloc(OS_LNX_EntityKind_ConditionVariable);
|
||||
int init_result = pthread_cond_init(&entity->cv.cond_handle, 0);
|
||||
@@ -970,7 +970,7 @@ os_condition_variable_alloc(void)
|
||||
}
|
||||
|
||||
internal void
|
||||
os_condition_variable_release(OS_Handle cv)
|
||||
os_cond_var_release(OS_Handle cv)
|
||||
{
|
||||
if(os_handle_match(cv, os_handle_zero())) { return; }
|
||||
OS_LNX_Entity *entity = (OS_LNX_Entity *)cv.u64[0];
|
||||
@@ -980,7 +980,7 @@ os_condition_variable_release(OS_Handle cv)
|
||||
}
|
||||
|
||||
internal B32
|
||||
os_condition_variable_wait(OS_Handle cv, OS_Handle mutex, U64 endt_us)
|
||||
os_cond_var_wait(OS_Handle cv, OS_Handle mutex, U64 endt_us)
|
||||
{
|
||||
if(os_handle_match(cv, os_handle_zero())) { return 0; }
|
||||
if(os_handle_match(mutex, os_handle_zero())) { return 0; }
|
||||
@@ -995,7 +995,7 @@ os_condition_variable_wait(OS_Handle cv, OS_Handle mutex, U64 endt_us)
|
||||
}
|
||||
|
||||
internal B32
|
||||
os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
|
||||
os_cond_var_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
|
||||
{
|
||||
// TODO(rjf): because pthread does not supply cv/rw natively, I had to hack
|
||||
// this together, but this would probably just be a lot better if we just
|
||||
@@ -1031,7 +1031,7 @@ os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
|
||||
}
|
||||
|
||||
internal B32
|
||||
os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
|
||||
os_cond_var_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
|
||||
{
|
||||
// TODO(rjf): because pthread does not supply cv/rw natively, I had to hack
|
||||
// this together, but this would probably just be a lot better if we just
|
||||
@@ -1067,7 +1067,7 @@ os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
|
||||
}
|
||||
|
||||
internal void
|
||||
os_condition_variable_signal(OS_Handle cv)
|
||||
os_cond_var_signal(OS_Handle cv)
|
||||
{
|
||||
if(os_handle_match(cv, os_handle_zero())) { return; }
|
||||
OS_LNX_Entity *cv_entity = (OS_LNX_Entity *)cv.u64[0];
|
||||
@@ -1075,7 +1075,7 @@ os_condition_variable_signal(OS_Handle cv)
|
||||
}
|
||||
|
||||
internal void
|
||||
os_condition_variable_broadcast(OS_Handle cv)
|
||||
os_cond_var_broadcast(OS_Handle cv)
|
||||
{
|
||||
if(os_handle_match(cv, os_handle_zero())) { return; }
|
||||
OS_LNX_Entity *cv_entity = (OS_LNX_Entity *)cv.u64[0];
|
||||
|
||||
@@ -1501,7 +1501,7 @@ os_rw_mutex_drop_w_(OS_Handle mutex)
|
||||
//- rjf: condition variables
|
||||
|
||||
internal OS_Handle
|
||||
os_condition_variable_alloc(void){
|
||||
os_cond_var_alloc(void){
|
||||
// entity
|
||||
LNX_Entity *entity = lnx_alloc_entity(LNX_EntityKind_ConditionVariable);
|
||||
|
||||
@@ -1521,7 +1521,7 @@ os_condition_variable_alloc(void){
|
||||
}
|
||||
|
||||
internal void
|
||||
os_condition_variable_release(OS_Handle cv){
|
||||
os_cond_var_release(OS_Handle cv){
|
||||
LNX_Entity *entity = (LNX_Entity*)PtrFromInt(cv.id);
|
||||
pthread_cond_destroy(&entity->cond);
|
||||
lnx_free_entity(entity);
|
||||
|
||||
+26
-26
@@ -270,41 +270,41 @@ internal void os_thread_detach(OS_Handle handle);
|
||||
//~ rjf: @os_hooks Synchronization Primitives (Implemented Per-OS)
|
||||
|
||||
//- rjf: recursive mutexes
|
||||
internal OS_Handle os_mutex_alloc(void);
|
||||
internal void os_mutex_release(OS_Handle mutex);
|
||||
internal void os_mutex_take(OS_Handle mutex);
|
||||
internal void os_mutex_drop(OS_Handle mutex);
|
||||
internal Mutex os_mutex_alloc(void);
|
||||
internal void os_mutex_release(Mutex mutex);
|
||||
internal void os_mutex_take(Mutex mutex);
|
||||
internal void os_mutex_drop(Mutex mutex);
|
||||
|
||||
//- rjf: reader/writer mutexes
|
||||
internal OS_Handle os_rw_mutex_alloc(void);
|
||||
internal void os_rw_mutex_release(OS_Handle rw_mutex);
|
||||
internal void os_rw_mutex_take_r(OS_Handle mutex);
|
||||
internal void os_rw_mutex_drop_r(OS_Handle mutex);
|
||||
internal void os_rw_mutex_take_w(OS_Handle mutex);
|
||||
internal void os_rw_mutex_drop_w(OS_Handle mutex);
|
||||
internal RWMutex os_rw_mutex_alloc(void);
|
||||
internal void os_rw_mutex_release(RWMutex mutex);
|
||||
internal void os_rw_mutex_take_r(RWMutex mutex);
|
||||
internal void os_rw_mutex_drop_r(RWMutex mutex);
|
||||
internal void os_rw_mutex_take_w(RWMutex mutex);
|
||||
internal void os_rw_mutex_drop_w(RWMutex mutex);
|
||||
|
||||
//- rjf: condition variables
|
||||
internal OS_Handle os_condition_variable_alloc(void);
|
||||
internal void os_condition_variable_release(OS_Handle cv);
|
||||
internal CondVar os_cond_var_alloc(void);
|
||||
internal void os_cond_var_release(CondVar cv);
|
||||
// returns false on timeout, true on signal, (max_wait_ms = max_U64) -> no timeout
|
||||
internal B32 os_condition_variable_wait(OS_Handle cv, OS_Handle mutex, U64 endt_us);
|
||||
internal B32 os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us);
|
||||
internal B32 os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us);
|
||||
internal void os_condition_variable_signal(OS_Handle cv);
|
||||
internal void os_condition_variable_broadcast(OS_Handle cv);
|
||||
internal B32 os_cond_var_wait(CondVar cv, Mutex mutex, U64 endt_us);
|
||||
internal B32 os_cond_var_wait_rw_r(CondVar cv, RWMutex mutex_rw, U64 endt_us);
|
||||
internal B32 os_cond_var_wait_rw_w(CondVar cv, RWMutex mutex_rw, U64 endt_us);
|
||||
internal void os_cond_var_signal(CondVar cv);
|
||||
internal void os_cond_var_broadcast(CondVar cv);
|
||||
|
||||
//- rjf: cross-process semaphores
|
||||
internal OS_Handle os_semaphore_alloc(U32 initial_count, U32 max_count, String8 name);
|
||||
internal void os_semaphore_release(OS_Handle semaphore);
|
||||
internal OS_Handle os_semaphore_open(String8 name);
|
||||
internal void os_semaphore_close(OS_Handle semaphore);
|
||||
internal B32 os_semaphore_take(OS_Handle semaphore, U64 endt_us);
|
||||
internal void os_semaphore_drop(OS_Handle semaphore);
|
||||
internal Semaphore os_semaphore_alloc(U32 initial_count, U32 max_count, String8 name);
|
||||
internal void os_semaphore_release(Semaphore semaphore);
|
||||
internal Semaphore os_semaphore_open(String8 name);
|
||||
internal void os_semaphore_close(Semaphore semaphore);
|
||||
internal B32 os_semaphore_take(Semaphore semaphore, U64 endt_us);
|
||||
internal void os_semaphore_drop(Semaphore semaphore);
|
||||
|
||||
//- rjf: barriers
|
||||
internal OS_Handle os_barrier_alloc(U64 count);
|
||||
internal void os_barrier_release(OS_Handle barrier);
|
||||
internal void os_barrier_wait(OS_Handle barrier);
|
||||
internal Barrier os_barrier_alloc(U64 count);
|
||||
internal void os_barrier_release(Barrier barrier);
|
||||
internal void os_barrier_wait(Barrier barrier);
|
||||
|
||||
//- rjf: scope macros
|
||||
#define OS_MutexScope(mutex) DeferLoop(os_mutex_take(mutex), os_mutex_drop(mutex))
|
||||
|
||||
@@ -1143,31 +1143,31 @@ os_thread_detach(OS_Handle thread)
|
||||
|
||||
//- rjf: mutexes
|
||||
|
||||
internal OS_Handle
|
||||
internal Mutex
|
||||
os_mutex_alloc(void)
|
||||
{
|
||||
OS_W32_Entity *entity = os_w32_entity_alloc(OS_W32_EntityKind_Mutex);
|
||||
InitializeCriticalSection(&entity->mutex);
|
||||
OS_Handle result = {IntFromPtr(entity)};
|
||||
Mutex result = {IntFromPtr(entity)};
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void
|
||||
os_mutex_release(OS_Handle mutex)
|
||||
os_mutex_release(Mutex mutex)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(mutex.u64[0]);
|
||||
os_w32_entity_release(entity);
|
||||
}
|
||||
|
||||
internal void
|
||||
os_mutex_take(OS_Handle mutex)
|
||||
os_mutex_take(Mutex mutex)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(mutex.u64[0]);
|
||||
EnterCriticalSection(&entity->mutex);
|
||||
}
|
||||
|
||||
internal void
|
||||
os_mutex_drop(OS_Handle mutex)
|
||||
os_mutex_drop(Mutex mutex)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(mutex.u64[0]);
|
||||
LeaveCriticalSection(&entity->mutex);
|
||||
@@ -1175,45 +1175,45 @@ os_mutex_drop(OS_Handle mutex)
|
||||
|
||||
//- rjf: reader/writer mutexes
|
||||
|
||||
internal OS_Handle
|
||||
internal RWMutex
|
||||
os_rw_mutex_alloc(void)
|
||||
{
|
||||
OS_W32_Entity *entity = os_w32_entity_alloc(OS_W32_EntityKind_RWMutex);
|
||||
InitializeSRWLock(&entity->rw_mutex);
|
||||
OS_Handle result = {IntFromPtr(entity)};
|
||||
RWMutex result = {IntFromPtr(entity)};
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void
|
||||
os_rw_mutex_release(OS_Handle rw_mutex)
|
||||
os_rw_mutex_release(RWMutex rw_mutex)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(rw_mutex.u64[0]);
|
||||
os_w32_entity_release(entity);
|
||||
}
|
||||
|
||||
internal void
|
||||
os_rw_mutex_take_r(OS_Handle rw_mutex)
|
||||
os_rw_mutex_take_r(RWMutex rw_mutex)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(rw_mutex.u64[0]);
|
||||
AcquireSRWLockShared(&entity->rw_mutex);
|
||||
}
|
||||
|
||||
internal void
|
||||
os_rw_mutex_drop_r(OS_Handle rw_mutex)
|
||||
os_rw_mutex_drop_r(RWMutex rw_mutex)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(rw_mutex.u64[0]);
|
||||
ReleaseSRWLockShared(&entity->rw_mutex);
|
||||
}
|
||||
|
||||
internal void
|
||||
os_rw_mutex_take_w(OS_Handle rw_mutex)
|
||||
os_rw_mutex_take_w(RWMutex rw_mutex)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(rw_mutex.u64[0]);
|
||||
AcquireSRWLockExclusive(&entity->rw_mutex);
|
||||
}
|
||||
|
||||
internal void
|
||||
os_rw_mutex_drop_w(OS_Handle rw_mutex)
|
||||
os_rw_mutex_drop_w(RWMutex rw_mutex)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(rw_mutex.u64[0]);
|
||||
ReleaseSRWLockExclusive(&entity->rw_mutex);
|
||||
@@ -1221,24 +1221,24 @@ os_rw_mutex_drop_w(OS_Handle rw_mutex)
|
||||
|
||||
//- rjf: condition variables
|
||||
|
||||
internal OS_Handle
|
||||
os_condition_variable_alloc(void)
|
||||
internal CondVar
|
||||
os_cond_var_alloc(void)
|
||||
{
|
||||
OS_W32_Entity *entity = os_w32_entity_alloc(OS_W32_EntityKind_ConditionVariable);
|
||||
InitializeConditionVariable(&entity->cv);
|
||||
OS_Handle result = {IntFromPtr(entity)};
|
||||
CondVar result = {IntFromPtr(entity)};
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void
|
||||
os_condition_variable_release(OS_Handle cv)
|
||||
os_cond_var_release(CondVar cv)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(cv.u64[0]);
|
||||
os_w32_entity_release(entity);
|
||||
}
|
||||
|
||||
internal B32
|
||||
os_condition_variable_wait(OS_Handle cv, OS_Handle mutex, U64 endt_us)
|
||||
os_cond_var_wait(CondVar cv, Mutex mutex, U64 endt_us)
|
||||
{
|
||||
U32 sleep_ms = os_w32_sleep_ms_from_endt_us(endt_us);
|
||||
BOOL result = 0;
|
||||
@@ -1252,7 +1252,7 @@ os_condition_variable_wait(OS_Handle cv, OS_Handle mutex, U64 endt_us)
|
||||
}
|
||||
|
||||
internal B32
|
||||
os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
|
||||
os_cond_var_wait_rw_r(CondVar cv, RWMutex mutex_rw, U64 endt_us)
|
||||
{
|
||||
U32 sleep_ms = os_w32_sleep_ms_from_endt_us(endt_us);
|
||||
BOOL result = 0;
|
||||
@@ -1267,7 +1267,7 @@ os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
|
||||
}
|
||||
|
||||
internal B32
|
||||
os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
|
||||
os_cond_var_wait_rw_w(CondVar cv, RWMutex mutex_rw, U64 endt_us)
|
||||
{
|
||||
U32 sleep_ms = os_w32_sleep_ms_from_endt_us(endt_us);
|
||||
BOOL result = 0;
|
||||
@@ -1281,14 +1281,14 @@ os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
|
||||
}
|
||||
|
||||
internal void
|
||||
os_condition_variable_signal(OS_Handle cv)
|
||||
os_cond_var_signal(CondVar cv)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(cv.u64[0]);
|
||||
WakeConditionVariable(&entity->cv);
|
||||
}
|
||||
|
||||
internal void
|
||||
os_condition_variable_broadcast(OS_Handle cv)
|
||||
os_cond_var_broadcast(CondVar cv)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(cv.u64[0]);
|
||||
WakeAllConditionVariable(&entity->cv);
|
||||
@@ -1296,44 +1296,44 @@ os_condition_variable_broadcast(OS_Handle cv)
|
||||
|
||||
//- rjf: cross-process semaphores
|
||||
|
||||
internal OS_Handle
|
||||
internal Semaphore
|
||||
os_semaphore_alloc(U32 initial_count, U32 max_count, String8 name)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String16 name16 = str16_from_8(scratch.arena, name);
|
||||
HANDLE handle = CreateSemaphoreW(0, initial_count, max_count, (WCHAR *)name16.str);
|
||||
OS_Handle result = {(U64)handle};
|
||||
Semaphore result = {(U64)handle};
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void
|
||||
os_semaphore_release(OS_Handle semaphore)
|
||||
os_semaphore_release(Semaphore semaphore)
|
||||
{
|
||||
HANDLE handle = (HANDLE)semaphore.u64[0];
|
||||
CloseHandle(handle);
|
||||
}
|
||||
|
||||
internal OS_Handle
|
||||
internal Semaphore
|
||||
os_semaphore_open(String8 name)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String16 name16 = str16_from_8(scratch.arena, name);
|
||||
HANDLE handle = OpenSemaphoreW(SEMAPHORE_ALL_ACCESS , 0, (WCHAR *)name16.str);
|
||||
OS_Handle result = {(U64)handle};
|
||||
Semaphore result = {(U64)handle};
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void
|
||||
os_semaphore_close(OS_Handle semaphore)
|
||||
os_semaphore_close(Semaphore semaphore)
|
||||
{
|
||||
HANDLE handle = (HANDLE)semaphore.u64[0];
|
||||
CloseHandle(handle);
|
||||
}
|
||||
|
||||
internal B32
|
||||
os_semaphore_take(OS_Handle semaphore, U64 endt_us)
|
||||
os_semaphore_take(Semaphore semaphore, U64 endt_us)
|
||||
{
|
||||
U32 sleep_ms = os_w32_sleep_ms_from_endt_us(endt_us);
|
||||
HANDLE handle = (HANDLE)semaphore.u64[0];
|
||||
@@ -1343,7 +1343,7 @@ os_semaphore_take(OS_Handle semaphore, U64 endt_us)
|
||||
}
|
||||
|
||||
internal void
|
||||
os_semaphore_drop(OS_Handle semaphore)
|
||||
os_semaphore_drop(Semaphore semaphore)
|
||||
{
|
||||
HANDLE handle = (HANDLE)semaphore.u64[0];
|
||||
ReleaseSemaphore(handle, 1, 0);
|
||||
@@ -1351,17 +1351,17 @@ os_semaphore_drop(OS_Handle semaphore)
|
||||
|
||||
//- rjf: barriers
|
||||
|
||||
internal OS_Handle
|
||||
internal Barrier
|
||||
os_barrier_alloc(U64 count)
|
||||
{
|
||||
OS_W32_Entity *entity = os_w32_entity_alloc(OS_W32_EntityKind_Barrier);
|
||||
InitializeSynchronizationBarrier(&entity->sb, count, -1);
|
||||
OS_Handle result = {IntFromPtr(entity)};
|
||||
Barrier result = {IntFromPtr(entity)};
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void
|
||||
os_barrier_release(OS_Handle barrier)
|
||||
os_barrier_release(Barrier barrier)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(barrier.u64[0]);
|
||||
DeleteSynchronizationBarrier(&entity->sb);
|
||||
@@ -1369,7 +1369,7 @@ os_barrier_release(OS_Handle barrier)
|
||||
}
|
||||
|
||||
internal void
|
||||
os_barrier_wait(OS_Handle barrier)
|
||||
os_barrier_wait(Barrier barrier)
|
||||
{
|
||||
OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(barrier.u64[0]);
|
||||
EnterSynchronizationBarrier(&entity->sb, 0);
|
||||
|
||||
+23
-23
@@ -566,7 +566,7 @@ pe_bin_info_from_data(Arena *arena, String8 data)
|
||||
Assert(!"unable to read data directory");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// export virtual directory ranges
|
||||
data_dir_vranges = push_array(arena, Rng1U64, data_dir_count);
|
||||
for(U32 dir_idx = 0; dir_idx < data_dir_count; dir_idx += 1)
|
||||
@@ -582,7 +582,7 @@ pe_bin_info_from_data(Arena *arena, String8 data)
|
||||
Assert(!"unable to read data directory");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// export directory range
|
||||
data_dir_range = rng_1u64(optional_range.min + reported_data_dir_offset, optional_range.min + reported_data_dir_offset + data_dir_count * sizeof(PE_DataDirectory));
|
||||
}
|
||||
@@ -1009,18 +1009,18 @@ pe_parsed_imports_from_data(Arena *arena,
|
||||
{
|
||||
PE_ParsedImport *imports = 0;
|
||||
U64 import_count = 0;
|
||||
|
||||
|
||||
U64 name_table_foff = coff_foff_from_voff(sections, section_count, name_table_voff);
|
||||
String8 entries = str8_substr(raw_data, rng_1u64(name_table_foff, raw_data.size));
|
||||
if (is_pe32) {
|
||||
import_count = index_of_zero_u32((U32 *)entries.str, entries.size/sizeof(U32));
|
||||
if (import_count == max_U64) { import_count = 0; }
|
||||
imports = push_array(arena, PE_ParsedImport, import_count);
|
||||
|
||||
|
||||
for (U64 imp_idx = 0; imp_idx < import_count; imp_idx += 1) {
|
||||
U32 raw_entry = 0;
|
||||
str8_deserial_read_struct(entries, imp_idx*sizeof(raw_entry), &raw_entry);
|
||||
|
||||
|
||||
B32 is_ordinal = ExtractBit(raw_entry, 31);
|
||||
if (is_ordinal) {
|
||||
// fill out ordinal import
|
||||
@@ -1048,11 +1048,11 @@ pe_parsed_imports_from_data(Arena *arena,
|
||||
import_count = index_of_zero_u64((U64 *)entries.str, entries.size/sizeof(U64));
|
||||
if (import_count == max_U64) { import_count = 0; }
|
||||
imports = push_array(arena, PE_ParsedImport, import_count);
|
||||
|
||||
|
||||
for (U64 imp_idx = 0; imp_idx < import_count; imp_idx += 1) {
|
||||
U64 raw_entry = 0;
|
||||
str8_deserial_read_struct(entries, imp_idx*sizeof(raw_entry), &raw_entry);
|
||||
|
||||
|
||||
B32 is_ordinal = ExtractBit(raw_entry, 63);
|
||||
if (is_ordinal) {
|
||||
// fill out ordinal import
|
||||
@@ -1215,7 +1215,7 @@ pe_delay_imports_from_data(Arena *arena,
|
||||
raw_dll->name_table_voff,
|
||||
&import_count);
|
||||
|
||||
|
||||
|
||||
// parse bound table
|
||||
Rng1U64 bound_table_range = {0};
|
||||
if (raw_dll->bound_table_voff) {
|
||||
@@ -1224,7 +1224,7 @@ pe_delay_imports_from_data(Arena *arena,
|
||||
}
|
||||
U64 bound_table_count;
|
||||
U64 *bound_table = pe_array_from_null_term_addr(arena, is_pe32, raw_data, bound_table_range, &bound_table_count);
|
||||
|
||||
|
||||
// parse unload table
|
||||
Rng1U64 unload_table_range = {0};
|
||||
if (raw_dll->unload_table_voff) {
|
||||
@@ -1233,7 +1233,7 @@ pe_delay_imports_from_data(Arena *arena,
|
||||
}
|
||||
U64 unload_table_count;
|
||||
U64 *unload_table = pe_array_from_null_term_addr(arena, is_pe32, raw_data, unload_table_range, &unload_table_count);
|
||||
|
||||
|
||||
// fill out DLL
|
||||
PE_ParsedDelayDLLImport *dll = dlls+dll_idx;
|
||||
dll->attributes = raw_dll->attributes;
|
||||
@@ -1782,12 +1782,12 @@ pe_has_plus_header(COFF_MachineType machine)
|
||||
{
|
||||
B32 has_plus_header = 0;
|
||||
switch (machine) {
|
||||
case COFF_MachineType_X86: {
|
||||
has_plus_header = 0;
|
||||
} break;
|
||||
case COFF_MachineType_X64: {
|
||||
has_plus_header = 1;
|
||||
} break;
|
||||
case COFF_MachineType_X86: {
|
||||
has_plus_header = 0;
|
||||
} break;
|
||||
case COFF_MachineType_X64: {
|
||||
has_plus_header = 1;
|
||||
} break;
|
||||
}
|
||||
return has_plus_header;
|
||||
}
|
||||
@@ -1806,13 +1806,13 @@ pe_pdata_sort(COFF_MachineType machine, String8 raw_pdata)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
switch (machine) {
|
||||
case COFF_MachineType_Unknown: break;
|
||||
case COFF_MachineType_X86:
|
||||
case COFF_MachineType_X64: {
|
||||
U64 count = raw_pdata.size / sizeof(PE_IntelPdata);
|
||||
radsort((PE_IntelPdata *)raw_pdata.str, count, pe_pdata_is_before_x86_64);
|
||||
} break;
|
||||
default: { NotImplemented; } break;
|
||||
case COFF_MachineType_Unknown: break;
|
||||
case COFF_MachineType_X86:
|
||||
case COFF_MachineType_X64: {
|
||||
U64 count = raw_pdata.size / sizeof(PE_IntelPdata);
|
||||
radsort((PE_IntelPdata *)raw_pdata.str, count, pe_pdata_is_before_x86_64);
|
||||
} break;
|
||||
default: { NotImplemented; } break;
|
||||
}
|
||||
ProfEnd();
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ ptg_init(void)
|
||||
for(U64 idx = 0; idx < ptg_shared->stripes_count; idx += 1)
|
||||
{
|
||||
ptg_shared->stripes[idx].arena = arena_alloc();
|
||||
ptg_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
ptg_shared->stripes[idx].cv = os_condition_variable_alloc();
|
||||
ptg_shared->stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
ptg_shared->stripes[idx].cv = cond_var_alloc();
|
||||
}
|
||||
ptg_shared->u2b_ring_size = KB(64);
|
||||
ptg_shared->u2b_ring_base = push_array_no_zero(arena, U8, ptg_shared->u2b_ring_size);
|
||||
ptg_shared->u2b_ring_cv = os_condition_variable_alloc();
|
||||
ptg_shared->u2b_ring_mutex = os_mutex_alloc();
|
||||
ptg_shared->u2b_ring_cv = cond_var_alloc();
|
||||
ptg_shared->u2b_ring_mutex = mutex_alloc();
|
||||
ptg_shared->builder_thread_count = Clamp(1, os_get_system_info()->logical_processor_count-1, 4);
|
||||
ptg_shared->builder_threads = push_array(arena, OS_Handle, ptg_shared->builder_thread_count);
|
||||
for(U64 idx = 0; idx < ptg_shared->builder_thread_count; idx += 1)
|
||||
@@ -136,11 +136,11 @@ ptg_u2b_enqueue_req(PTG_Key *key, U64 endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(ptg_shared->u2b_ring_cv, ptg_shared->u2b_ring_mutex, endt_us);
|
||||
cond_var_wait(ptg_shared->u2b_ring_cv, ptg_shared->u2b_ring_mutex, endt_us);
|
||||
}
|
||||
if(good)
|
||||
{
|
||||
os_condition_variable_broadcast(ptg_shared->u2b_ring_cv);
|
||||
cond_var_broadcast(ptg_shared->u2b_ring_cv);
|
||||
}
|
||||
return good;
|
||||
}
|
||||
@@ -156,9 +156,9 @@ ptg_u2b_dequeue_req(PTG_Key *key_out)
|
||||
ptg_shared->u2b_ring_read_pos += ring_read_struct(ptg_shared->u2b_ring_base, ptg_shared->u2b_ring_size, ptg_shared->u2b_ring_read_pos, key_out);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(ptg_shared->u2b_ring_cv, ptg_shared->u2b_ring_mutex, max_U64);
|
||||
cond_var_wait(ptg_shared->u2b_ring_cv, ptg_shared->u2b_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(ptg_shared->u2b_ring_cv);
|
||||
cond_var_broadcast(ptg_shared->u2b_ring_cv);
|
||||
}
|
||||
|
||||
internal void
|
||||
|
||||
@@ -121,8 +121,8 @@ typedef struct PTG_GraphStripe PTG_GraphStripe;
|
||||
struct PTG_GraphStripe
|
||||
{
|
||||
Arena *arena;
|
||||
OS_Handle rw_mutex;
|
||||
OS_Handle cv;
|
||||
RWMutex rw_mutex;
|
||||
CondVar cv;
|
||||
PTG_GraphNode *free_node;
|
||||
};
|
||||
|
||||
@@ -176,8 +176,8 @@ struct PTG_Shared
|
||||
U8 *u2b_ring_base;
|
||||
U64 u2b_ring_write_pos;
|
||||
U64 u2b_ring_read_pos;
|
||||
OS_Handle u2b_ring_cv;
|
||||
OS_Handle u2b_ring_mutex;
|
||||
CondVar u2b_ring_cv;
|
||||
Mutex u2b_ring_mutex;
|
||||
|
||||
// rjf: builder threads
|
||||
U64 builder_thread_count;
|
||||
|
||||
@@ -5679,7 +5679,7 @@ rd_arch_from_eval(E_Eval eval)
|
||||
Arch arch = process->arch;
|
||||
if(arch == Arch_Null)
|
||||
{
|
||||
arch = arch_from_context();
|
||||
arch = Arch_CURRENT;
|
||||
}
|
||||
|
||||
// rjf: try arch arguments
|
||||
|
||||
+11
-11
@@ -335,17 +335,17 @@ struct IPCInfo
|
||||
//- rjf: IPC resources
|
||||
#define IPC_SHARED_MEMORY_BUFFER_SIZE MB(4)
|
||||
StaticAssert(IPC_SHARED_MEMORY_BUFFER_SIZE > sizeof(IPCInfo), ipc_buffer_size_requirement);
|
||||
global OS_Handle ipc_sender2main_signal_semaphore = {0};
|
||||
global OS_Handle ipc_sender2main_lock_semaphore = {0};
|
||||
global Semaphore ipc_sender2main_signal_semaphore = {0};
|
||||
global Semaphore ipc_sender2main_lock_semaphore = {0};
|
||||
global U8 *ipc_sender2main_shared_memory_base = 0;
|
||||
global OS_Handle ipc_main2sender_signal_semaphore = {0};
|
||||
global OS_Handle ipc_main2sender_lock_semaphore = {0};
|
||||
global Semaphore ipc_main2sender_signal_semaphore = {0};
|
||||
global Semaphore ipc_main2sender_lock_semaphore = {0};
|
||||
global U8 *ipc_main2sender_shared_memory_base = 0;
|
||||
global U8 ipc_s2m_ring_buffer[MB(4)] = {0};
|
||||
global U64 ipc_s2m_ring_write_pos = 0;
|
||||
global U64 ipc_s2m_ring_read_pos = 0;
|
||||
global OS_Handle ipc_s2m_ring_mutex = {0};
|
||||
global OS_Handle ipc_s2m_ring_cv = {0};
|
||||
global Mutex ipc_s2m_ring_mutex = {0};
|
||||
global CondVar ipc_s2m_ring_cv = {0};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: IPC Signaler Thread
|
||||
@@ -373,9 +373,9 @@ ipc_signaler_thread__entry_point(void *p)
|
||||
ipc_s2m_ring_write_pos += ring_write(ipc_s2m_ring_buffer, sizeof(ipc_s2m_ring_buffer), ipc_s2m_ring_write_pos, msg.str, msg.size);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(ipc_s2m_ring_cv, ipc_s2m_ring_mutex, max_U64);
|
||||
cond_var_wait(ipc_s2m_ring_cv, ipc_s2m_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(ipc_s2m_ring_cv);
|
||||
cond_var_broadcast(ipc_s2m_ring_cv);
|
||||
os_send_wakeup_event();
|
||||
ipc_info->msg_size = 0;
|
||||
os_semaphore_drop(ipc_sender2main_lock_semaphore);
|
||||
@@ -525,8 +525,8 @@ entry_point(CmdLine *cmd_line)
|
||||
ipc_main2sender_lock_semaphore = os_semaphore_alloc(1, 1, ipc_main2sender_lock_semaphore_name);
|
||||
|
||||
// rjf: set up ipc-receiver -> main thread ring buffer; launch signaler thread
|
||||
ipc_s2m_ring_mutex = os_mutex_alloc();
|
||||
ipc_s2m_ring_cv = os_condition_variable_alloc();
|
||||
ipc_s2m_ring_mutex = mutex_alloc();
|
||||
ipc_s2m_ring_cv = cond_var_alloc();
|
||||
IPCInfo *ipc_info = (IPCInfo *)ipc_sender2main_shared_memory_base;
|
||||
if(ipc_sender2main_shared_memory_base != 0)
|
||||
{
|
||||
@@ -562,7 +562,7 @@ entry_point(CmdLine *cmd_line)
|
||||
}
|
||||
if(consumed)
|
||||
{
|
||||
os_condition_variable_broadcast(ipc_s2m_ring_cv);
|
||||
cond_var_broadcast(ipc_s2m_ring_cv);
|
||||
}
|
||||
if(msg.size != 0)
|
||||
{
|
||||
|
||||
@@ -159,7 +159,7 @@ r_init(CmdLine *cmdln)
|
||||
Arena *arena = arena_alloc();
|
||||
r_d3d11_state = push_array(arena, R_D3D11_State, 1);
|
||||
r_d3d11_state->arena = arena;
|
||||
r_d3d11_state->device_rw_mutex = os_rw_mutex_alloc();
|
||||
r_d3d11_state->device_rw_mutex = rw_mutex_alloc();
|
||||
|
||||
//- rjf: create base device
|
||||
ProfBegin("create base device");
|
||||
|
||||
@@ -135,7 +135,7 @@ struct R_D3D11_State
|
||||
R_D3D11_Buffer *first_free_buffer;
|
||||
R_D3D11_Tex2D *first_to_free_tex2d;
|
||||
R_D3D11_Buffer *first_to_free_buffer;
|
||||
OS_Handle device_rw_mutex;
|
||||
RWMutex device_rw_mutex;
|
||||
|
||||
// rjf: base d3d11 objects
|
||||
ID3D11Device *base_device;
|
||||
|
||||
@@ -1607,13 +1607,13 @@ txt_init(void)
|
||||
for(U64 idx = 0; idx < txt_shared->stripes_count; idx += 1)
|
||||
{
|
||||
txt_shared->stripes[idx].arena = arena_alloc();
|
||||
txt_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
txt_shared->stripes[idx].cv = os_condition_variable_alloc();
|
||||
txt_shared->stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
txt_shared->stripes[idx].cv = cond_var_alloc();
|
||||
}
|
||||
txt_shared->u2p_ring_size = KB(64);
|
||||
txt_shared->u2p_ring_base = push_array_no_zero(arena, U8, txt_shared->u2p_ring_size);
|
||||
txt_shared->u2p_ring_cv = os_condition_variable_alloc();
|
||||
txt_shared->u2p_ring_mutex = os_mutex_alloc();
|
||||
txt_shared->u2p_ring_cv = cond_var_alloc();
|
||||
txt_shared->u2p_ring_mutex = mutex_alloc();
|
||||
txt_shared->evictor_thread = os_thread_launch(txt_evictor_thread__entry_point, 0, 0);
|
||||
}
|
||||
|
||||
@@ -2172,11 +2172,11 @@ txt_u2p_enqueue_req(U128 hash, TXT_LangKind lang, U64 endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(txt_shared->u2p_ring_cv, txt_shared->u2p_ring_mutex, endt_us);
|
||||
cond_var_wait(txt_shared->u2p_ring_cv, txt_shared->u2p_ring_mutex, endt_us);
|
||||
}
|
||||
if(good)
|
||||
{
|
||||
os_condition_variable_broadcast(txt_shared->u2p_ring_cv);
|
||||
cond_var_broadcast(txt_shared->u2p_ring_cv);
|
||||
}
|
||||
return good;
|
||||
}
|
||||
@@ -2193,9 +2193,9 @@ txt_u2p_dequeue_req(U128 *hash_out, TXT_LangKind *lang_out)
|
||||
txt_shared->u2p_ring_read_pos += ring_read_struct(txt_shared->u2p_ring_base, txt_shared->u2p_ring_size, txt_shared->u2p_ring_read_pos, lang_out);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(txt_shared->u2p_ring_cv, txt_shared->u2p_ring_mutex, max_U64);
|
||||
cond_var_wait(txt_shared->u2p_ring_cv, txt_shared->u2p_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(txt_shared->u2p_ring_cv);
|
||||
cond_var_broadcast(txt_shared->u2p_ring_cv);
|
||||
}
|
||||
|
||||
ASYNC_WORK_DEF(txt_parse_work)
|
||||
|
||||
@@ -192,8 +192,8 @@ typedef struct TXT_Stripe TXT_Stripe;
|
||||
struct TXT_Stripe
|
||||
{
|
||||
Arena *arena;
|
||||
OS_Handle rw_mutex;
|
||||
OS_Handle cv;
|
||||
RWMutex rw_mutex;
|
||||
CondVar cv;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -248,8 +248,8 @@ struct TXT_Shared
|
||||
U8 *u2p_ring_base;
|
||||
U64 u2p_ring_write_pos;
|
||||
U64 u2p_ring_read_pos;
|
||||
OS_Handle u2p_ring_cv;
|
||||
OS_Handle u2p_ring_mutex;
|
||||
CondVar u2p_ring_cv;
|
||||
Mutex u2p_ring_mutex;
|
||||
|
||||
// rjf: evictor thread
|
||||
OS_Handle evictor_thread;
|
||||
|
||||
@@ -34,13 +34,13 @@ tex_init(void)
|
||||
for(U64 idx = 0; idx < tex_shared->stripes_count; idx += 1)
|
||||
{
|
||||
tex_shared->stripes[idx].arena = arena_alloc();
|
||||
tex_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
tex_shared->stripes[idx].cv = os_condition_variable_alloc();
|
||||
tex_shared->stripes[idx].rw_mutex = rw_mutex_alloc();
|
||||
tex_shared->stripes[idx].cv = cond_var_alloc();
|
||||
}
|
||||
tex_shared->u2x_ring_size = KB(64);
|
||||
tex_shared->u2x_ring_base = push_array_no_zero(arena, U8, tex_shared->u2x_ring_size);
|
||||
tex_shared->u2x_ring_cv = os_condition_variable_alloc();
|
||||
tex_shared->u2x_ring_mutex = os_mutex_alloc();
|
||||
tex_shared->u2x_ring_cv = cond_var_alloc();
|
||||
tex_shared->u2x_ring_mutex = mutex_alloc();
|
||||
tex_shared->evictor_thread = os_thread_launch(tex_evictor_thread__entry_point, 0, 0);
|
||||
}
|
||||
|
||||
@@ -237,11 +237,11 @@ tex_u2x_enqueue_req(U128 hash, TEX_Topology top, U64 endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(tex_shared->u2x_ring_cv, tex_shared->u2x_ring_mutex, endt_us);
|
||||
cond_var_wait(tex_shared->u2x_ring_cv, tex_shared->u2x_ring_mutex, endt_us);
|
||||
}
|
||||
if(good)
|
||||
{
|
||||
os_condition_variable_broadcast(tex_shared->u2x_ring_cv);
|
||||
cond_var_broadcast(tex_shared->u2x_ring_cv);
|
||||
}
|
||||
return good;
|
||||
}
|
||||
@@ -258,9 +258,9 @@ tex_u2x_dequeue_req(U128 *hash_out, TEX_Topology *top_out)
|
||||
tex_shared->u2x_ring_read_pos += ring_read_struct(tex_shared->u2x_ring_base, tex_shared->u2x_ring_size, tex_shared->u2x_ring_read_pos, top_out);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(tex_shared->u2x_ring_cv, tex_shared->u2x_ring_mutex, max_U64);
|
||||
cond_var_wait(tex_shared->u2x_ring_cv, tex_shared->u2x_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(tex_shared->u2x_ring_cv);
|
||||
cond_var_broadcast(tex_shared->u2x_ring_cv);
|
||||
}
|
||||
|
||||
ASYNC_WORK_DEF(tex_xfer_work)
|
||||
|
||||
@@ -43,8 +43,8 @@ typedef struct TEX_Stripe TEX_Stripe;
|
||||
struct TEX_Stripe
|
||||
{
|
||||
Arena *arena;
|
||||
OS_Handle rw_mutex;
|
||||
OS_Handle cv;
|
||||
RWMutex rw_mutex;
|
||||
CondVar cv;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -96,8 +96,8 @@ struct TEX_Shared
|
||||
U8 *u2x_ring_base;
|
||||
U64 u2x_ring_write_pos;
|
||||
U64 u2x_ring_read_pos;
|
||||
OS_Handle u2x_ring_cv;
|
||||
OS_Handle u2x_ring_mutex;
|
||||
CondVar u2x_ring_cv;
|
||||
Mutex u2x_ring_mutex;
|
||||
|
||||
// rjf: evictor thread
|
||||
OS_Handle evictor_thread;
|
||||
|
||||
Reference in New Issue
Block a user