notification-thread: drain all tracer notification on removal
[lttng-tools.git] / src / common / pipe.h
CommitLineData
9fd92637 1/*
ab5be9fa 2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
9fd92637 3 *
ab5be9fa 4 * SPDX-License-Identifier: GPL-2.0-only
9fd92637 5 *
9fd92637
DG
6 */
7
8#ifndef LTTNG_PIPE_H
9#define LTTNG_PIPE_H
10
11#include <pthread.h>
a247c6e0 12#include <common/macros.h>
40dde31f 13#include <sys/types.h>
9fd92637
DG
14
15enum lttng_pipe_state {
16 LTTNG_PIPE_STATE_OPENED = 1,
17 LTTNG_PIPE_STATE_CLOSED = 2,
18};
19
20struct lttng_pipe {
21 /* Read: 0, Write: 1. */
22 int fd[2];
23 /*
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.
26 */
27 int flags;
28
29 /*
30 * These states are protected by the operation mutex below.
31 */
32 enum lttng_pipe_state r_state;
33 enum lttng_pipe_state w_state;
34
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;
39};
40
41/*
42 * Return 1 if read side is open else 0.
43 */
40b66b26 44static inline int lttng_pipe_is_read_open(const struct lttng_pipe *pipe)
9fd92637
DG
45{
46 return pipe->r_state == LTTNG_PIPE_STATE_OPENED ? 1 : 0;
47}
48
49/*
50 * Return 1 if write side is open else 0.
51 */
40b66b26 52static inline int lttng_pipe_is_write_open(const struct lttng_pipe *pipe)
9fd92637
DG
53{
54 return pipe->w_state == LTTNG_PIPE_STATE_OPENED ? 1 : 0;
55}
56
40b66b26 57static inline int lttng_pipe_get_readfd(const struct lttng_pipe *pipe)
9fd92637
DG
58{
59 return pipe->fd[0];
60}
61
40b66b26 62static inline int lttng_pipe_get_writefd(const struct lttng_pipe *pipe)
9fd92637
DG
63{
64 return pipe->fd[1];
65}
66
a247c6e0 67LTTNG_HIDDEN
9fd92637 68struct lttng_pipe *lttng_pipe_open(int flags);
a247c6e0 69LTTNG_HIDDEN
9c2bd8db
JG
70struct lttng_pipe *lttng_pipe_named_open(const char *path, mode_t mode,
71 int flags);
72LTTNG_HIDDEN
9fd92637 73int lttng_pipe_write_close(struct lttng_pipe *pipe);
a247c6e0 74LTTNG_HIDDEN
9fd92637
DG
75int lttng_pipe_read_close(struct lttng_pipe *pipe);
76/* Close both side of pipe. */
a247c6e0 77LTTNG_HIDDEN
9fd92637 78int lttng_pipe_close(struct lttng_pipe *pipe);
a247c6e0 79LTTNG_HIDDEN
9fd92637
DG
80void lttng_pipe_destroy(struct lttng_pipe *pipe);
81
a247c6e0 82LTTNG_HIDDEN
9fd92637 83ssize_t lttng_pipe_read(struct lttng_pipe *pipe, void *buf, size_t count);
a247c6e0 84LTTNG_HIDDEN
9fd92637
DG
85ssize_t lttng_pipe_write(struct lttng_pipe *pipe, const void *buf,
86 size_t count);
55dfb029
JG
87/* Returns and releases the read end of the pipe. */
88LTTNG_HIDDEN
89int lttng_pipe_release_readfd(struct lttng_pipe *pipe);
90/* Returns and releases the write end of the pipe. */
91LTTNG_HIDDEN
92int lttng_pipe_release_writefd(struct lttng_pipe *pipe);
9fd92637
DG
93
94#endif /* LTTNG_PIPE_H */
This page took 0.053157 seconds and 4 git commands to generate.