pipe.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 RenĂ© Kijewski <rene.kijewski@fu-berlin.de>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
35 #ifndef PIPE_H
36 #define PIPE_H
37 
38 #include <sys/types.h>
39 
40 #include "mutex.h"
41 #include "ringbuffer.h"
42 #include "thread.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #ifndef PIPE_BUF
49 # define PIPE_BUF (128)
50 #endif
51 
55 typedef struct riot_pipe {
61  void (*free)(void *);
63  } pipe_t;
64 
72 void pipe_init(pipe_t *pipe, ringbuffer_t *rb, void (*free)(void *));
73 
86 ssize_t pipe_read(pipe_t *pipe, void *buf, size_t n);
87 
100 ssize_t pipe_write(pipe_t *pipe, const void *buf, size_t n);
101 
109 pipe_t *pipe_malloc(unsigned size);
110 
118 void pipe_free(pipe_t *rp);
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif /* PIPE_H */
125 
ringbuffer.h
A utility for storing and retrieving byte data using a ring buffer.
pipe_write
ssize_t pipe_write(pipe_t *pipe, const void *buf, size_t n)
Write to a pipe.
riot_pipe::write_blocked
thread_t * write_blocked
A thread that wants to read from this empty pipe.
Definition: pipe.h:59
riot_pipe::read_blocked
thread_t * read_blocked
A thread that wants to write to this full pipe.
Definition: pipe.h:57
ringbuffer_t
Ringbuffer.
Definition: ringbuffer.h:36
_thread
thread_t holds thread's context data.
Definition: thread.h:154
riot_pipe::rb
ringbuffer_t * rb
Wrapped ringbuffer.
Definition: pipe.h:56
mutex.h
Mutex for thread synchronization.
pipe_malloc
pipe_t * pipe_malloc(unsigned size)
Dynamically allocate a pipe with room for size bytes.
free
void free(void *ptr)
This is a no-op.
pipe_t
struct riot_pipe pipe_t
A generic pipe.
pipe_init
void pipe_init(pipe_t *pipe, ringbuffer_t *rb, void(*free)(void *))
Initialize a pipe.
pipe_free
void pipe_free(pipe_t *rp)
Free a pipe.
pipe_read
ssize_t pipe_read(pipe_t *pipe, void *buf, size_t n)
Read from a pipe.
riot_pipe
A generic pipe.
Definition: pipe.h:55
riot_pipe::free
void(* free)(void *)
Function to call by pipe_free().
Definition: pipe.h:61