Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions common/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "spall.h"
#endif

#include "thread_id.h"

#if defined(_AMD64_) || defined(__amd64__)
static double rdtsc_freq;
static uint64_t timer_start;
Expand Down Expand Up @@ -165,7 +167,7 @@ void cuikperf_thread_start(void) {
#if _WIN32
uint32_t tid = GetCurrentThreadId();
#else
uint32_t tid = pthread_self();
uint32_t tid = thread_id32();
#endif

if (profiling) {
Expand Down Expand Up @@ -201,7 +203,7 @@ void cuikperf_region_start(const char* label, const char* extra) {
#if _WIN32
uint32_t tid = GetCurrentThreadId();
#else
uint32_t tid = pthread_self();
uint32_t tid = thread_id32();
#endif

spall_buffer_begin_args(&ctx, &muh_buffer, label, strlen(label), extra, extra ? strlen(extra) : 0, nanos, tid, 0);
Expand All @@ -217,7 +219,7 @@ void cuikperf_region_start2(const char* label, size_t extra_len, const char* ext
#if _WIN32
uint32_t tid = GetCurrentThreadId();
#else
uint32_t tid = pthread_self();
uint32_t tid = thread_id32();
#endif

spall_buffer_begin_args(&ctx, &muh_buffer, label, strlen(label), extra, extra_len, nanos, tid, 0);
Expand All @@ -233,7 +235,7 @@ void cuikperf_region_end(void) {
#if _WIN32
uint32_t tid = GetCurrentThreadId();
#else
uint32_t tid = pthread_self();
uint32_t tid = thread_id32();
#endif

spall_buffer_end_ex(&ctx, &muh_buffer, nanos, tid, 0);
Expand Down
1 change: 1 addition & 0 deletions common/pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// https://github.com/colrdavidson/workpool/blob/main/pool.h
#include "pool.h"
#include <threads.h>
#include <pthread.h>

#ifdef ENABLE_TRACING
#include "spall_native_auto.h"
Expand Down
18 changes: 18 additions & 0 deletions common/thread_id.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <stdint.h>

#if defined(_WIN32)
#include <windows.h>
static inline uint32_t thread_id32(void) {
return (uint32_t)GetCurrentThreadId();
}
#else
#include <pthread.h>
#include <stdint.h>

static inline uint32_t thread_id32(void) {
uintptr_t p = (uintptr_t)pthread_self();
return (uint32_t)(p ^ (p >> 32));
}
#endif
29 changes: 28 additions & 1 deletion cuik_c/driver/driver_arg_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,33 @@ static once_flag arg_global_init = ONCE_FLAG_INIT;
static bool arg_global_init;
#endif

#ifndef DEBUGBREAK
#ifdef _WIN32
#if defined(_MSC_VER) || defined(__clang__)
#include <intrin.h>
#define DEBUGBREAK() __debugbreak()
#else
#include <windows.h>
#define DEBUGBREAK() DebugBreak()
#endif
#else
#if defined(__has_builtin)
#if __has_builtin(__builtin_debugtrap)
#define DEBUGBREAK() __builtin_debugtrap()
#elif __has_builtin(__builtin_trap)
#define DEBUGBREAK() __builtin_trap()
#else
#include <signal.h>
#define DEBUGBREAK() raise(SIGTRAP)
#endif
#else
#include <signal.h>
#define DEBUGBREAK() raise(SIGTRAP)
#endif
#endif
#endif


typedef struct {
const char* key;
void* val;
Expand Down Expand Up @@ -243,7 +270,7 @@ static void print_help(void) {
for (int j = len; j < round_up; j++) printf(" ");
printf("%s\n", options[i].desc);
}
__debugbreak();
DEBUGBREAK();

/*size_t split = 24;
for (int i = 1; i < ARG_DESC_COUNT; i++) {
Expand Down
2 changes: 1 addition & 1 deletion linker/linker.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void tb_linker_append_module(TB_Linker* l, TB_Module* m) {
#endif
}

static bool tb__linker_is_library_new(TB_Linker* l, const char* file_name) {
bool tb__linker_is_library_new(TB_Linker* l, const char* file_name) {
if (!linker_thread_init) {
linker_thread_init = true;
tb_arena_create(&linker_perm_arena, "LinkerPerm");
Expand Down