artifact cache cancellation mutex -> semaphore (fixes cancellation thread on linux - we cannot take/drop across threads with mutexes); flip no_meta -> meta

This commit is contained in:
Ryan Fleury
2025-11-07 15:47:15 -08:00
parent 85778910c6
commit 4ea3c5a0e4
5 changed files with 32 additions and 39 deletions
+2 -2
View File
@@ -53,9 +53,9 @@ mkdir -p build
mkdir -p local mkdir -p local
# --- Build & Run Metaprogram ------------------------------------------------- # --- Build & Run Metaprogram -------------------------------------------------
if [ -v no_meta ]; then echo "[skipping metagen]"; fi if [ ! -v meta ]
if [ ! -v no_meta ]
then then
echo "[doing metagen]"
cd build cd build
$compile_debug ../src/metagen/metagen_main.c $compile_link $out metagen $compile_debug ../src/metagen/metagen_main.c $compile_link $out metagen
./metagen ./metagen
+5 -5
View File
@@ -19,8 +19,7 @@ ac_init(void)
ac_shared->req_batches[idx].arena = arena_alloc(); ac_shared->req_batches[idx].arena = arena_alloc();
} }
ac_shared->cancel_thread = thread_launch(ac_cancel_thread_entry_point, 0); ac_shared->cancel_thread = thread_launch(ac_cancel_thread_entry_point, 0);
ac_shared->cancel_thread_mutex = mutex_alloc(); ac_shared->cancel_thread_semaphore = semaphore_alloc(0, 1, str8_zero());
mutex_take(ac_shared->cancel_thread_mutex);
} }
//////////////////////////////// ////////////////////////////////
@@ -218,7 +217,7 @@ ac_async_tick(void)
// //
if(lane_idx() == 0) if(lane_idx() == 0)
{ {
mutex_drop(ac_shared->cancel_thread_mutex); semaphore_drop(ac_shared->cancel_thread_semaphore);
} }
////////////////////////////// //////////////////////////////
@@ -590,7 +589,7 @@ ac_async_tick(void)
// //
if(lane_idx() == 0) if(lane_idx() == 0)
{ {
mutex_take(ac_shared->cancel_thread_mutex); semaphore_take(ac_shared->cancel_thread_semaphore, max_U64);
} }
scratch_end(scratch); scratch_end(scratch);
} }
@@ -604,7 +603,7 @@ ac_cancel_thread_entry_point(void *p)
for(;;) for(;;)
{ {
os_sleep_milliseconds(50); os_sleep_milliseconds(50);
MutexScope(ac_shared->cancel_thread_mutex) semaphore_take(ac_shared->cancel_thread_semaphore, max_U64);
{ {
for EachIndex(cache_slot_idx, ac_shared->cache_slots_count) for EachIndex(cache_slot_idx, ac_shared->cache_slots_count)
{ {
@@ -650,5 +649,6 @@ ac_cancel_thread_entry_point(void *p)
} }
} }
} }
semaphore_drop(ac_shared->cancel_thread_semaphore);
} }
} }
+1 -1
View File
@@ -129,7 +129,7 @@ struct AC_Shared
// rjf: cancel thread // rjf: cancel thread
Thread cancel_thread; Thread cancel_thread;
Mutex cancel_thread_mutex; Semaphore cancel_thread_semaphore;
}; };
//////////////////////////////// ////////////////////////////////
-3
View File
@@ -57,9 +57,6 @@ main_thread_base_entry_point(int arguments_count, char **arguments)
#if defined(ARTIFACT_CACHE_H) && !defined(AC_INIT_MANUAL) #if defined(ARTIFACT_CACHE_H) && !defined(AC_INIT_MANUAL)
ac_init(); ac_init();
#endif #endif
#if defined(ASYNC_H) && !defined(ASYNC_INIT_MANUAL)
async_init(&cmdline);
#endif
#if defined(CONTENT_H) && !defined(C_INIT_MANUAL) #if defined(CONTENT_H) && !defined(C_INIT_MANUAL)
c_init(); c_init();
#endif #endif
+24 -28
View File
@@ -771,7 +771,7 @@ internal OS_Handle
os_process_launch(OS_ProcessLaunchParams *params) os_process_launch(OS_ProcessLaunchParams *params)
{ {
OS_Handle handle = {0}; OS_Handle handle = {0};
posix_spawn_file_actions_t file_actions = {0}; posix_spawn_file_actions_t file_actions = {0};
int file_actions_init_code = posix_spawn_file_actions_init(&file_actions); int file_actions_init_code = posix_spawn_file_actions_init(&file_actions);
if(file_actions_init_code == 0) if(file_actions_init_code == 0)
@@ -779,33 +779,33 @@ os_process_launch(OS_ProcessLaunchParams *params)
// redirect STDOUT // redirect STDOUT
int stdout_code = posix_spawn_file_actions_adddup2(&file_actions, (int)params->stdout_file.u64[0], STDOUT_FILENO); int stdout_code = posix_spawn_file_actions_adddup2(&file_actions, (int)params->stdout_file.u64[0], STDOUT_FILENO);
Assert(stdout_code == 0); Assert(stdout_code == 0);
// redirect STDERR // redirect STDERR
int stderr_code = posix_spawn_file_actions_adddup2(&file_actions, (int)params->stderr_file.u64[0], STDERR_FILENO); int stderr_code = posix_spawn_file_actions_adddup2(&file_actions, (int)params->stderr_file.u64[0], STDERR_FILENO);
Assert(stderr_code == 0); Assert(stderr_code == 0);
// redirect STDIN // redirect STDIN
int stdin_code = posix_spawn_file_actions_adddup2(&file_actions, (int)params->stdin_file.u64[0], STDIN_FILENO); int stdin_code = posix_spawn_file_actions_adddup2(&file_actions, (int)params->stdin_file.u64[0], STDIN_FILENO);
Assert(stdin_code == 0); Assert(stdin_code == 0);
posix_spawnattr_t attr = {0}; posix_spawnattr_t attr = {0};
int attr_init_code = posix_spawnattr_init(&attr); int attr_init_code = posix_spawnattr_init(&attr);
if(attr_init_code == 0) if(attr_init_code == 0)
{ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
// package argv // package argv
char **argv = push_array(scratch.arena, char *, params->cmd_line.node_count + 1); char **argv = push_array(scratch.arena, char *, params->cmd_line.node_count + 1);
{ {
String8List l = str8_split_path(scratch.arena, params->path); String8List l = str8_split_path(scratch.arena, params->path);
str8_list_push(scratch.arena, &l, params->cmd_line.first->string); str8_list_push(scratch.arena, &l, params->cmd_line.first->string);
String8 path_to_exe = str8_path_list_join_by_style(scratch.arena, &l, PathStyle_SystemAbsolute); String8 path_to_exe = str8_path_list_join_by_style(scratch.arena, &l, PathStyle_SystemAbsolute);
argv[0] = (char *)path_to_exe.str; argv[0] = (char *)path_to_exe.str;
U64 arg_idx = 1; U64 arg_idx = 1;
for EachNode(n, String8Node, params->cmd_line.first->next) { argv[arg_idx++] = (char *)n->string.str; } for EachNode(n, String8Node, params->cmd_line.first->next) { argv[arg_idx++] = (char *)n->string.str; }
} }
// package envp // package envp
char **envp = 0; char **envp = 0;
if(params->inherit_env) if(params->inherit_env)
@@ -821,39 +821,39 @@ os_process_launch(OS_ProcessLaunchParams *params)
envp[env_idx] = (char *)n->string.str; envp[env_idx] = (char *)n->string.str;
} }
} }
if(params->debug_subprocesses) if(params->debug_subprocesses)
{ {
// not suported // not suported
InvalidPath; InvalidPath;
} }
if(!params->consoleless) if(!params->consoleless)
{ {
NotImplemented; NotImplemented;
} }
// spawn process // spawn process
pid_t pid = 0; pid_t pid = 0;
int spawn_code = posix_spawn(&pid, argv[0], &file_actions, &attr, argv, envp); int spawn_code = posix_spawn(&pid, argv[0], &file_actions, &attr, argv, envp);
if(spawn_code == 0) if(spawn_code == 0)
{ {
handle.u64[0] = (U64)pid; handle.u64[0] = (U64)pid;
} }
// clean up attributes // clean up attributes
int attr_destroy_code = posix_spawnattr_destroy(&attr); int attr_destroy_code = posix_spawnattr_destroy(&attr);
Assert(attr_destroy_code == 0); Assert(attr_destroy_code == 0);
scratch_end(scratch); scratch_end(scratch);
} }
// clean up file actions // clean up file actions
int file_actions_destroy_code = posix_spawn_file_actions_destroy(&file_actions); int file_actions_destroy_code = posix_spawn_file_actions_destroy(&file_actions);
Assert(file_actions_destroy_code == 0); Assert(file_actions_destroy_code == 0);
} }
return handle; return handle;
} }
@@ -867,7 +867,7 @@ os_process_join(OS_Handle handle, U64 endt_us, U64 *exit_code_out)
if(kill(pid, 0) >= 0) if(kill(pid, 0) >= 0)
{ {
result = (errno == ENOENT); result = (errno == ENOENT);
if(result) if(result)
{ {
int status; int status;
@@ -969,11 +969,7 @@ internal Mutex
os_mutex_alloc(void) os_mutex_alloc(void)
{ {
OS_LNX_Entity *entity = os_lnx_entity_alloc(OS_LNX_EntityKind_Mutex); OS_LNX_Entity *entity = os_lnx_entity_alloc(OS_LNX_EntityKind_Mutex);
pthread_mutexattr_t attr; int init_result = pthread_mutex_init(&entity->mutex_handle, 0);
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
int init_result = pthread_mutex_init(&entity->mutex_handle, &attr);
pthread_mutexattr_destroy(&attr);
if(init_result == -1) if(init_result == -1)
{ {
os_lnx_entity_release(entity); os_lnx_entity_release(entity);
@@ -1410,10 +1406,10 @@ lnx_signal_handler(int sig, siginfo_t *info, void *arg)
sleep(UINT32_MAX); sleep(UINT32_MAX);
} }
} }
local_persist void *ips[4096]; local_persist void *ips[4096];
int ips_count = backtrace(ips, ArrayCount(ips)); int ips_count = backtrace(ips, ArrayCount(ips));
fprintf(stderr, "A fatal signal was received: %s (%d). The process is terminating.\n", strsignal(sig), sig); fprintf(stderr, "A fatal signal was received: %s (%d). The process is terminating.\n", strsignal(sig), sig);
fprintf(stderr, "Create a new issue with this report at %s.\n\n", BUILD_ISSUES_LINK_STRING_LITERAL); fprintf(stderr, "Create a new issue with this report at %s.\n\n", BUILD_ISSUES_LINK_STRING_LITERAL);
fprintf(stderr, "Callstack:\n"); fprintf(stderr, "Callstack:\n");
@@ -1421,7 +1417,7 @@ lnx_signal_handler(int sig, siginfo_t *info, void *arg)
{ {
Dl_info info = {0}; Dl_info info = {0};
dladdr(ips[i], &info); dladdr(ips[i], &info);
char cmd[2048]; char cmd[2048];
snprintf(cmd, sizeof(cmd), "llvm-symbolizer --relative-address -f -e %s %lu", info.dli_fname, (unsigned long)ips[i] - (unsigned long)info.dli_fbase); snprintf(cmd, sizeof(cmd), "llvm-symbolizer --relative-address -f -e %s %lu", info.dli_fname, (unsigned long)ips[i] - (unsigned long)info.dli_fbase);
FILE *f = popen(cmd, "r"); FILE *f = popen(cmd, "r");
@@ -1435,12 +1431,12 @@ lnx_signal_handler(int sig, siginfo_t *info, void *arg)
String8 module = str8_skip_last_slash(str8_cstring(info.dli_fname)); String8 module = str8_skip_last_slash(str8_cstring(info.dli_fname));
String8 file = str8_skip_last_slash(str8_cstring_capped(file_name, file_name + sizeof(file_name))); String8 file = str8_skip_last_slash(str8_cstring_capped(file_name, file_name + sizeof(file_name)));
if(file.size > 0) file.size -= 1; if(file.size > 0) file.size -= 1;
B32 no_func = str8_match(func, str8_lit("??"), StringMatchFlag_RightSideSloppy); B32 no_func = str8_match(func, str8_lit("??"), StringMatchFlag_RightSideSloppy);
B32 no_file = str8_match(file, str8_lit("??"), StringMatchFlag_RightSideSloppy); B32 no_file = str8_match(file, str8_lit("??"), StringMatchFlag_RightSideSloppy);
if(no_func) { func = str8_zero(); } if(no_func) { func = str8_zero(); }
if(no_file) { file = str8_zero(); } if(no_file) { file = str8_zero(); }
fprintf(stderr, "%ld. [0x%016lx] %.*s%s%.*s %.*s\n", i+1, (unsigned long)ips[i], (int)module.size, module.str, (!no_func || !no_file) ? ", " : "", (int)func.size, func.str, (int)file.size, file.str); fprintf(stderr, "%ld. [0x%016lx] %.*s%s%.*s %.*s\n", i+1, (unsigned long)ips[i], (int)module.size, module.str, (!no_func || !no_file) ? ", " : "", (int)func.size, func.str, (int)file.size, file.str);
} }
pclose(f); pclose(f);
@@ -1451,7 +1447,7 @@ lnx_signal_handler(int sig, siginfo_t *info, void *arg)
} }
} }
fprintf(stderr, "\nVersion: %s%s\n\n", BUILD_VERSION_STRING_LITERAL, BUILD_GIT_HASH_STRING_LITERAL_APPEND); fprintf(stderr, "\nVersion: %s%s\n\n", BUILD_VERSION_STRING_LITERAL, BUILD_GIT_HASH_STRING_LITERAL_APPEND);
_exit(0); _exit(0);
} }
@@ -1470,7 +1466,7 @@ main(int argc, char **argv)
sigaction(SIGSEGV, &handler, NULL); sigaction(SIGSEGV, &handler, NULL);
sigaction(SIGQUIT, &handler, NULL); sigaction(SIGQUIT, &handler, NULL);
} }
//- rjf: set up OS layer //- rjf: set up OS layer
{ {
//- rjf: get statically-allocated system/process info //- rjf: get statically-allocated system/process info