Invert Pan-Azimuth (up means left)
[ardour.git] / libs / pbd / resource.cc
1 /*
2  * Copyright (C) 2011 Tim Mayberry <mojofunk@gmail.com>
3  * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #ifdef PLATFORM_WINDOWS
21 #include <stdio.h>
22 #else
23 #include <sys/time.h>
24 #include <sys/resource.h>
25 #endif
26
27 #include "pbd/resource.h"
28
29 namespace PBD {
30
31 bool
32 get_resource_limit (ResourceType resource, ResourceLimit& limit)
33 {
34         if (resource == OpenFiles)
35         {
36 #ifdef PLATFORM_WINDOWS
37                 limit.current_limit = _getmaxstdio();
38                 limit.max_limit = 2048;
39                 return true;
40 #else
41                 struct rlimit rl;
42                 if (getrlimit (RLIMIT_NOFILE, &rl) == 0) {
43                         limit.current_limit = rl.rlim_cur;
44                         limit.max_limit = rl.rlim_max;
45                         return true;
46                 }
47 #endif
48         }
49
50         return false;
51 }
52
53 bool
54 set_resource_limit (ResourceType resource, const ResourceLimit& limit)
55 {
56         if (resource == OpenFiles)
57         {
58 #ifdef PLATFORM_WINDOWS
59                 // no soft and hard limits on windows
60                 rlimit_t new_max = _setmaxstdio(limit.current_limit);
61
62                 if (new_max == limit.current_limit) return true;
63 #else
64                 struct rlimit rl;
65                 rl.rlim_cur = limit.current_limit;
66                 rl.rlim_max = limit.max_limit;
67                 if (setrlimit (RLIMIT_NOFILE, &rl) == 0) {
68                         return true;
69                 }
70
71 #endif
72         }
73
74         return false;
75 }
76
77 } // namespace PBD