1 #include <Fw/Types/Assert.hpp>
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) {
98 this->
m_handle =
reinterpret_cast<POINTER_CAST
>(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);