2 * Copyright (C) 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <urcu/uatomic.h>
22 #include <sys/resource.h>
26 #include <common/error.h>
28 /* total count of fd. */
32 * threshold in % of number of fd allowed.
34 static long fd_threshold
[LTTNG_FD_NR_TYPES
] = {
38 static rlim_t max_nr_fd
;
40 int lttng_fd_get(enum lttng_fd_type type
, unsigned int nr
)
44 if (type
>= LTTNG_FD_NR_TYPES
) {
48 newval
= uatomic_add_return(&fd_count
, (long) nr
);
49 if ((long) (newval
* 100)
50 - (long) (max_nr_fd
* fd_threshold
[type
]) > 0) {
51 uatomic_sub(&fd_count
, (long) nr
);
57 void lttng_fd_put(enum lttng_fd_type type
, unsigned int nr
)
59 uatomic_sub(&fd_count
, (long) nr
);
62 void lttng_fd_init(void)
67 ret
= getrlimit(RLIMIT_NOFILE
, &rlim
);
71 max_nr_fd
= rlim
.rlim_cur
;
This page took 0.031612 seconds and 5 git commands to generate.