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.
19 #include <urcu/uatomic.h>
21 #include <sys/resource.h>
26 /* total count of fd. */
30 * threshold in % of number of fd allowed.
32 static long fd_threshold
[LTTNG_FD_NR_TYPES
] = {
36 static rlim_t max_nr_fd
;
38 int lttng_fd_get(enum lttng_fd_type type
, unsigned int nr
)
42 if (type
>= LTTNG_FD_NR_TYPES
) {
46 newval
= uatomic_add_return(&fd_count
, (long) nr
);
47 if ((long) (newval
* 100)
48 - (long) (max_nr_fd
* fd_threshold
[type
]) > 0) {
49 uatomic_sub(&fd_count
, (long) nr
);
55 void lttng_fd_put(enum lttng_fd_type type
, unsigned int nr
)
57 uatomic_sub(&fd_count
, (long) nr
);
60 void lttng_fd_init(void)
65 ret
= getrlimit(RLIMIT_NOFILE
, &rlim
);
69 max_nr_fd
= rlim
.rlim_cur
;
This page took 0.031412 seconds and 5 git commands to generate.