Fix: consumerd: use packet sequence number for rotation position
[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>
40dde31f 23#include <sys/types.h>
9fd92637
DG
24
25enum lttng_pipe_state {
26 LTTNG_PIPE_STATE_OPENED = 1,
27 LTTNG_PIPE_STATE_CLOSED = 2,
28};
29
30struct lttng_pipe {
31 /* Read: 0, Write: 1. */
32 int fd[2];
33 /*
34 * Flags of the pipe once opened. pipe(2) specifies either O_NONBLOCK or
35 * O_CLOEXEC can be used. Flags are set using fcntl(2) call.
36 */
37 int flags;
38
39 /*
40 * These states are protected by the operation mutex below.
41 */
42 enum lttng_pipe_state r_state;
43 enum lttng_pipe_state w_state;
44
45 /* Held for each read(2) operation. */
46 pthread_mutex_t read_mutex;
47 /* Held for each write(2) operation. */
48 pthread_mutex_t write_mutex;
49};
50
51/*
52 * Return 1 if read side is open else 0.
53 */
427788ec 54static inline int lttng_pipe_is_read_open(const struct lttng_pipe *pipe)
9fd92637
DG
55{
56 return pipe->r_state == LTTNG_PIPE_STATE_OPENED ? 1 : 0;
57}
58
59/*
60 * Return 1 if write side is open else 0.
61 */
427788ec 62static inline int lttng_pipe_is_write_open(const struct lttng_pipe *pipe)
9fd92637
DG
63{
64 return pipe->w_state == LTTNG_PIPE_STATE_OPENED ? 1 : 0;
65}
66
427788ec 67static inline int lttng_pipe_get_readfd(const struct lttng_pipe *pipe)
9fd92637
DG
68{
69 return pipe->fd[0];
70}
71
427788ec 72static inline int lttng_pipe_get_writefd(const struct lttng_pipe *pipe)
9fd92637
DG
73{
74 return pipe->fd[1];
75}
76
a247c6e0 77LTTNG_HIDDEN
9fd92637 78struct lttng_pipe *lttng_pipe_open(int flags);
a247c6e0 79LTTNG_HIDDEN
9c2bd8db
JG
80struct lttng_pipe *lttng_pipe_named_open(const char *path, mode_t mode,
81 int flags);
82LTTNG_HIDDEN
9fd92637 83int lttng_pipe_write_close(struct lttng_pipe *pipe);
a247c6e0 84LTTNG_HIDDEN
9fd92637
DG
85int lttng_pipe_read_close(struct lttng_pipe *pipe);
86/* Close both side of pipe. */
a247c6e0 87LTTNG_HIDDEN
9fd92637 88int lttng_pipe_close(struct lttng_pipe *pipe);
a247c6e0 89LTTNG_HIDDEN
9fd92637
DG
90void lttng_pipe_destroy(struct lttng_pipe *pipe);
91
a247c6e0 92LTTNG_HIDDEN
9fd92637 93ssize_t lttng_pipe_read(struct lttng_pipe *pipe, void *buf, size_t count);
a247c6e0 94LTTNG_HIDDEN
9fd92637
DG
95ssize_t lttng_pipe_write(struct lttng_pipe *pipe, const void *buf,
96 size_t count);
55dfb029
JG
97/* Returns and releases the read end of the pipe. */
98LTTNG_HIDDEN
99int lttng_pipe_release_readfd(struct lttng_pipe *pipe);
100/* Returns and releases the write end of the pipe. */
101LTTNG_HIDDEN
102int lttng_pipe_release_writefd(struct lttng_pipe *pipe);
9fd92637
DG
103
104#endif /* LTTNG_PIPE_H */
This page took 0.064559 seconds and 4 git commands to generate.