Skip to content

Commit

Permalink
core/msg_bus: fix shift on 8-bit platforms
Browse files Browse the repository at this point in the history
The previous shift would wrap if the compiler defaults to 16 bit words.
Use explicit `unsigned long` integer constants to mitigate that.

before:

2020-07-22 15:25:17,063 # THREAD 1 start
2020-07-22 15:25:17,063 # THREAD 2 start
2020-07-22 15:25:17,065 # THREAD 3 start
2020-07-22 15:25:17,066 # THREADS CREATED
2020-07-22 15:25:17,068 # Posted event 22 to 0 threads
2020-07-22 15:25:17,071 # Posted event 23 to 0 threads
2020-07-22 15:25:17,076 # Posted event 24 to 0 threads
2020-07-22 15:25:17,076 # SUCCESS
2020-07-22 15:26:00,188 # Exiting Pyterm

after:

2020-07-22 15:26:10,374 # THREAD 1 start
2020-07-22 15:26:10,374 # THREAD 2 start
2020-07-22 15:26:10,377 # THREAD 3 start
2020-07-22 15:26:10,377 # THREADS CREATED
2020-07-22 15:26:10,380 # Posted event 22 to 0 threads
2020-07-22 15:26:10,383 # T1 recv: Hello Threads! (type=23)
2020-07-22 15:26:10,386 # T3 recv: Hello Threads! (type=23)
2020-07-22 15:26:10,388 # Posted event 23 to 2 threads
2020-07-22 15:26:10,391 # T2 recv: Hello Threads! (type=24)
2020-07-22 15:26:10,394 # Posted event 24 to 1 threads
2020-07-22 15:26:10,396 # SUCCESS
  • Loading branch information
benpicco committed Jul 22, 2020
1 parent 43d2de0 commit 46b89eb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/include/msg_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ msg_bus_entry_t *msg_bus_get_entry(msg_bus_t *bus);
static inline void msg_bus_subscribe(msg_bus_entry_t *entry, uint8_t type)
{
assert(type < 32);
entry->event_mask |= (1 << type);
entry->event_mask |= (1UL << type);
}

/**
Expand All @@ -160,7 +160,7 @@ static inline void msg_bus_subscribe(msg_bus_entry_t *entry, uint8_t type)
static inline void msg_bus_unsubscribe(msg_bus_entry_t *entry, uint8_t type)
{
assert(type < 32);
entry->event_mask &= ~(1 << type);
entry->event_mask &= ~(1UL << type);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ int msg_send_int(msg_t *m, kernel_pid_t target_pid)
int msg_send_bus(msg_t *m, msg_bus_t *bus)
{
const bool in_irq = irq_is_in();
const uint32_t event_mask = (1 << (m->type & 0x1F));
const uint32_t event_mask = (1UL << (m->type & 0x1F));
int count = 0;

m->sender_pid = in_irq ? KERNEL_PID_ISR : sched_active_pid;
Expand Down

0 comments on commit 46b89eb

Please sign in to comment.