Migration Guides

Migration Guides

Guides for migrating your application from other RTOSes to LightOS.


From FreeRTOS

Thread Creation

FreeRTOSLightOS
xTaskCreate()lightos::thread::create()
vTaskDelete()lightos::thread::terminate()
vTaskDelay()lightos::thread::sleep()
vTaskDelayUntil()lightos::thread::sleep_until()
taskYIELD()lightos::thread::yield()

Example Migration

FreeRTOS:

void task(void* arg) {
    while (1) {
        // Work
        vTaskDelay(pdMS_TO_TICKS(100));
    }
}

xTaskCreate(task, "Task", 1024, NULL, 5, NULL);
vTaskStartScheduler();

LightOS:

void task(void* arg) {
    while (true) {
        // Work
        lightos::thread::sleep(100_ms);
    }
}

lightos::thread::create(task, nullptr, 1024, 5);
lightos::scheduler::start();

Synchronization

FreeRTOSLightOS
xSemaphoreCreateMutex()lightos::mutex mtx;
xSemaphoreTake()mtx.lock()
xSemaphoreGive()mtx.unlock()
xQueueCreate()lightos::queue<T, N> q;
xQueueSend()q.send()
xQueueReceive()q.receive()

From Zephyr

Thread Creation

ZephyrLightOS
K_THREAD_DEFINE()lightos::thread::create()
k_thread_create()lightos::thread::create()
k_sleep()lightos::thread::sleep()
k_yield()lightos::thread::yield()

Example Migration

Zephyr:

K_THREAD_STACK_DEFINE(stack, 1024);
struct k_thread thread;

void entry(void* p1, void* p2, void* p3) {
    while (1) {
        k_sleep(K_MSEC(100));
    }
}

k_thread_create(&thread, stack, 1024, entry, 
                NULL, NULL, NULL, 5, 0, K_NO_WAIT);

LightOS:

void entry(void* arg) {
    while (true) {
        lightos::thread::sleep(100_ms);
    }
}

lightos::thread::create(entry, nullptr, 1024, 5);

Synchronization

ZephyrLightOS
k_mutex_init()Constructor
k_mutex_lock()mutex.lock()
k_mutex_unlock()mutex.unlock()
k_sem_init()Constructor
k_sem_take()sem.acquire()
k_sem_give()sem.release()

From ThreadX

Thread Creation

ThreadXLightOS
tx_thread_create()lightos::thread::create()
tx_thread_delete()lightos::thread::terminate()
tx_thread_sleep()lightos::thread::sleep()
tx_thread_relinquish()lightos::thread::yield()

Example Migration

ThreadX:

TX_THREAD thread;
UCHAR stack[1024];

void entry(ULONG arg) {
    while (1) {
        tx_thread_sleep(100);
    }
}

tx_thread_create(&thread, "Thread", entry, 0,
                 stack, 1024, 5, 5, TX_NO_TIME_SLICE, TX_AUTO_START);

LightOS:

void entry(void* arg) {
    while (true) {
        lightos::thread::sleep(100_ms);
    }
}

lightos::thread::create(entry, nullptr, 1024, 5);

Synchronization

ThreadXLightOS
tx_mutex_create()Constructor
tx_mutex_get()mutex.lock()
tx_mutex_put()mutex.unlock()
tx_semaphore_create()Constructor
tx_semaphore_get()sem.acquire()
tx_semaphore_put()sem.release()

POSIX Compatibility

If your application uses POSIX APIs, LightOS provides a compatibility layer:

#include <lightos/posix/pthread.hpp>
#include <lightos/posix/semaphore.hpp>
#include <lightos/posix/time.hpp>

// Your existing POSIX code works with minimal changes
pthread_t thread;
pthread_create(&thread, nullptr, worker, nullptr);

Supported POSIX APIs


Key Differences

C++ Modern API

LightOS uses modern C++20 features:

Zero-Cost Abstractions

LightOS C++ wrappers compile down to the same code as C:

// This:
lightos::thread::sleep(100_ms);

// Compiles to same code as:
lightos_thread_sleep(100);

Need Help?