Skip to content

Conversation

@dmitrykos
Copy link
Owner

@dmitrykos dmitrykos commented Jan 26, 2026

Currently supported:

  • ScopedCriticalSection
  • ConditionVariable
  • Event
  • Mutex
  • Semaphore
  • Pipe

All these primitives can be used as a building blocks for other synchronization implementation (see Pipe which is using ConditionVariable).

There is an example demonstrating synchronization primitives for x86, ARM and RISC-V archs in action:

  • in build/example/sync folder
  • corresponding Eclipse projects in x86, stm, rpi directories

There are additional tests (work in progress in this PR).

To support synchronization primitives Kernel must be configured with a new KERNEL_SYNC flag. Obviously, if KERNEL_SYNC is not set then all synchronization-related support is removed by the compiler (no binary bloat due to this new feature).

This PR is work in progress and will be merged when work on test coverage and C interface is completed. New C++ API is stable, so you can use implementation already in your C++ project.

Demo:

#include <stk.h>
#include <sync/stk_sync.h>

enum LedState { LED_OFF, LED_ON };

// One-slot pipe for passing LED states between tasks
static stk::sync::Pipe<LedState, 1> g_CtrlSignalPipe;
static stk::sync::Mutex g_HwMutex;

// Consumer Task: Waits for state updates from the pipe
template <stk::EAccessMode _Mode>
class LedTask : public stk::Task<2048, _Mode> {
    void RunInner() {
        LedState target_state;
        while (true) {
            // Blocks until a signal is received or 100ms timeout occurs
            if (g_CtrlSignalPipe.Read(target_state, 100)) {
                stk::sync::Mutex::ScopedLock guard(g_HwMutex);
                Led::Set(Led::GREEN, (target_state == LED_ON));
            }
        }
    }
};

// Producer Task: Writes new states to the pipe
template <stk::EAccessMode _Mode>
class CtrlTask : public stk::Task<256, _Mode> {
    void RunInner() {
        bool led_sw = false;
        while (true) {
            stk::Sleep(250);
            led_sw = !led_sw;
            // Write new state to the pipe for the LedTask to consume
            g_CtrlSignalPipe.Write(led_sw ? LED_ON : LED_OFF);
        }
    }
};

@dmitrykos dmitrykos self-assigned this Jan 26, 2026
@dmitrykos dmitrykos added the enhancement New feature or request label Jan 26, 2026
Repository owner deleted a comment from github-actions bot Jan 26, 2026
Repository owner deleted a comment from github-actions bot Jan 26, 2026
@github-actions
Copy link

github-actions bot commented Jan 26, 2026

MemBrowse Memory Report

stm32f0-sleep

  • RAM: .bss +16 B (+0.3%, 6,300 B / 8,192 B, total: 77% used)
  • FLASH: .text +308 B (+1.7%, 18,156 B / 65,536 B, total: 28% used)

stm32f1-sleep

  • RAM: .bss +16 B (+0.3%, 6,300 B / 20,480 B, total: 31% used)
  • FLASH: .text +368 B (+2.2%, 17,469 B / 131,072 B, total: 13% used)

stm32f4-sleep

  • RAM: .bss +16 B (+0.3%, 6,304 B / 131,072 B, total: 5% used)
  • FLASH: .text +368 B (+2.0%, 18,353 B / 1,048,576 B, total: 2% used)

Repository owner deleted a comment from github-actions bot Jan 26, 2026
…: ScopedCriticalSection, ConditionVariable, Event, Mutex, Semaphore, Pipe,

Example demonstrating synchronization primitives for x86, ARM and RISC-V archs: build/example/sync and corresponding Eclipse projects in x86, stm, rpi directories.
Additional tests.
Repository owner deleted a comment from github-actions bot Jan 26, 2026
Repository owner deleted a comment from github-actions bot Jan 26, 2026
Repository owner deleted a comment from github-actions bot Jan 26, 2026
Repository owner deleted a comment from github-actions bot Jan 26, 2026
@github-actions
Copy link

LCOV of commit f2e3f78 during Code Coverage - Generic #300

Summary coverage rate:
  lines......: 100.0% (936 of 936 lines)
  functions..: 55.2% (1190 of 2156 functions)
  branches...: no data found

Files changed coverage rate: n/a

Repository owner deleted a comment from github-actions bot Jan 26, 2026
Fixed main C interface for memory consumption and multi-core race issues.
Add Doxygen documentation for classes of sync namespace.
New low-level Spinlock for inter-core synchronization.
New sync_c example using C interface on dual-core system with sync classes (similar to C++ version of sync).
@github-actions
Copy link

LCOV of commit db9054c during Code Coverage - Generic #301

Summary coverage rate:
  lines......: 100.0% (936 of 936 lines)
  functions..: 55.2% (1190 of 2156 functions)
  branches...: no data found

Files changed coverage rate: n/a

@dmitrykos dmitrykos merged commit ee00f17 into main Jan 27, 2026
21 checks passed
@dmitrykos dmitrykos deleted the sync_event branch January 28, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants