Skip to content

File syn_pt_sem.h

FileList > pt > syn_pt_sem.h

Go to the source code of this file

Lightweight counting semaphores for protothreads. More...

  • #include "syn_pt.h"

Classes

Type Name
struct SYN_PT_Sem
Counting semaphore for protothreads.

Public Static Functions

Type Name
int pt_sem_trywait (SYN_PT_Sem * sem)
Try to acquire the semaphore without blocking.

Macros

Type Name
define PT_SEM_COUNT (sem) ((sem)->count)
define PT_SEM_INIT (sem, initial) ((sem)->count = (int16\_t)(initial))
Initialize a semaphore with the given count.
define PT_SEM_SIGNAL (sem) ((sem)->count++)
Increment the semaphore count, unblocking a waiting protothread.
define PT_SEM_TRYWAIT (sem) [**pt\_sem\_trywait**](syn__pt__sem_8h.md#function-pt_sem_trywait)(sem)
Macro wrapper for pt_sem_trywait.
define PT_SEM_WAIT (pt, sem) /* multi line expression */
Block the protothread until the semaphore count is > 0, then decrement it.

Detailed Description

Provides inter-protothread synchronization with zero RAM overhead beyond the 2-byte counter itself. All operations are macro/inline — no .c file is needed.

** **

static SYN_PT_Sem data_ready;
PT_SEM_INIT(&data_ready, 0);

// Producer (can be called from ISR):
PT_SEM_SIGNAL(&data_ready);

// Consumer (inside a protothread):
PT_SEM_WAIT(pt, &data_ready);
// ... data is now available ...

Public Static Functions Documentation

function pt_sem_trywait

Try to acquire the semaphore without blocking.

static inline int pt_sem_trywait (
    SYN_PT_Sem * sem
) 

Parameters:

  • sem Semaphore to try.

Returns:

1 if acquired (count was > 0 and was decremented), 0 otherwise.


Macro Definition Documentation

define PT_SEM_COUNT

#define PT_SEM_COUNT (
    sem
) `((sem)->count)`

Return the current count.


define PT_SEM_INIT

Initialize a semaphore with the given count.

#define PT_SEM_INIT (
    sem,
    initial
) `((sem)->count = (int16_t)(initial))`

Parameters:

  • sem Pointer to the semaphore.
  • initial Initial count (typically 0 or 1).

define PT_SEM_SIGNAL

Increment the semaphore count, unblocking a waiting protothread.

#define PT_SEM_SIGNAL (
    sem
) `((sem)->count++)`

Safe to call from ISR context.

Parameters:

  • sem Semaphore to signal.

define PT_SEM_TRYWAIT

Macro wrapper for pt_sem_trywait.

#define PT_SEM_TRYWAIT (
    sem
) `pt_sem_trywait (sem)`


define PT_SEM_WAIT

Block the protothread until the semaphore count is > 0, then decrement it.

#define PT_SEM_WAIT (
    pt,
    sem
) `/* multi line expression */`

Must be called from within a protothread (between PT_BEGIN/PT_END).

Parameters:

  • pt Protothread.
  • sem Semaphore to wait on.


The documentation for this class was generated from the following file src/syntropic/pt/syn_pt_sem.h