This is Unofficial EPICS BASE Doxygen Site
osdMessageQueue.c File Reference
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rtems.h>
#include <rtems/error.h>
#include "epicsMessageQueue.h"
#include "errlog.h"
+ Include dependency graph for osdMessageQueue.c:

Go to the source code of this file.

Macros

#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__   1
 

Functions

LIBCOM_API epicsMessageQueueId epicsStdCall epicsMessageQueueCreate (unsigned int capacity, unsigned int maximumMessageSize)
 Create a message queue. More...
 
LIBCOM_API int epicsStdCall epicsMessageQueueSend (epicsMessageQueueId id, void *message, unsigned int messageSize)
 Send a message. More...
 
LIBCOM_API int epicsStdCall epicsMessageQueueSendWithTimeout (epicsMessageQueueId id, void *message, unsigned int messageSize, double timeout)
 Send a message or timeout. More...
 
LIBCOM_API int epicsStdCall epicsMessageQueueTryReceive (epicsMessageQueueId id, void *message, unsigned int size)
 Try to receive a message. More...
 
LIBCOM_API int epicsStdCall epicsMessageQueueReceive (epicsMessageQueueId id, void *message, unsigned int size)
 Fetch the next message on the queue. More...
 
LIBCOM_API int epicsStdCall epicsMessageQueueReceiveWithTimeout (epicsMessageQueueId id, void *message, unsigned int size, double timeout)
 Wait for a message to be queued. More...
 
LIBCOM_API int epicsStdCall epicsMessageQueuePending (epicsMessageQueueId id)
 How many messages are queued. More...
 
LIBCOM_API void epicsStdCall epicsMessageQueueShow (epicsMessageQueueId id, int level)
 Displays some information about the message queue. More...
 

Macro Definition Documentation

#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__   1

Definition at line 20 of file osdMessageQueue.c.

Function Documentation

LIBCOM_API epicsMessageQueueId epicsStdCall epicsMessageQueueCreate ( unsigned int  capacity,
unsigned int  maximumMessageSize 
)

Create a message queue.

Parameters
capacityMaximum number of messages to queue
maximumMessageSizeNumber of bytes of the largest message that may be queued
Returns
An identifier for the new queue, or 0.

Definition at line 32 of file osdMessageQueue.c.

33 {
34  rtems_status_code sc;
35  epicsMessageQueueId id = calloc(1, sizeof(*id));
36  rtems_interrupt_level level;
37  static char c1 = 'a';
38  static char c2 = 'a';
39  static char c3 = 'a';
40 
41  if(!id)
42  return NULL;
43 
44  sc = rtems_message_queue_create (rtems_build_name ('Q', c3, c2, c1),
45  capacity,
46  maximumMessageSize,
47  RTEMS_FIFO|RTEMS_LOCAL,
48  &id->id);
49  if (sc != RTEMS_SUCCESSFUL) {
50  free(id);
51  errlogPrintf ("Can't create message queue: %s\n", rtems_status_text (sc));
52  return NULL;
53  }
54  id->maxSize = maximumMessageSize;
55  id->localBuf = NULL;
56  rtems_interrupt_disable (level);
57  if (c1 == 'z') {
58  if (c2 == 'z') {
59  if (c3 == 'z') {
60  c3 = 'a';
61  }
62  else {
63  c3++;
64  }
65  c2 = 'a';
66  }
67  else {
68  c2++;
69  }
70  c1 = 'a';
71  }
72  else {
73  c1++;
74  }
75  rtems_interrupt_enable (level);
76  return id;
77 }
#define NULL
Definition: catime.c:38
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
LIBCOM_API int epicsStdCall epicsMessageQueuePending ( epicsMessageQueueId  id)

How many messages are queued.

Parameters
idMessage queue identifier.
Returns
The number of messages presently in the queue.

Definition at line 227 of file osdMessageQueue.c.

229 {
230  uint32_t count;
231  rtems_status_code sc;
232 
233  sc = rtems_message_queue_get_number_pending(id->id, &count);
234  if (sc != RTEMS_SUCCESSFUL) {
235  errlogPrintf("Message queue %x get number pending failed: %s\n",
236  (unsigned int)id,
237  rtems_status_text(sc));
238  return -1;
239  }
240  return count;
241 }
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
LIBCOM_API int epicsStdCall epicsMessageQueueReceive ( epicsMessageQueueId  id,
void *  message,
unsigned int  size 
)

Fetch the next message on the queue.

Wait for a message to be sent if the queue is empty, then move the first message queued to the specified location.

If the received message is larger than the specified message size the implementation may either return -1, or truncate the message. It is most efficient if the messageBufferSize is equal to the maximumMessageSize with which the message queue was created.

Returns
Number of bytes in the message.
-1 if the buffer is too small for the message.

Definition at line 193 of file osdMessageQueue.c.

197 {
198  return receiveMessage(id, message, size, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
199 }
LIBCOM_API int epicsStdCall epicsMessageQueueReceiveWithTimeout ( epicsMessageQueueId  id,
void *  message,
unsigned int  size,
double  timeout 
)

Wait for a message to be queued.

Wait up to timeout seconds for a message to be sent if the queue is empty, then move the first message to the specified location.

If the received message is larger than the specified message buffer size the implementation may either return -1, or truncate the message. It is most efficient if the messageBufferSize is equal to the maximumMessageSize with which the message queue was created.

Returns
Number of bytes in the message.
-1 if a message is not received within the timeout interval.

Definition at line 201 of file osdMessageQueue.c.

206 {
207  rtems_interval delay;
208  uint32_t wait;
209  extern double rtemsTicksPerSecond_double;
210 
211  /*
212  * Convert time to ticks
213  */
214  if (timeout <= 0.0) {
215  wait = RTEMS_NO_WAIT;
216  delay = 0;
217  }
218  else {
219  wait = RTEMS_WAIT;
220  delay = (int)(timeout * rtemsTicksPerSecond_double);
221  if (delay == 0)
222  delay++;
223  }
224  return receiveMessage(id, message, size, wait, delay);
225 }
double timeout
Definition: pvutils.cpp:25
double rtemsTicksPerSecond_double
Definition: osdTime.cpp:143
LIBCOM_API int epicsStdCall epicsMessageQueueSend ( epicsMessageQueueId  id,
void *  message,
unsigned int  messageSize 
)

Send a message.

Returns
0 if the message was sent to a receiver or queued for future delivery.
-1 if the message is larger than the queue's maximum message size.

Definition at line 122 of file osdMessageQueue.c.

126 {
127  if (rtems_message_queue_send_timeout(id->id, message, messageSize, RTEMS_NO_TIMEOUT) == RTEMS_SUCCESSFUL)
128  return 0;
129  else
130  return -1;
131 }
LIBCOM_API int epicsStdCall epicsMessageQueueSendWithTimeout ( epicsMessageQueueId  id,
void *  message,
unsigned int  messageSize,
double  timeout 
)

Send a message or timeout.

Returns
0 if the message was sent to a receiver or queued for future delivery.
-1 if the timeout was reached before the message could be sent or queued, or if the message is larger than the queue's maximum message size.

Definition at line 133 of file osdMessageQueue.c.

138 {
139  rtems_interval delay;
140  extern double rtemsTicksPerSecond_double;
141 
142  /*
143  * Convert time to ticks
144  */
145  if (timeout <= 0.0)
146  return epicsMessageQueueTrySend(id, message, messageSize);
147  delay = (int)(timeout * rtemsTicksPerSecond_double);
148  if (delay == 0)
149  delay++;
150  if (rtems_message_queue_send_timeout(id->id, message, messageSize, delay) == RTEMS_SUCCESSFUL)
151  return 0;
152  else
153  return -1;
154 }
double timeout
Definition: pvutils.cpp:25
#define epicsMessageQueueTrySend(q, m, l)
double rtemsTicksPerSecond_double
Definition: osdTime.cpp:143
LIBCOM_API void epicsStdCall epicsMessageQueueShow ( epicsMessageQueueId  id,
int  level 
)

Displays some information about the message queue.

Parameters
idMessage queue identifier.
levelControls the amount of information displayed.

Definition at line 243 of file osdMessageQueue.c.

246 {
247  int pending = epicsMessageQueuePending(id);
248  if (pending >= 0)
249  printf ("Message queue %lx -- Pending: %d\n", (unsigned long)id, pending);
250 }
#define printf
Definition: epicsStdio.h:41
LIBCOM_API int epicsStdCall epicsMessageQueuePending(epicsMessageQueueId id)
How many messages are queued.
LIBCOM_API int epicsStdCall epicsMessageQueueTryReceive ( epicsMessageQueueId  id,
void *  message,
unsigned int  size 
)

Try to receive a message.

If the queue holds at least one message, the first message on the queue is moved to the specified location and the length of that message is returned.

If the received message is larger than the specified message size the implementation may either return -1, or truncate the message. It is most efficient if the messageBufferSize is equal to the maximumMessageSize with which the message queue was created.

Returns
Number of bytes in the message.
-1 if the message queue is empty, or the buffer too small.

Definition at line 185 of file osdMessageQueue.c.

189 {
190  return receiveMessage(id, message, size, RTEMS_NO_WAIT, 0);
191 }