Skip to content

feat(api): _DEFINE macros for every M2 object type (M2 leftover) - #43

Merged
teo1747 merged 3 commits into
mainfrom
feat/m2-object-define
Nov 1, 2026
Merged

teo1747 merged 3 commits into
mainfrom
feat/m2-object-define

Conversation

@teo1747

@teo1747 teo1747 commented Oct 31, 2026

Copy link
Copy Markdown
Member

Contains the time-slicing commit as its base: merge the time-slicing PR first, after which this diff shows only the _DEFINE change.

This is the cross-type _DEFINE change deferred in A40 (API-021, KRN-OBJ-009). Each macro declares storage and the handle, and registers an init-table wrapper that constructs the object in emb_kernel_init(), as EMB_THREAD_DEFINE does. A construction failure faults through emb_check_status().

Macro Positional fields
EMB_SEM_DEFINE initial, max
EMB_MUTEX_DEFINE protocol, ceiling, flags
EMB_EVENT_DEFINE initial, flags
EMB_COND_DEFINE flags
EMB_MSGQ_DEFINE item_size, capacity, flags (defines the ring)
EMB_WORKQ_DEFINE priority, stack_size (defines the stack)
EMB_TIMER_DEFINE fn, arg; interrupt-context timers only

A64 records the contract:

  • The macros take positional fields: an attribute initializer would zero fields whose defaults are not zero.
  • The table entry stays one wrapper pointer.
  • A work-queue timer is not covered. Table entries, the system queue's included, run in link order and EMB_INIT_AFTER does not exist yet, so such a timer is constructed in code (SPEC-009 §5.2 already says so).
  • Names are kept only with CONFIG_EMB_OBJ_NAMES, so AVR does not copy the literals to RAM.

Evidence

  • One *_define_constructs_in_init_table conformance case per type.
  • Local runs, all passing:
    • native gcc/clang/release/tiny/periodic/timeslice/timeslice-tickless;
    • QEMU cm3, cm4 ×3, rv32 ×3;
    • AVR uno ×3; on AVR and RISC-V the per-case output confirms the cases ran;
    • asan/tsan/coverage and EmbSIM ×3.
  • The docs build has the 9 known shim warnings; check-banned and generate --check are clean.

Docs

API-021, SPEC-001 §6.4, SPEC-009 §5.2, the synchronization guide and CHANGELOG.

The deferred cross-type change of A40: EMB_SEM_DEFINE, EMB_MUTEX_DEFINE,
EMB_EVENT_DEFINE, EMB_COND_DEFINE, EMB_MSGQ_DEFINE (with its ring),
EMB_WORKQ_DEFINE (with its stack) and EMB_TIMER_DEFINE declare storage
and the handle. Each registers an init-table wrapper that constructs the
object in emb_kernel_init(), as EMB_THREAD_DEFINE does (API-021,
KRN-OBJ-009). The macros take positional fields because a partial
attribute initializer would zero fields whose defaults are not zero.

EMB_TIMER_DEFINE covers interrupt-context timers only. Table entries,
the system work queue's included, run in link order, and EMB_INIT_AFTER
does not exist yet. Object names are kept only where
CONFIG_EMB_OBJ_NAMES keeps them. One conformance case per type checks
construction in the init table. A64 records the contract.

Signed-off-by: teo1747 <motsoujunior17@gmail.com>
@teo1747
teo1747 merged commit 349a0a4 into main Nov 1, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant