Skip to content

Commit

Permalink
Merge pull request #454 from lf-lang/initialize-master-thread-id
Browse files Browse the repository at this point in the history
Fixed initialization of the master worker thread id
  • Loading branch information
cmnrd authored Jun 28, 2024
2 parents eb48bae + 5818d15 commit d22db97
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ int lf_reactor_c_main(int argc, const char* argv[]) {
// run on the main thread, rather than creating a new thread.
// This is important for bare-metal platforms, who can't
// afford to have the main thread sit idle.
env->thread_ids[j] = lf_thread_self();
continue;
}
if (lf_thread_create(&env->thread_ids[j], worker, env) != 0) {
Expand Down
7 changes: 7 additions & 0 deletions low_level_platform/impl/src/lf_arduino_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ typedef void* (*lf_function_t)(void*);
*/
int lf_available_cores() { return 1; }

lf_thread_t lf_thread_self() {
// Not implemented. Although Arduino mbed provides a ThisThread API and a
// get_id() function, it does not provide a way to get the current thread as a
// Thread object.
return NULL;
}

int lf_thread_create(lf_thread_t* thread, void* (*lf_thread)(void*), void* arguments) {
lf_thread_t t = thread_new();
long int start = thread_start(t, *lf_thread, arguments);
Expand Down
5 changes: 5 additions & 0 deletions low_level_platform/impl/src/lf_flexpret_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ int lf_available_cores() {
return FP_THREADS - 1; // Return the number of Flexpret HW threads
}

lf_thread_t lf_thread_self() {
// Not implemented.
return NULL;
}

int lf_thread_create(lf_thread_t* thread, void* (*lf_thread)(void*), void* arguments) {
/**
* Need to select between HRTT or SRTT; see
Expand Down
2 changes: 2 additions & 0 deletions low_level_platform/impl/src/lf_windows_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ int lf_available_cores() {
return sysinfo.dwNumberOfProcessors;
}

lf_thread_t lf_thread_self() { return GetCurrentThread(); }

int lf_thread_create(lf_thread_t* thread, void* (*lf_thread)(void*), void* arguments) {
uintptr_t handle = _beginthreadex(NULL, 0, lf_thread, arguments, 0, NULL);
*thread = (HANDLE)handle;
Expand Down

0 comments on commit d22db97

Please sign in to comment.