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 
19 #pragma once
20 
37 #include <sys/types.h>
38 
39 #include "mutex.h"
40 #include "ringbuffer.h"
41 #include "thread.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #ifndef PIPE_BUF
48 # define PIPE_BUF (128)
49 #endif
50 
54 typedef struct riot_pipe {
60  void (*free)(void *);
62  } pipe_t;
63 
71 void pipe_init(pipe_t *pipe, ringbuffer_t *rb, void (*free)(void *));
72 
85 ssize_t pipe_read(pipe_t *pipe, void *buf, size_t n);
86 
99 ssize_t pipe_write(pipe_t *pipe, const void *buf, size_t n);
100 
108 pipe_t *pipe_malloc(unsigned size);
109 
117 void pipe_free(pipe_t *rp);
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 
void free(void *ptr)
This is a no-op.
pipe_t * pipe_malloc(unsigned size)
Dynamically allocate a pipe with room for size bytes.
ssize_t pipe_read(pipe_t *pipe, void *buf, size_t n)
Read from a pipe.
void pipe_free(pipe_t *rp)
Free a pipe.
struct riot_pipe pipe_t
A generic pipe.
ssize_t pipe_write(pipe_t *pipe, const void *buf, size_t n)
Write to a pipe.
void pipe_init(pipe_t *pipe, ringbuffer_t *rb, void(*free)(void *))
Initialize a pipe.
Mutex for thread synchronization.
A utility for storing and retrieving byte data using a ring buffer.
thread_t holds thread's context data.
Definition: thread.h:170
Ringbuffer.
Definition: ringbuffer.h:35
A generic pipe.
Definition: pipe.h:54
thread_t * read_blocked
A thread that wants to write to this full pipe.
Definition: pipe.h:56
ringbuffer_t * rb
Wrapped ringbuffer.
Definition: pipe.h:55
void(* free)(void *)
Function to call by pipe_free().
Definition: pipe.h:60
thread_t * write_blocked
A thread that wants to read from this empty pipe.
Definition: pipe.h:58