diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2002-04-26 23:39:01 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2002-04-26 23:39:01 +0000 |
commit | 53092d19211054d67787990714798c2e72c8a623 (patch) | |
tree | 9386e2095e8fd1d9c3e419faae2006df2ec80a48 /cpukit/posix/src/mqueueopen.c | |
parent | 2001-04-26 Joel Sherrill <joel@OARcorp.com> (diff) | |
download | rtems-53092d19211054d67787990714798c2e72c8a623.tar.bz2 |
2001-04-26 Joel Sherrill <joel@OARcorp.com>
* include/rtems/posix/mqueue.h, inline/rtems/posix/mqueue.inl,
src/mqueue.c, src/mqueueclose.c, src/mqueuecreatesupp.c,
src/mqueuegetattr.c, src/mqueuenotify.c, src/mqueueopen.c,
src/mqueuerecvsupp.c, src/mqueuesendsupp.c, src/mqueuesetattr.c:
Per PR81 reworked to add a message queue descriptor separate from
the underlying message queue. This allows non-blocking to follow
the "open" not the underlying queue.
Diffstat (limited to 'cpukit/posix/src/mqueueopen.c')
-rw-r--r-- | cpukit/posix/src/mqueueopen.c | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/cpukit/posix/src/mqueueopen.c b/cpukit/posix/src/mqueueopen.c index 0cad4974f6..f0dfc34f7c 100644 --- a/cpukit/posix/src/mqueueopen.c +++ b/cpukit/posix/src/mqueueopen.c @@ -45,13 +45,14 @@ mqd_t mq_open( /* struct mq_attr attr */ ) { - va_list arg; - mode_t mode; - struct mq_attr *attr = NULL; - int status; - Objects_Id the_mq_id; - POSIX_Message_queue_Control *the_mq; - Objects_Locations location; + va_list arg; + mode_t mode; + struct mq_attr *attr = NULL; + int status; + Objects_Id the_mq_id; + POSIX_Message_queue_Control *the_mq; + POSIX_Message_queue_Control_fd *the_mq_fd; + Objects_Locations location; _Thread_Disable_dispatch(); @@ -62,8 +63,15 @@ mqd_t mq_open( va_end(arg); } + the_mq_fd = _POSIX_Message_queue_Allocate_fd(); + if ( !the_mq_fd ) { + _Thread_Enable_dispatch(); + rtems_set_errno_and_return_minus_one( ENFILE ); + } + the_mq_fd->oflag = oflag; + status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id ); - + /* * If the name to id translation worked, then the message queue exists * and we can just return a pointer to the id. Otherwise we may @@ -79,6 +87,7 @@ mqd_t mq_open( */ if ( !( status == ENOENT && (oflag & O_CREAT) ) ) { + _POSIX_Message_queue_Free_fd( the_mq_fd ); _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one_cast( status, mqd_t ); } @@ -90,20 +99,22 @@ mqd_t mq_open( */ if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) { + _POSIX_Message_queue_Free_fd( the_mq_fd ); _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one_cast( EEXIST, mqd_t ); } /* - * XXX In this case we need to do an ID->pointer conversion to - * check the mode. This is probably a good place for a subroutine. + * In this case we need to do an ID->pointer conversion to + * check the mode. */ the_mq = _POSIX_Message_queue_Get( the_mq_id, &location ); the_mq->open_count += 1; + the_mq_fd->Queue = the_mq; _Thread_Enable_dispatch(); _Thread_Enable_dispatch(); - return (mqd_t)the_mq->Object.id; + return (mqd_t)the_mq_fd->Object.id; } @@ -115,7 +126,6 @@ mqd_t mq_open( status = _POSIX_Message_queue_Create_support( name, TRUE, /* shared across processes */ - oflag, attr, &the_mq ); @@ -124,12 +134,22 @@ mqd_t mq_open( * errno was set by Create_support, so don't set it again. */ - _Thread_Enable_dispatch(); - - if ( status == -1 ) + if ( status == -1 ) { + _Thread_Enable_dispatch(); + _POSIX_Message_queue_Free_fd( the_mq_fd ); return (mqd_t) -1; + } + + the_mq_fd->Queue = the_mq; + _Objects_Open( + &_POSIX_Message_queue_Information_fds, + &the_mq_fd->Object, + NULL + ); - return (mqd_t) the_mq->Object.id; + _Thread_Enable_dispatch(); + + return (mqd_t) the_mq_fd->Object.id; } |