Fix: add missing semicolons after MSG, DBG, ERR print macros
[lttng-tools.git] / src / common / pipe.h
CommitLineData
9fd92637
DG
1/*
2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18#ifndef LTTNG_PIPE_H
19#define LTTNG_PIPE_H
20
21#include <pthread.h>
a247c6e0 22#include <common/macros.h>
9fd92637
DG
23
24enum lttng_pipe_state {
25 LTTNG_PIPE_STATE_OPENED = 1,
26 LTTNG_PIPE_STATE_CLOSED = 2,
27};
28
29struct lttng_pipe {
30 /* Read: 0, Write: 1. */
31 int fd[2];
32 /*
33 * Flags of the pipe once opened. pipe(2) specifies either O_NONBLOCK or
34 * O_CLOEXEC can be used. Flags are set using fcntl(2) call.
35 */
36 int flags;
37
38 /*
39 * These states are protected by the operation mutex below.
40 */
41 enum lttng_pipe_state r_state;
42 enum lttng_pipe_state w_state;
43
44 /* Held for each read(2) operation. */
45 pthread_mutex_t read_mutex;
46 /* Held for each write(2) operation. */
47 pthread_mutex_t write_mutex;
48};
49
50/*
51 * Return 1 if read side is open else 0.
52 */
53static inline int lttng_pipe_is_read_open(struct lttng_pipe *pipe)
54{
55 return pipe->r_state == LTTNG_PIPE_STATE_OPENED ? 1 : 0;
56}
57
58/*
59 * Return 1 if write side is open else 0.
60 */
61static inline int lttng_pipe_is_write_open(struct lttng_pipe *pipe)
62{
63 return pipe->w_state == LTTNG_PIPE_STATE_OPENED ? 1 : 0;
64}
65
66static inline int lttng_pipe_get_readfd(struct lttng_pipe *pipe)
67{
68 return pipe->fd[0];
69}
70
71static inline int lttng_pipe_get_writefd(struct lttng_pipe *pipe)
72{
73 return pipe->fd[1];
74}
75
a247c6e0 76LTTNG_HIDDEN
9fd92637 77struct lttng_pipe *lttng_pipe_open(int flags);
a247c6e0 78LTTNG_HIDDEN
9fd92637 79int lttng_pipe_write_close(struct lttng_pipe *pipe);
a247c6e0 80LTTNG_HIDDEN
9fd92637
DG
81int lttng_pipe_read_close(struct lttng_pipe *pipe);
82/* Close both side of pipe. */
a247c6e0 83LTTNG_HIDDEN
9fd92637 84int lttng_pipe_close(struct lttng_pipe *pipe);
a247c6e0 85LTTNG_HIDDEN
9fd92637
DG
86void lttng_pipe_destroy(struct lttng_pipe *pipe);
87
a247c6e0 88LTTNG_HIDDEN
9fd92637 89ssize_t lttng_pipe_read(struct lttng_pipe *pipe, void *buf, size_t count);
a247c6e0 90LTTNG_HIDDEN
9fd92637
DG
91ssize_t lttng_pipe_write(struct lttng_pipe *pipe, const void *buf,
92 size_t count);
93
94#endif /* LTTNG_PIPE_H */
This page took 0.03573 seconds and 4 git commands to generate.