2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
12 #include <common/macros.hpp>
13 #include <sys/types.h>
15 enum lttng_pipe_state {
16 LTTNG_PIPE_STATE_OPENED = 1,
17 LTTNG_PIPE_STATE_CLOSED = 2,
21 /* Read: 0, Write: 1. */
24 * Flags of the pipe once opened. pipe(2) specifies either O_NONBLOCK or
25 * O_CLOEXEC can be used. Flags are set using fcntl(2) call.
30 * These states are protected by the operation mutex below.
32 enum lttng_pipe_state r_state;
33 enum lttng_pipe_state w_state;
35 /* Held for each read(2) operation. */
36 pthread_mutex_t read_mutex;
37 /* Held for each write(2) operation. */
38 pthread_mutex_t write_mutex;
42 * Return 1 if read side is open else 0.
44 static inline int lttng_pipe_is_read_open(const struct lttng_pipe *pipe)
46 return pipe->r_state == LTTNG_PIPE_STATE_OPENED ? 1 : 0;
50 * Return 1 if write side is open else 0.
52 static inline int lttng_pipe_is_write_open(const struct lttng_pipe *pipe)
54 return pipe->w_state == LTTNG_PIPE_STATE_OPENED ? 1 : 0;
57 static inline int lttng_pipe_get_readfd(const struct lttng_pipe *pipe)
62 static inline int lttng_pipe_get_writefd(const struct lttng_pipe *pipe)
67 struct lttng_pipe *lttng_pipe_open(int flags);
68 struct lttng_pipe *lttng_pipe_named_open(const char *path, mode_t mode,
70 int lttng_pipe_write_close(struct lttng_pipe *pipe);
71 int lttng_pipe_read_close(struct lttng_pipe *pipe);
72 /* Close both side of pipe. */
73 int lttng_pipe_close(struct lttng_pipe *pipe);
74 void lttng_pipe_destroy(struct lttng_pipe *pipe);
76 ssize_t lttng_pipe_read(struct lttng_pipe *pipe, void *buf, size_t count);
77 ssize_t lttng_pipe_write(struct lttng_pipe *pipe, const void *buf,
79 /* Returns and releases the read end of the pipe. */
80 int lttng_pipe_release_readfd(struct lttng_pipe *pipe);
81 /* Returns and releases the write end of the pipe. */
82 int lttng_pipe_release_writefd(struct lttng_pipe *pipe);
84 #endif /* LTTNG_PIPE_H */