Skip to content

Commit 130fffa

Browse files
committed
Shrink RTOS classes
Various RTOS classes were storing their CMSIS-RTOS creation attribute structure as a member, when it's not required after construction. Reduce memory by eliminating this member.
1 parent 9c1fd48 commit 130fffa

File tree

10 files changed

+31
-37
lines changed

10 files changed

+31
-37
lines changed

rtos/EventFlags.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ EventFlags::EventFlags(const char *name)
3939
void EventFlags::constructor(const char *name)
4040
{
4141
memset(&_obj_mem, 0, sizeof(_obj_mem));
42-
memset(&_attr, 0, sizeof(_attr));
43-
_attr.name = name ? name : "application_unnamed_event_flags";
44-
_attr.cb_mem = &_obj_mem;
45-
_attr.cb_size = sizeof(_obj_mem);
46-
_id = osEventFlagsNew(&_attr);
42+
osEventFlagsAttr_t attr;
43+
attr.name = name ? name : "application_unnamed_event_flags";
44+
attr.cb_mem = &_obj_mem;
45+
attr.cb_size = sizeof(_obj_mem);
46+
_id = osEventFlagsNew(&attr);
4747
MBED_ASSERT(_id);
4848
}
4949

rtos/EventFlags.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class EventFlags : private mbed::NonCopyable<EventFlags> {
9090
void constructor(const char *name = NULL);
9191
uint32_t wait(uint32_t flags, uint32_t opt, uint32_t timeout, bool clear);
9292
osEventFlagsId_t _id;
93-
osEventFlagsAttr_t _attr;
9493
mbed_rtos_storage_event_flags_t _obj_mem;
9594
};
9695

rtos/MemoryPool.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
5050
MemoryPool() {
5151
memset(_pool_mem, 0, sizeof(_pool_mem));
5252
memset(&_obj_mem, 0, sizeof(_obj_mem));
53-
memset(&_attr, 0, sizeof(_attr));
54-
_attr.mp_mem = _pool_mem;
55-
_attr.mp_size = sizeof(_pool_mem);
56-
_attr.cb_mem = &_obj_mem;
57-
_attr.cb_size = sizeof(_obj_mem);
58-
_id = osMemoryPoolNew(pool_sz, sizeof(T), &_attr);
53+
osMemoryPoolAttr_t attr = { 0 };
54+
attr.mp_mem = _pool_mem;
55+
attr.mp_size = sizeof(_pool_mem);
56+
attr.cb_mem = &_obj_mem;
57+
attr.cb_size = sizeof(_obj_mem);
58+
_id = osMemoryPoolNew(pool_sz, sizeof(T), &attr);
5959
MBED_ASSERT(_id);
6060
}
6161

@@ -95,7 +95,6 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
9595

9696
private:
9797
osMemoryPoolId_t _id;
98-
osMemoryPoolAttr_t _attr;
9998
/* osMemoryPoolNew requires that pool block size is a multiple of 4 bytes. */
10099
char _pool_mem[((sizeof(T) + 3) & ~3) * pool_sz];
101100
mbed_rtos_storage_mem_pool_t _obj_mem;

rtos/Mutex.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ Mutex::Mutex(const char *name)
4040
void Mutex::constructor(const char *name)
4141
{
4242
memset(&_obj_mem, 0, sizeof(_obj_mem));
43-
memset(&_attr, 0, sizeof(_attr));
44-
_attr.name = name ? name : "aplication_unnamed_mutex";
45-
_attr.cb_mem = &_obj_mem;
46-
_attr.cb_size = sizeof(_obj_mem);
47-
_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust;
48-
_id = osMutexNew(&_attr);
43+
osMutexAttr_t attr = { 0 };
44+
attr.name = name ? name : "aplication_unnamed_mutex";
45+
attr.cb_mem = &_obj_mem;
46+
attr.cb_size = sizeof(_obj_mem);
47+
attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust;
48+
_id = osMutexNew(&attr);
4949
MBED_ASSERT(_id);
5050
}
5151

rtos/Mutex.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class Mutex : private mbed::NonCopyable<Mutex> {
8282
void constructor(const char *name = NULL);
8383

8484
osMutexId_t _id;
85-
osMutexAttr_t _attr;
8685
mbed_rtos_storage_mutex_t _obj_mem;
8786
};
8887

rtos/Queue.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
5151
/** Create and initialize a message Queue. */
5252
Queue() {
5353
memset(&_obj_mem, 0, sizeof(_obj_mem));
54-
memset(&_attr, 0, sizeof(_attr));
55-
_attr.mq_mem = _queue_mem;
56-
_attr.mq_size = sizeof(_queue_mem);
57-
_attr.cb_mem = &_obj_mem;
58-
_attr.cb_size = sizeof(_obj_mem);
59-
_id = osMessageQueueNew(queue_sz, sizeof(T*), &_attr);
54+
osMessageQueueAttr_t attr = { 0 };
55+
attr.mq_mem = _queue_mem;
56+
attr.mq_size = sizeof(_queue_mem);
57+
attr.cb_mem = &_obj_mem;
58+
attr.cb_size = sizeof(_obj_mem);
59+
_id = osMessageQueueNew(queue_sz, sizeof(T*), &attr);
6060
MBED_ASSERT(_id);
6161
}
6262

@@ -115,7 +115,6 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
115115

116116
private:
117117
osMessageQueueId_t _id;
118-
osMessageQueueAttr_t _attr;
119118
char _queue_mem[queue_sz * (sizeof(T*) + sizeof(mbed_rtos_storage_message_t))];
120119
mbed_rtos_storage_msg_queue_t _obj_mem;
121120
};

rtos/RtosTimer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ namespace rtos {
3131
void RtosTimer::constructor(mbed::Callback<void()> func, os_timer_type type) {
3232
_function = func;
3333
memset(&_obj_mem, 0, sizeof(_obj_mem));
34-
memset(&_attr, 0, sizeof(_attr));
35-
_attr.cb_mem = &_obj_mem;
36-
_attr.cb_size = sizeof(_obj_mem);
37-
_id = osTimerNew((void (*)(void *))Callback<void()>::thunk, type, &_function, &_attr);
34+
osTimerAttr_t attr = { 0 };
35+
attr.cb_mem = &_obj_mem;
36+
attr.cb_size = sizeof(_obj_mem);
37+
_id = osTimerNew((void (*)(void *))Callback<void()>::thunk, type, &_function, &attr);
3838
MBED_ASSERT(_id);
3939
}
4040

rtos/RtosTimer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ class RtosTimer : private mbed::NonCopyable<RtosTimer> {
157157
void constructor(mbed::Callback<void()> func, os_timer_type type);
158158

159159
osTimerId_t _id;
160-
osTimerAttr_t _attr;
161160
mbed_rtos_storage_timer_t _obj_mem;
162161
mbed::Callback<void()> _function;
163162
};

rtos/Semaphore.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ Semaphore::Semaphore(int32_t count, uint16_t max_count) {
3636

3737
void Semaphore::constructor(int32_t count, uint16_t max_count) {
3838
memset(&_obj_mem, 0, sizeof(_obj_mem));
39-
memset(&_attr, 0, sizeof(_attr));
40-
_attr.cb_mem = &_obj_mem;
41-
_attr.cb_size = sizeof(_obj_mem);
42-
_id = osSemaphoreNew(max_count, count, &_attr);
39+
osSemaphoreAttr_t attr = { 0 };
40+
attr.cb_mem = &_obj_mem;
41+
attr.cb_size = sizeof(_obj_mem);
42+
_id = osSemaphoreNew(max_count, count, &attr);
4343
MBED_ASSERT(_id != NULL);
4444
}
4545

rtos/Semaphore.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class Semaphore : private mbed::NonCopyable<Semaphore> {
7171
void constructor(int32_t count, uint16_t max_count);
7272

7373
osSemaphoreId_t _id;
74-
osSemaphoreAttr_t _attr;
7574
mbed_rtos_storage_semaphore_t _obj_mem;
7675
};
7776

0 commit comments

Comments
 (0)