pipe.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2014 RenĂ© Kijewski <rene.kijewski@fu-berlin.de>
3  * SPDX-License-Identifier: LGPL-2.1-or-later
4  */
5 
6 #pragma once
7 
24 #include <sys/types.h>
25 
26 #include "mutex.h"
27 #include "ringbuffer.h"
28 #include "thread.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #ifndef PIPE_BUF
35 # define PIPE_BUF (128)
36 #endif
37 
41 typedef struct riot_pipe {
47  void (*free)(void *);
49  } pipe_t;
50 
58 void pipe_init(pipe_t *pipe, ringbuffer_t *rb, void (*free)(void *));
59 
72 ssize_t pipe_read(pipe_t *pipe, void *buf, size_t n);
73 
86 ssize_t pipe_write(pipe_t *pipe, const void *buf, size_t n);
87 
95 pipe_t *pipe_malloc(unsigned size);
96 
104 void pipe_free(pipe_t *rp);
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
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:167
Ringbuffer.
Definition: ringbuffer.h:32
A generic pipe.
Definition: pipe.h:41
thread_t * read_blocked
A thread that wants to write to this full pipe.
Definition: pipe.h:43
ringbuffer_t * rb
Wrapped ringbuffer.
Definition: pipe.h:42
void(* free)(void *)
Function to call by pipe_free().
Definition: pipe.h:47
thread_t * write_blocked
A thread that wants to read from this empty pipe.
Definition: pipe.h:45