Replace C++ thread module with C implementation and update build/tests#3
Open
ggeier wants to merge 1 commit into
Open
Replace C++ thread module with C implementation and update build/tests#3ggeier wants to merge 1 commit into
ggeier wants to merge 1 commit into
Conversation
### Motivation - Replace the C++ implementation that used `std::vector` and C++-specific constructs with a C implementation to avoid C++ dependency and simplify integration. - Ensure thread-local state and per-thread writer/stack management are implemented in plain C for compatibility with the rest of the codebase. - Update the build to compile the new C source instead of the removed C++ file. ### Description - Added `src/thread.c` which implements per-thread state, a manual dynamic stack (`coldtrace_stack`), writer integration, and thread lifecycle helpers (`coldtrace_thread_init`, `coldtrace_thread_fini`, `coldtrace_thread_append`, stack push/pop, and create index getters/setters`). - Implemented stack growth and safety checks with `coldtrace_stack_reserve_`, `coldtrace_stack_push_`, and `coldtrace_stack_pop_`, and replaced C++ memory management with `malloc`/`free`/`memcpy` and `log_fatal` on allocation failures. - Replaced `src/thread.cpp` with the new `src/thread.c` in `src/CMakeLists.txt` so the project builds the C implementation instead of the C++ source. - Preserved the external API and added a weak `coldtrace_main_thread_fini` placeholder to match previous behavior. ### Testing - Configured and built the project with `cmake -S . -B build` and `cmake --build build`, and the build completed successfully. - Ran the test suite with `ctest --test-dir build` and all automated tests passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
mempoolallocator and explicit stack management for portability and smaller runtime dependencies.Description
src/CMakeLists.txtto replacethread.cppwiththread.cin the build sources.src/thread.cwhich implementsstruct coldtrace_threadand acoldtrace_stackbacked bymempool_alloc, and provides the thread APIscoldtrace_thread_append,coldtrace_thread_init,coldtrace_thread_fini,coldtrace_thread_set_create_idx,coldtrace_thread_get_create_idx,coldtrace_thread_stack_push,coldtrace_thread_stack_pop, and a weakcoldtrace_main_thread_fini.src/thread.cppand replacedstd::vectorusage with manual reserve/push/pop andmempoolmemory management.mempool_freewith a null check intest/checkers/indexes_checker.c, adjustedINVALID_INDEXdefine formatting, and updated severaltest/*.cexpected-trace assertions fromEXPECT_ENTRYtoEXPECT_SOME/EXPECT_SOME_SIZEto match the new allocation/observation behavior.Testing
test/includingtrace_calloc,trace_memcpy,trace_pthread_mutex_clocklock,trace_read_write_range, andtrace_read_write_size, and the checkertest/checkers/indexes_checker.cas part of the test suite; all tests passed.CMakeLists.txtand verified the newthread.ccompiles into the object library successfully.Codex Task