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>
25 #include <common/error.h>
27 /* total count of fd. */
31 * threshold in % of number of fd allowed.
33 static long fd_threshold
[LTTNG_FD_NR_TYPES
] = {
37 static rlim_t max_nr_fd
;
39 int lttng_fd_get(enum lttng_fd_type type
, unsigned int nr
)
43 if (type
>= LTTNG_FD_NR_TYPES
) {
47 newval
= uatomic_add_return(&fd_count
, (long) nr
);
48 if ((long) (newval
* 100)
49 - (long) (max_nr_fd
* fd_threshold
[type
]) > 0) {
50 uatomic_sub(&fd_count
, (long) nr
);
56 void lttng_fd_put(enum lttng_fd_type type
, unsigned int nr
)
58 uatomic_sub(&fd_count
, (long) nr
);
61 void lttng_fd_init(void)
66 ret
= getrlimit(RLIMIT_NOFILE
, &rlim
);
70 max_nr_fd
= rlim
.rlim_cur
;
This page took 0.042821 seconds and 4 git commands to generate.