4 #ifdef TGT_OS_TYPE_VXWORKS
8 #ifdef TGT_OS_TYPE_LINUX
33 ret = pthread_mutex_init(&this->
mp,
nullptr);
40 (void) mq_close(this->
handle);
43 (void) pthread_mutex_destroy(&this->
mp);
59 #ifndef TGT_OS_TYPE_VXWORKS
61 (void)snprintf(pid,
sizeof(pid),
".%d",getpid());
62 pid[
sizeof(pid)-1] = 0;
68 memset(&att,0,
sizeof(att));
69 att.mq_maxmsg = depth;
70 att.mq_msgsize = msgSize;
74 handle = mq_open(this->m_name.toChar(), O_RDWR | O_CREAT | O_EXCL | O_NONBLOCK, 0666, &att);
80 (void)mq_unlink(this->m_name.toChar());
86 handle = mq_open(this->m_name.toChar(), O_RDWR | O_CREAT | O_EXCL, 0666, &att);
94 QueueHandle* queueHandle =
new(std::nothrow) QueueHandle(handle);
95 if (
nullptr == queueHandle) {
106 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
108 (void) mq_unlink(this->m_name.toChar());
113 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
114 mqd_t handle = queueHandle->handle;
115 pthread_cond_t* queueNotEmpty = &queueHandle->queueNotEmpty;
116 pthread_cond_t* queueNotFull = &queueHandle->queueNotFull;
117 pthread_mutex_t* mp = &queueHandle->mp;
123 if (
nullptr == buffer) {
127 bool keepTrying =
true;
130 NATIVE_INT_TYPE stat = mq_send(handle,
reinterpret_cast<const char*
>(buffer), size, priority);
148 ret = pthread_mutex_lock(mp);
150 ret = pthread_cond_wait(queueNotFull, mp);
152 ret = pthread_mutex_unlock(mp);
162 ret = pthread_cond_signal(queueNotEmpty);
172 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
173 mqd_t handle = queueHandle->handle;
174 pthread_cond_t* queueNotEmpty = &queueHandle->queueNotEmpty;
175 pthread_cond_t* queueNotFull = &queueHandle->queueNotFull;
176 pthread_mutex_t* mp = &queueHandle->mp;
184 bool notFinished =
true;
185 while (notFinished) {
186 size = mq_receive(handle,
static_cast<char*
>(buffer),
static_cast<size_t>(capacity),
187 #ifdef TGT_OS_TYPE_VXWORKS
188 reinterpret_cast<int*
>(&priority));
190 reinterpret_cast<unsigned int*
>(&priority));
208 ret = pthread_mutex_lock(mp);
210 ret = pthread_cond_wait(queueNotEmpty, mp);
212 ret = pthread_mutex_unlock(mp);
224 ret = pthread_cond_signal(queueNotFull);
234 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
235 mqd_t handle = queueHandle->handle;
238 int status = mq_getattr(handle, &attr);
240 return static_cast<U32
>(attr.mq_curmsgs);
249 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
250 mqd_t handle = queueHandle->handle;
253 int status = mq_getattr(handle, &attr);
255 return static_cast<U32
>(attr.mq_maxmsg);
259 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
260 mqd_t handle = queueHandle->handle;
263 int status = mq_getattr(handle, &attr);
265 return static_cast<U32
>(attr.mq_msgsize);
PlatformPointerCastType POINTER_CAST
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
pthread_cond_t queueNotEmpty
QueueHandle(mqd_t m_handle)
pthread_cond_t queueNotFull
QueueString m_name
queue name
NATIVE_INT_TYPE getMsgSize() const
get the message size (maximum message size queue can hold)
@ QUEUE_SIZE_MISMATCH
attempted to send or receive with buffer too large, too small
@ QUEUE_UNINITIALIZED
Queue wasn't initialized successfully.
@ QUEUE_NO_MORE_MSGS
If non-blocking, all the messages have been drained.
@ QUEUE_INVALID_PRIORITY
invalid priority requested
@ QUEUE_EMPTY_BUFFER
supplied buffer is empty
@ QUEUE_UNKNOWN_ERROR
Unexpected error; can't match with returns.
@ QUEUE_OK
message sent/received okay
@ QUEUE_FULL
queue was full when attempting to send a message
QueueStatus send(const Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE priority, QueueBlocking block)
send a message
QueueStatus createInternal(const Fw::StringBase &name, NATIVE_INT_TYPE depth, NATIVE_INT_TYPE msgSize)
create a message queue
QueueStatus receive(Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE &priority, QueueBlocking block)
receive a message
NATIVE_INT_TYPE getQueueSize() const
get the queue depth (maximum number of messages queue can hold)
NATIVE_INT_TYPE getMaxMsgs() const
get the maximum number of messages (high watermark)
@ QUEUE_NONBLOCKING
Queue receive always returns even if there is no message.
NATIVE_INT_TYPE getNumMsgs() const
get the number of messages in the queue
static NATIVE_INT_TYPE s_numQueues
tracks number of queues in the system
POINTER_CAST m_handle
handle for implementation specific queue