summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/pipe
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2010-06-08 10:25:46 +0000
committerSebastian Huber <sebastian.huber@embedded-brains.de>2010-06-08 10:25:46 +0000
commit241f4c96378ff3ca0ad811290c1dac49b571d1cc (patch)
tree5c6c0298594abcbe1c626bbd44c2ed1e74f3ffdc /cpukit/libfs/src/pipe
parent2010-06-08 Sebastian Huber <sebastian.huber@embedded-brains.de> (diff)
downloadrtems-241f4c96378ff3ca0ad811290c1dac49b571d1cc.tar.bz2
2010-06-08 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libfs/src/imfs/fifoimfs_init.c: New file. * libfs/Makefile.am: Reflect change above. * libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_init.c, libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/miniimfs_init.c, libfs/src/pipe/fifo.c, libfs/src/pipe/pipe.c, libfs/src/pipe/pipe.h: Pipe support is now link-time optional. * sapi/include/confdefs.h: Reflect changes above.
Diffstat (limited to 'cpukit/libfs/src/pipe')
-rw-r--r--cpukit/libfs/src/pipe/fifo.c109
-rw-r--r--cpukit/libfs/src/pipe/pipe.c4
-rw-r--r--cpukit/libfs/src/pipe/pipe.h5
3 files changed, 67 insertions, 51 deletions
diff --git a/cpukit/libfs/src/pipe/fifo.c b/cpukit/libfs/src/pipe/fifo.c
index 8f3fe82ddc..9bf362b7f0 100644
--- a/cpukit/libfs/src/pipe/fifo.c
+++ b/cpukit/libfs/src/pipe/fifo.c
@@ -21,6 +21,10 @@
#include <errno.h>
#include <stdlib.h>
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+
#include "pipe.h"
@@ -29,9 +33,7 @@
#define LIBIO_ACCMODE(_iop) ((_iop)->flags & LIBIO_FLAGS_READ_WRITE)
#define LIBIO_NODELAY(_iop) ((_iop)->flags & LIBIO_FLAGS_NO_DELAY)
-extern uint16_t rtems_pipe_no;
-static rtems_id rtems_pipe_semaphore = 0;
-extern bool rtems_pipe_configured;
+static rtems_id pipe_semaphore = RTEMS_ID_NONE;
#define PIPE_EMPTY(_pipe) (_pipe->Length == 0)
@@ -82,7 +84,7 @@ static void pipe_interruptible(pipe_control_t *pipe)
/*
* Alloc pipe control structure, buffer, and resources.
- * Called with rtems_pipe_semaphore held.
+ * Called with pipe_semaphore held.
*/
static int pipe_alloc(
pipe_control_t **pipep
@@ -139,7 +141,7 @@ err_buf:
return err;
}
-/* Called with rtems_pipe_semaphore held. */
+/* Called with pipe_semaphore held. */
static inline void pipe_free(
pipe_control_t *pipe
)
@@ -151,6 +153,48 @@ static inline void pipe_free(
free(pipe);
}
+static rtems_status_code pipe_lock(void)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ if (pipe_semaphore == RTEMS_ID_NONE) {
+ rtems_libio_lock();
+
+ if (pipe_semaphore == RTEMS_ID_NONE) {
+ sc = rtems_semaphore_create(
+ rtems_build_name('P', 'I', 'P', 'E'),
+ 1,
+ RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
+ RTEMS_NO_PRIORITY,
+ &pipe_semaphore
+ );
+ }
+
+ rtems_libio_unlock();
+ }
+
+ if (sc == RTEMS_SUCCESSFUL) {
+ sc = rtems_semaphore_obtain(pipe_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ }
+
+ if (sc == RTEMS_SUCCESSFUL) {
+ return 0;
+ } else {
+ return -EINTR;
+ }
+}
+
+static void pipe_unlock(void)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+ sc = rtems_semaphore_release(pipe_semaphore);
+ if (sc != RTEMS_SUCCESSFUL) {
+ /* FIXME */
+ rtems_fatal_error_occurred(0xdeadbeef);
+ }
+}
+
/*
* If called with *pipep = NULL, pipe_new will call pipe_alloc to allocate a
* pipe control structure and set *pipep to its address.
@@ -163,9 +207,9 @@ static int pipe_new(
pipe_control_t *pipe;
int err = 0;
- if (rtems_semaphore_obtain(rtems_pipe_semaphore,
- RTEMS_WAIT, RTEMS_NO_TIMEOUT) != RTEMS_SUCCESSFUL)
- return -EINTR;
+ err = pipe_lock();
+ if (err)
+ return err;
pipe = *pipep;
if (pipe == NULL) {
@@ -185,7 +229,7 @@ static int pipe_new(
}
out:
- rtems_semaphore_release(rtems_pipe_semaphore);
+ pipe_unlock();
return err;
}
@@ -204,11 +248,16 @@ int pipe_release(
uint32_t mode;
rtems_status_code sc;
- sc = rtems_semaphore_obtain(pipe->Semaphore,
- RTEMS_WAIT, RTEMS_NO_TIMEOUT);
- /* WARN pipe not released! */
- if(sc != RTEMS_SUCCESSFUL)
- rtems_fatal_error_occurred(sc);
+
+ if (pipe_lock())
+ /* WARN pipe not freed and pipep not set to NULL! */
+ /* FIXME */
+ rtems_fatal_error_occurred(0xdeadbeef);
+
+ if (!PIPE_LOCK(pipe))
+ /* WARN pipe not released! */
+ /* FIXME */
+ rtems_fatal_error_occurred(0xdeadbeef);
mode = LIBIO_ACCMODE(iop);
if (mode & LIBIO_FLAGS_READ)
@@ -216,12 +265,6 @@ int pipe_release(
if (mode & LIBIO_FLAGS_WRITE)
pipe->Writers --;
- sc = rtems_semaphore_obtain(rtems_pipe_semaphore,
- RTEMS_WAIT, RTEMS_NO_TIMEOUT);
- /* WARN pipe not freed and pipep not set to NULL! */
- if(sc != RTEMS_SUCCESSFUL)
- rtems_fatal_error_occurred(sc);
-
PIPE_UNLOCK(pipe);
if (pipe->Readers == 0 && pipe->Writers == 0) {
@@ -239,7 +282,7 @@ int pipe_release(
else if (pipe->Writers == 0 && mode != LIBIO_FLAGS_READ)
PIPE_WAKEUPREADERS(pipe);
- rtems_semaphore_release(rtems_pipe_semaphore);
+ pipe_unlock();
#if 0
if (! delfile)
@@ -539,27 +582,3 @@ int pipe_lseek(
/* Seek on pipe is not supported */
return -ESPIPE;
}
-
-/*
- * Initialization of FIFO/pipe module.
- */
-void rtems_pipe_initialize (void)
-{
- if (!rtems_pipe_configured)
- return;
-
- if (rtems_pipe_semaphore)
- return;
-
- rtems_status_code sc;
- sc = rtems_semaphore_create(
- rtems_build_name ('P', 'I', 'P', 'E'), 1,
- RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
- RTEMS_NO_PRIORITY, &rtems_pipe_semaphore);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_fatal_error_occurred (sc);
-
- rtems_interval now;
- now = rtems_clock_get_ticks_since_boot();
- rtems_pipe_no = now;
-}
diff --git a/cpukit/libfs/src/pipe/pipe.c b/cpukit/libfs/src/pipe/pipe.c
index 45a27ac160..0cc8c9acdb 100644
--- a/cpukit/libfs/src/pipe/pipe.c
+++ b/cpukit/libfs/src/pipe/pipe.c
@@ -20,7 +20,8 @@
#include <rtems/seterr.h>
/* Incremental number added to names of anonymous pipe files */
-uint16_t rtems_pipe_no = 0;
+/* FIXME: This approach is questionable */
+static uint16_t rtems_pipe_no = 0;
/*
* Called by pipe() to create an anonymous pipe.
@@ -33,6 +34,7 @@ int pipe_create(
rtems_libio_t *iop;
int err = 0;
/* Create /tmp if not exists */
+ /* FIXME: We should use a general mkdir function for this */
if (rtems_filesystem_evaluate_path("/tmp", 3, RTEMS_LIBIO_PERMS_RWX, &loc, TRUE)
!= 0) {
if (errno != ENOENT)
diff --git a/cpukit/libfs/src/pipe/pipe.h b/cpukit/libfs/src/pipe/pipe.h
index 283e036778..e86c0a978b 100644
--- a/cpukit/libfs/src/pipe/pipe.h
+++ b/cpukit/libfs/src/pipe/pipe.h
@@ -109,11 +109,6 @@ extern int pipe_lseek(
rtems_libio_t *iop
);
-/*
- * Initialization of FIFO/pipe module.
- */
-extern void rtems_pipe_initialize (void);
-
#ifdef __cplusplus
}
#endif