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 header.
struct riot_pipe pipe_t
A generic pipe.
ssize_t pipe_read(pipe_t *pipe, void *buf, size_t n)
Read from a pipe.
ssize_t pipe_write(pipe_t *pipe, const void *buf, size_t n)
Write to a pipe.
thread_t * write_blocked
A thread that wants to read from this empty pipe.
Definition: pipe.h:59
thread_t holds thread&#39;s context data.
Definition: thread.h:172
Threading API.
Ringbuffer.
Definition: ringbuffer.h:30
ringbuffer_t * rb
Wrapped ringbuffer.
Definition: pipe.h:56
thread_t * read_blocked
A thread that wants to write to this full pipe.
Definition: pipe.h:57
void pipe_init(pipe_t *pipe, ringbuffer_t *rb, void(*free)(void *))
Initialize a pipe.
void pipe_free(pipe_t *rp)
Free a pipe.
RIOT synchronization API.
A generic pipe.
Definition: pipe.h:55
pipe_t * pipe_malloc(unsigned size)
Dynamically allocate a pipe with room for size bytes.
void(* free)(void *)
Function to call by pipe_free().
Definition: pipe.h:61