Changeset d4d6bd81 in rtems for cpukit/libblock


Ignore:
Timestamp:
Aug 25, 2010, 8:44:14 AM (9 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
9788279
Parents:
6ef96da
Message:

2010-08-25 Sebastian Huber <sebastian.huber@…>

  • libblock/include/rtems/media.h, libblock/src/media-server.c: Use chains instead of a message queue.
Location:
cpukit/libblock
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libblock/include/rtems/media.h

    r6ef96da rd4d6bd81  
    388388 * @a attributes parameters.
    389389 *
    390  * A message queue will be used for communication with the server task which
    391  * may buffer up to @a message_count messages.
    392  *
    393390 * Calling this function more than once will have no effects.  There is no
    394391 * protection against concurrent access.
     
    401398  size_t stack_size,
    402399  rtems_mode modes,
    403   rtems_attribute attributes,
    404   uint32_t message_count
     400  rtems_attribute attributes
    405401);
    406402
     
    411407 *
    412408 * @retval RTEMS_SUCCESSFUL Successful operation.
    413  * @retval RTEMS_UNSATISFIED Message queue is full.
    414  * @retval RTEMS_NO_MEMORY Not enough memory for the message.
     409 * @retval RTEMS_NO_MEMORY Not enough resources to notify the media server.
     410 * @retval RTEMS_NOT_CONFIGURED Media server is not initialized.
    415411 */
    416412rtems_status_code rtems_media_server_post_event(
  • cpukit/libblock/src/media-server.c

    r6ef96da rd4d6bd81  
    2222
    2323#include <string.h>
    24 #include <stdio.h>
    2524#include <stdlib.h>
     25#include <assert.h>
    2626
    2727#include <rtems.h>
    2828#include <rtems/chain.h>
    29 
    3029#include <rtems/media.h>
    3130
     31#define EVENT RTEMS_EVENT_13
     32
    3233typedef struct {
     34  rtems_chain_node node;
    3335  rtems_media_event event;
    34   char *src;
     36  const char *src;
    3537  rtems_media_worker worker;
    36   void *arg;
    37 } media_server_event;
     38  void *worker_arg;
     39} message;
    3840
    39 static rtems_id message_queue_id = RTEMS_ID_NONE;
     41static RTEMS_CHAIN_DEFINE_EMPTY(message_chain);
    4042
    41 static void rtems_media_server(rtems_task_argument arg __attribute__((unused)))
     43static rtems_id server_id = RTEMS_ID_NONE;
     44
     45static void media_server(rtems_task_argument arg __attribute__((unused)))
    4246{
    4347  rtems_status_code sc = RTEMS_SUCCESSFUL;
    4448
    4549  while (true) {
    46     media_server_event msg;
    47     size_t msg_size = sizeof(msg);
     50    message *msg = NULL;
    4851
    49     sc = rtems_message_queue_receive(
    50       message_queue_id,
    51       &msg,
    52       &msg_size,
    53       RTEMS_WAIT,
    54       RTEMS_NO_TIMEOUT
     52    sc = rtems_chain_get_with_wait(
     53      &message_chain,
     54      EVENT,
     55      RTEMS_NO_TIMEOUT,
     56      (rtems_chain_node **) &msg
    5557    );
    56     if (sc != RTEMS_SUCCESSFUL) {
    57       break;
    58     }
     58    assert(sc == RTEMS_SUCCESSFUL);
     59    assert(msg != NULL);
    5960
    60     rtems_media_post_event(msg.event, msg.src, NULL, msg.worker, msg.arg);
     61    rtems_media_post_event(
     62      msg->event,
     63      msg->src,
     64      NULL,
     65      msg->worker,
     66      msg->worker_arg
     67    );
    6168
    62     free(msg.src);
     69    free(msg);
    6370  }
    64 
    65   rtems_task_delete(RTEMS_SELF);
    6671}
    6772
     
    7075  size_t stack_size,
    7176  rtems_mode modes,
    72   rtems_attribute attributes,
    73   uint32_t message_count
     77  rtems_attribute attributes
    7478)
    7579{
    7680  rtems_status_code sc = RTEMS_SUCCESSFUL;
    77   rtems_id task_id = RTEMS_ID_NONE;
    7881
    79   if (message_queue_id == RTEMS_ID_NONE) {
     82  if (server_id == RTEMS_ID_NONE) {
    8083    sc = rtems_media_initialize();
    81     if (sc != RTEMS_SUCCESSFUL) {
    82       goto error;
    83     }
    84 
    85     sc = rtems_message_queue_create(
    86       rtems_build_name('M', 'D', 'I', 'A'),
    87       message_count,
    88       sizeof(media_server_event),
    89       RTEMS_DEFAULT_ATTRIBUTES,
    90       &message_queue_id
    91     );
    9284    if (sc != RTEMS_SUCCESSFUL) {
    9385      goto error;
     
    10092      modes,
    10193      attributes,
    102       &task_id
     94      &server_id
    10395    );
    10496    if (sc != RTEMS_SUCCESSFUL) {
     
    10698    }
    10799
    108     sc = rtems_task_start(task_id, rtems_media_server, 0);
     100    sc = rtems_task_start(server_id, media_server, 0);
    109101    if (sc != RTEMS_SUCCESSFUL) {
    110102      goto error;
     
    116108error:
    117109
    118   if (task_id != RTEMS_ID_NONE) {
    119     rtems_task_delete(task_id);
     110  if (server_id != RTEMS_ID_NONE) {
     111    rtems_task_delete(server_id);
    120112  }
    121 
    122   rtems_message_queue_delete(message_queue_id);
    123113
    124114  return RTEMS_NO_MEMORY;
     
    129119  const char *src,
    130120  rtems_media_worker worker,
    131   void *arg
     121  void *worker_arg
    132122)
    133123{
    134124  rtems_status_code sc = RTEMS_SUCCESSFUL;
    135   media_server_event msg = {
    136     .event = event,
    137     .src = strdup(src),
    138     .worker = worker,
    139     .arg = arg
    140   };
     125  size_t src_size = strlen(src) + 1;
     126  message *msg = malloc(sizeof(*msg) + src_size);
    141127
    142   if (msg.src == NULL) {
    143     return RTEMS_NO_MEMORY;
     128  if (msg != NULL) {
     129    char *s = (char *) msg + sizeof(*msg);
     130
     131    memcpy(s, src, src_size);
     132
     133    msg->event = event;
     134    msg->src = s;
     135    msg->worker = worker;
     136    msg->worker_arg = worker_arg;
     137
     138    sc = rtems_chain_append_with_notification(
     139      &message_chain,
     140      &msg->node,
     141      server_id,
     142      EVENT
     143    );
     144    if (sc != RTEMS_SUCCESSFUL) {
     145      sc = RTEMS_NOT_CONFIGURED;
     146    }
     147  } else {
     148    sc = RTEMS_NO_MEMORY;
    144149  }
    145150
    146   sc = rtems_message_queue_send(
    147     message_queue_id,
    148     &msg,
    149     sizeof(msg)
    150   );
    151   if (sc != RTEMS_SUCCESSFUL) {
    152     free(msg.src);
    153 
    154     return RTEMS_UNSATISFIED;
    155   }
    156 
    157   return RTEMS_SUCCESSFUL;
     151  return sc;
    158152}
Note: See TracChangeset for help on using the changeset viewer.