29 #include "rtos/Queue.h" 30 #include "rtos/MemoryPool.h" 31 #include "rtos/mbed_rtos_types.h" 32 #include "rtos/internal/mbed_rtos_storage.h" 33 #include "rtos/internal/mbed_rtos1_types.h" 35 #include "platform/mbed_toolchain.h" 36 #include "platform/mbed_assert.h" 37 #include "platform/NonCopyable.h" 39 #ifndef MBED_NO_GLOBAL_USING_DIRECTIVE 43 #if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) 67 template<
typename T, u
int32_t queue_sz>
86 return _queue.empty();
112 MBED_DEPRECATED_SINCE(
"mbed-os-6.0.0",
"Replaced with try_alloc. In future alloc() will be an untimed blocking call.")
152 MBED_DEPRECATED_SINCE(
"mbed-os-6.0.0",
"Pass a chrono duration, not an integer millisecond count. For example use `5s` rather than `5000`.")
155 return try_alloc_for(std::chrono::duration<uint32_t, std::milli>(millisec));
189 MBED_DEPRECATED_SINCE(
"mbed-os-6.0.0",
"Pass a chrono time_point, not an integer millisecond count. For example use `Kernel::Clock::now() + 5s` rather than `Kernel::get_ms_count() + 5000`.")
192 return try_alloc_until(Kernel::Clock::time_point(std::chrono::duration<uint64_t, std::milli>(millisec)));
205 MBED_DEPRECATED_SINCE(
"mbed-os-6.0.0",
"Replaced with try_calloc. In future calloc() will be an untimed blocking call.")
245 MBED_DEPRECATED_SINCE(
"mbed-os-6.0.0",
"Pass a chrono duration, not an integer millisecond count. For example use `5s` rather than `5000`.")
248 return try_calloc_for(std::chrono::duration<uint32_t, std::milli>(millisec));
282 MBED_DEPRECATED_SINCE(
"mbed-os-6.0.0",
"Pass a chrono time_point, not an integer millisecond count. For example use `Kernel::Clock::now() + 5s` rather than `Kernel::get_ms_count() + 5000`.")
285 return try_calloc_until(Kernel::Clock::time_point(std::chrono::duration<uint64_t, std::milli>(millisec)));
303 bool ok = _queue.try_put(mptr);
305 return ok ? osOK : osErrorResource;
322 MBED_DEPRECATED_SINCE(
"mbed-os-6.0.0",
"Replaced with try_get and try_get_for. In future get will be an untimed blocking call.")
323 osEvent
get(uint32_t millisec = osWaitForever)
325 osEvent evt = _queue.get(millisec);
326 if (evt.status == osEventMessage) {
327 evt.status = osEventMail;
341 _queue.try_get(&mptr);
356 _queue.try_get_for(rel_time, &mptr);
370 return _pool.
free(mptr);
osStatus put(T *mptr)
Put a mail in the queue.
osEvent get(uint32_t millisec=osWaitForever)
Get a mail from the queue.
Mail()=default
Create and initialize Mail queue.
bool empty() const
Check if the mail queue is empty.
The Queue class represents a collection of objects that are stored first by order of priority...
T * calloc_for(uint32_t millisec)
Allocate a memory block of type T, optionally blocking, and set memory block to zero.
T * try_calloc_for(Kernel::Clock::duration_u32 rel_time)
Allocate a memory block from a memory pool, optionally blocking, and set memory block to zero...
T * try_alloc_for(Kernel::Clock::duration_u32 rel_time)
Allocate a memory block from a memory pool, optionally blocking.
T * try_calloc_until(Kernel::Clock::time_point abs_time)
Allocate a memory block of type T, blocking, and set memory block to zero.
T * calloc_until(uint64_t millisec)
Allocate a memory block of type T, blocking, and set memory block to zero.
T * alloc(MBED_UNUSED uint32_t millisec=0)
Allocate a memory block of type T, without blocking.
Prevents generation of copy constructor and copy assignment operator in derived classes.
T * try_calloc()
Allocate a memory block of type T, and set memory block to zero.
T * try_get()
Get a mail from the queue.
T * try_alloc()
Allocate a memory block of type T, without blocking.
T * alloc_until(uint64_t millisec)
Allocate a memory block of type T, blocking.
T * try_alloc_until(Kernel::Clock::time_point abs_time)
Allocate a memory block of type T, blocking.
The Mail class allows you to control, send, receive or wait for mail.
osStatus free(T *block)
Free a memory block.
T * try_alloc_until(Kernel::Clock::time_point abs_time)
Allocate a memory block from a memory pool, blocking.
osStatus free(T *mptr)
Free a memory block from a mail.
T * try_get_for(Kernel::Clock::duration_u32 rel_time)
Get a mail from the queue.
T * try_alloc()
Allocate a memory block from a memory pool, without blocking.
T * calloc(MBED_UNUSED uint32_t millisec=0)
Allocate a memory block of type T, and set memory block to zero.
T * alloc_for(uint32_t millisec)
Allocate a memory block of type T, optionally blocking.
T * try_calloc_for(Kernel::Clock::duration_u32 rel_time)
Allocate a memory block of type T, optionally blocking, and set memory block to zero.
bool full() const
Check if the mail queue is full.
T * try_alloc_for(Kernel::Clock::duration_u32 rel_time)
Allocate a memory block of type T, optionally blocking.
T * try_calloc()
Allocate a memory block from a memory pool, without blocking, and set memory block to zero...
T * try_calloc_until(Kernel::Clock::time_point abs_time)
Allocate a memory block from a memory pool, blocking, and set memory block to zero.