mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-07-31 03:10:03 +00: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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user