summaryrefslogtreecommitdiffstats
path: root/cpukit/rtems/src/msgqcreate.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1999-05-17 22:52:59 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1999-05-17 22:52:59 +0000
commit1e1b3e00d1d7dcf8ae674db66250fbccab293f4f (patch)
tree67032028ca5ce58703a6cd52b1f4738e48fd021a /cpukit/rtems/src/msgqcreate.c
parentMoved an MP routine from msg.c to here. (diff)
downloadrtems-1e1b3e00d1d7dcf8ae674db66250fbccab293f4f.tar.bz2
Split Message Manager into one routine per file.
Diffstat (limited to 'cpukit/rtems/src/msgqcreate.c')
-rw-r--r--cpukit/rtems/src/msgqcreate.c168
1 files changed, 168 insertions, 0 deletions
diff --git a/cpukit/rtems/src/msgqcreate.c b/cpukit/rtems/src/msgqcreate.c
new file mode 100644
index 0000000000..11d1e7d297
--- /dev/null
+++ b/cpukit/rtems/src/msgqcreate.c
@@ -0,0 +1,168 @@
+/*
+ * Message Queue Manager
+ *
+ *
+ * COPYRIGHT (c) 1989-1998.
+ * On-Line Applications Research Corporation (OAR).
+ * Copyright assigned to U.S. Government, 1994.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ * $Id$
+ */
+
+#include <rtems/system.h>
+#include <rtems/score/sysstate.h>
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/coremsg.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
+#if defined(RTEMS_MULTIPROCESSING)
+#include <rtems/score/mpci.h>
+#endif
+#include <rtems/rtems/status.h>
+#include <rtems/rtems/attr.h>
+#include <rtems/rtems/message.h>
+#include <rtems/rtems/options.h>
+#include <rtems/rtems/support.h>
+
+/*PAGE
+ *
+ * rtems_message_queue_create
+ *
+ * This directive creates a message queue by allocating and initializing
+ * a message queue data structure.
+ *
+ * Input parameters:
+ * name - user defined queue name
+ * count - maximum message and reserved buffer count
+ * max_message_size - maximum size of each message
+ * attribute_set - process method
+ * id - pointer to queue
+ *
+ * Output parameters:
+ * id - queue id
+ * RTEMS_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ */
+
+rtems_status_code rtems_message_queue_create(
+ rtems_name name,
+ unsigned32 count,
+ unsigned32 max_message_size,
+ rtems_attribute attribute_set,
+ Objects_Id *id
+)
+{
+ register Message_queue_Control *the_message_queue;
+ CORE_message_queue_Attributes the_message_queue_attributes;
+ void *handler;
+#if defined(RTEMS_MULTIPROCESSING)
+ boolean is_global;
+#endif
+
+ if ( !rtems_is_name_valid( name ) )
+ return RTEMS_INVALID_NAME;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( (is_global = _Attributes_Is_global( attribute_set ) ) &&
+ !_System_state_Is_multiprocessing )
+ return RTEMS_MP_NOT_CONFIGURED;
+#endif
+
+ if (count == 0)
+ return RTEMS_INVALID_NUMBER;
+
+ if (max_message_size == 0)
+ return RTEMS_INVALID_SIZE;
+
+#if defined(RTEMS_MULTIPROCESSING)
+#if 1
+ /*
+ * I am not 100% sure this should be an error.
+ * It seems reasonable to create a que with a large max size,
+ * and then just send smaller msgs from remote (or all) nodes.
+ */
+
+ if ( is_global && (_MPCI_table->maximum_packet_size < max_message_size) )
+ return RTEMS_INVALID_SIZE;
+#endif
+#endif
+
+ _Thread_Disable_dispatch(); /* protects object pointer */
+
+ the_message_queue = _Message_queue_Allocate( count, max_message_size );
+
+ if ( !the_message_queue ) {
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( is_global &&
+ !( _Objects_MP_Allocate_and_open( &_Message_queue_Information,
+ name, the_message_queue->Object.id, FALSE ) ) ) {
+ _Message_queue_Free( the_message_queue );
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+#endif
+
+ the_message_queue->attribute_set = attribute_set;
+
+ if (_Attributes_Is_priority( attribute_set ) )
+ the_message_queue_attributes.discipline =
+ CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY;
+ else
+ the_message_queue_attributes.discipline =
+ CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
+
+ handler = NULL;
+#if defined(RTEMS_MULTIPROCESSING)
+ handler = _Message_queue_MP_Send_extract_proxy;
+#endif
+
+ if ( ! _CORE_message_queue_Initialize(
+ &the_message_queue->message_queue,
+ OBJECTS_RTEMS_MESSAGE_QUEUES,
+ &the_message_queue_attributes,
+ count,
+ max_message_size,
+ handler ) ) {
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( is_global )
+ _Objects_MP_Close(
+ &_Message_queue_Information, the_message_queue->Object.id);
+#endif
+
+ _Message_queue_Free( the_message_queue );
+ _Thread_Enable_dispatch();
+ return RTEMS_TOO_MANY;
+ }
+
+ _Objects_Open(
+ &_Message_queue_Information,
+ &the_message_queue->Object,
+ &name
+ );
+
+ *id = the_message_queue->Object.id;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ if ( is_global )
+ _Message_queue_MP_Send_process_packet(
+ MESSAGE_QUEUE_MP_ANNOUNCE_CREATE,
+ the_message_queue->Object.id,
+ name,
+ 0
+ );
+#endif
+
+ _Thread_Enable_dispatch();
+ return RTEMS_SUCCESSFUL;
+}