Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7680b4d
Added parallelization capabilities.
kilo52 Sep 5, 2026
435a105
Fixed native threading implementation for Windows.
kilo52 Sep 5, 2026
17f7326
Updated API docs about thread-safety.
kilo52 Sep 10, 2026
bb815c8
Added documentation to threading.h header.
kilo52 Sep 10, 2026
d77b6b7
Added RCN_NATIVE_HANDLE macro used in threading.
kilo52 Sep 10, 2026
a9eccc6
Renamed struct fields.
kilo52 Sep 10, 2026
46dff1d
Renamed thread locking and unlocking functions.
kilo52 Sep 10, 2026
f641492
Changed type of ThreadControl.abortRequested from plain bool to atomi…
kilo52 Sep 10, 2026
a16e381
Fixed compilation error for MSVC by enabling C11 atomics.
kilo52 Sep 10, 2026
2f73206
Fixed compilation error on Windows.
kilo52 Sep 10, 2026
7dc764b
Added -fprofile-update=atomic compile option when building with test …
kilo52 Sep 12, 2026
8b50da0
Renamed internal RcnThreadArg structs to NativeThreadArg and added docs.
kilo52 Sep 12, 2026
13fae2b
Renamed ThreadHandle.handle member to ThreadHandle.instance.
kilo52 Sep 12, 2026
a1340cf
Removed unnecessary null check and improved docs.
kilo52 Sep 12, 2026
99c9e7b
Renamed joinThread to waitForThread.
kilo52 Sep 12, 2026
aad257a
Added missing header.
kilo52 Sep 12, 2026
0fee7ec
Added missing header includes.
kilo52 Sep 12, 2026
9e89d87
Added assertions for the return status of the pthread_* family of fun…
kilo52 Sep 12, 2026
dccb79e
Refactored Windows threading implementation.
kilo52 Sep 12, 2026
eeae294
Fixed GCC compiler warning about unused status variable in release bu…
kilo52 Sep 13, 2026
1efc228
Improved Windows threading implementation.
kilo52 Sep 16, 2026
0be215d
Refactored error checking condition in processFileRange().
kilo52 Sep 16, 2026
4eefa97
Improved initThreadControl() to always explicitly initialize ThreadCo…
kilo52 Sep 16, 2026
cb3dd46
Refactored error handling of init code in parallelizeCount().
kilo52 Sep 16, 2026
6e5e8fa
Improved threading docs.
kilo52 Sep 16, 2026
618c07c
Reverted refactoring of error handling in parallelizeCount().
kilo52 Sep 16, 2026
599a8bc
Refactored checkIntermediateResultState() implementation.
kilo52 Sep 16, 2026
3fd3edb
Changed parallelizeCount() to return a RcnResultState instead of bool.
kilo52 Sep 16, 2026
c41dc36
Improved Windows threading implementation.
kilo52 Sep 16, 2026
d96b12b
Removed duplicate target_compile_options() call for MSVC.
kilo52 Sep 16, 2026
6544261
Removed testStatOptionsZeroInitLeavesMultiThreadingDisabled() test fu…
kilo52 Sep 16, 2026
48f89c0
Added functionality test for --no-parallelization option.
kilo52 Sep 16, 2026
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ include(cmake/TestUtil.cmake)
include(cmake/TestCoverageUtil.cmake)
include(cmake/SanitizerUtil.cmake)

find_package(Threads REQUIRED)

if(NOT DEFINED RECKON_DO_NOT_OVERWRITE_OUTPUT_DIRECTORY)
set_output_directories()
endif()
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.1-dev
1.9.0-dev
5 changes: 4 additions & 1 deletion cmake/TestCoverageUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ function(add_code_coverage target_name)
target_compile_options(
${target_name}
PRIVATE
-ftest-coverage -fprofile-arcs -fno-default-inline
-ftest-coverage
-fprofile-arcs
-fprofile-update=atomic
-fno-default-inline
$<$<COMPILE_LANGUAGE:CXX>:-fno-elide-constructors>
)
target_link_libraries(
Expand Down
13 changes: 13 additions & 0 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ target_sources(
"c/encoding.c"
"c/factories.c"
"c/fileio.c"
"c/threading.c"
"$<$<PLATFORM_ID:Linux>:${CMAKE_CURRENT_SOURCE_DIR}/c/linux/fileio.c>"
"$<$<PLATFORM_ID:Linux>:${CMAKE_CURRENT_SOURCE_DIR}/c/linux/threading.c>"
"$<$<PLATFORM_ID:Windows>:${CMAKE_CURRENT_SOURCE_DIR}/c/win32/fileio.c>"
"$<$<PLATFORM_ID:Windows>:${CMAKE_CURRENT_SOURCE_DIR}/c/win32/threading.c>"
"c/lang_c.c"
"c/lang_java.c"
"c/lang_python.c"
Expand Down Expand Up @@ -61,6 +64,7 @@ target_include_directories(
target_link_libraries(
${RECKON_TARGET_LIB_OBJ}
PUBLIC
Threads::Threads
${RECKON_DEPENDENCIES_LINK_TARGETS}
)

Expand Down Expand Up @@ -88,6 +92,14 @@ if("${RECKON_MAIN_LIB_TYPE}" STREQUAL "SHARED")
)
endif()

if(MSVC)
target_compile_options(
${RECKON_TARGET_LIB_OBJ}
PRIVATE
/experimental:c11atomics
)
endif()

enable_compiler_warnings(
${RECKON_TARGET_LIB_OBJ}
${RECKON_IGNORE_WARNINGS}
Expand Down Expand Up @@ -124,6 +136,7 @@ target_include_directories(
target_link_libraries(
${RECKON_TARGET_LIB}
PRIVATE
Threads::Threads
${RECKON_DEPENDENCIES_LINK_TARGETS}
)

Expand Down
9 changes: 9 additions & 0 deletions src/lib/c/evaluation.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ typedef struct Span {
size_t length;
} Span;

/**
* An indicator for a slice of an array.
* Has a start (inclusive) and an end (exclusive) index.
*/
typedef struct Slice {
size_t start;
size_t end;
} Slice;

/**
* Opaque context type used during node evaluation.
* Can be used by concrete `NodeVisitor` implementations to store
Expand Down
127 changes: 127 additions & 0 deletions src/lib/c/linux/threading.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Copyright (C) 2026 Raven Computing
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifdef __linux__

#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <unistd.h>
#include <assert.h>
#include <pthread.h>

#include "threading.h"

/**
* The argument passed to pthread_create()
*/
typedef struct NativeThreadArg {
ThreadRoutine routine;
ThreadWork* arg;
} NativeThreadArg;

/**
* The start routine passed to pthread_create()
*/
static void* rcnRun(void* arg) {
NativeThreadArg* feeder = (NativeThreadArg*) arg;
ThreadRoutine routine = feeder->routine;
ThreadWork* threadArg = feeder->arg;
free(feeder);
routine(threadArg);
return NULL;
}

bool initThreadMutex(RCN_NATIVE_HANDLE* mutex) {
pthread_mutex_t* nativeMutex = malloc(sizeof(pthread_mutex_t));
if (!nativeMutex) {
return false;
}
if (pthread_mutex_init(nativeMutex, NULL) != 0) {
free(nativeMutex);
return false;
}
*mutex = nativeMutex;
return true;
}

void deinitThreadMutex(RCN_NATIVE_HANDLE mutex) {
pthread_mutex_t* nativeMutex = mutex;
if (!nativeMutex) {
return;
}
int status = pthread_mutex_destroy(nativeMutex);
assert(status == 0);
(void) status;
free(nativeMutex);
}

void lockThread(RCN_NATIVE_HANDLE mutex) {
int status = pthread_mutex_lock((pthread_mutex_t*) mutex);
assert(status == 0);
(void) status;
}

void unlockThread(RCN_NATIVE_HANDLE mutex) {
int status = pthread_mutex_unlock((pthread_mutex_t*) mutex);
assert(status == 0);
(void) status;
}

size_t getSystemConcurrency(void) {
long processorCount = sysconf(_SC_NPROCESSORS_ONLN);
if (processorCount <= 0) {
return 1;
}
return (size_t) processorCount;
}

bool createThread(
ThreadHandle* handle,
ThreadRoutine routine,
ThreadWork* arg
) {
pthread_t* nativeThread = malloc(sizeof(pthread_t));
NativeThreadArg* feeder = malloc(sizeof(NativeThreadArg));
if (!nativeThread || !feeder) {
free(nativeThread);
free(feeder);
return false;
}
feeder->routine = routine;
feeder->arg = arg;
if (pthread_create(nativeThread, NULL, rcnRun, feeder) != 0) {
free(feeder);
free(nativeThread);
return false;
}
handle->instance = nativeThread;
return true;
}

void waitForThread(ThreadHandle* handle) {
pthread_t* nativeThread = (pthread_t*) handle->instance;
if (!nativeThread) {
return;
}
int status = pthread_join(*nativeThread, NULL);
assert(status == 0);
(void) status;
free(nativeThread);
handle->instance = NULL;
}

#endif // __linux__
Loading