diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index 392f49c31..14d84fd14 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -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) { diff --git a/low_level_platform/impl/src/lf_arduino_support.c b/low_level_platform/impl/src/lf_arduino_support.c index ed9391205..5793bd650 100644 --- a/low_level_platform/impl/src/lf_arduino_support.c +++ b/low_level_platform/impl/src/lf_arduino_support.c @@ -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); diff --git a/low_level_platform/impl/src/lf_flexpret_support.c b/low_level_platform/impl/src/lf_flexpret_support.c index 9d83283c5..cf37c1b8a 100644 --- a/low_level_platform/impl/src/lf_flexpret_support.c +++ b/low_level_platform/impl/src/lf_flexpret_support.c @@ -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 diff --git a/low_level_platform/impl/src/lf_windows_support.c b/low_level_platform/impl/src/lf_windows_support.c index 1d48bc6c7..61424ac7f 100644 --- a/low_level_platform/impl/src/lf_windows_support.c +++ b/low_level_platform/impl/src/lf_windows_support.c @@ -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;