2 * Copyright (C) 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
9 #include <urcu/uatomic.h>
11 #include <sys/resource.h>
14 #include <common/error.h>
15 #include <common/compat/errno.h>
17 /* total count of fd. */
21 * threshold in % of number of fd allowed.
23 static long fd_threshold
[LTTNG_FD_NR_TYPES
] = {
24 75, /* LTTNG_FD_APPS */
27 static rlim_t max_nr_fd
;
29 int lttng_fd_get(enum lttng_fd_type type
, unsigned int nr
)
33 if (type
>= LTTNG_FD_NR_TYPES
) {
37 newval
= uatomic_add_return(&fd_count
, (long) nr
);
38 if ((long) (newval
* 100)
39 - (long) (max_nr_fd
* fd_threshold
[type
]) > 0) {
40 uatomic_sub(&fd_count
, (long) nr
);
46 void lttng_fd_put(enum lttng_fd_type type
, unsigned int nr
)
48 uatomic_sub(&fd_count
, (long) nr
);
51 void lttng_fd_init(void)
56 ret
= getrlimit(RLIMIT_NOFILE
, &rlim
);
60 max_nr_fd
= rlim
.rlim_cur
;
This page took 0.033093 seconds and 4 git commands to generate.