19 #include "../core/application.hpp"
21 #include <boost/exception/diagnostic_information.hpp>
22 #include <boost/program_options.hpp>
29 #include <sys/resource.h>
32 "/******************************************************************************\n"
33 "** Copyright © 2019 by J.M.McGuiness, coder@hussar.me.uk\n"
35 "** This library is free software; you can redistribute it and/or\n"
36 "** modify it under the terms of the GNU Lesser General Public\n"
37 "** License as published by the Free Software Foundation; either\n"
38 "** version 2.1 of the License, or (at your option) any later version.\n"
40 "** This library is distributed in the hope that it will be useful,\n"
41 "** but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
42 "** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
43 "** Lesser General Public License for more details.\n"
45 "** You should have received a copy of the GNU Lesser General Public\n"
46 "** License along with this library; if not, write to the Free Software\n"
47 "** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
72 <<
"#ifndef LIBJMMCG_UNIX_"<<std::filesystem::path(fname).stem().string()<<
"_HPP\n"
73 "#define LIBJMMCG_UNIX_"<<std::filesystem::path(fname).stem().string()<<
"_HPP\n"
75 <<
"// Auto-generated header file.\n"
76 "// DO NOT EDIT. IT WILL BE OVERWRITTEN.\n"
80 "\t\\file The constants created in this file are used in api_threading_traits::set_kernel_priority(), so must not be manually doctored! To re-generate this file for your O/S, run '"<<exe<<
"' in the installation directory as a suitable user.\n"
82 "namespace jmmcg { namespace LIBJMMCG_VER_NAMESPACE { namespace ppd { namespace private_ {\n";
92 int err=::getrlimit(RLIMIT_NICE, &lim);
94 throw std::runtime_error(
"Failed to get the rlimit of the priorities.");
96 lim.rlim_cur=lim.rlim_max;
97 err=::setrlimit(RLIMIT_NICE, &lim);
99 throw std::runtime_error(
"Failed to update the rlimit of the priorities.");
103 if ((max_priority!=-1) && (min_priority!=-1)) {
104 return std::make_pair(min_priority, max_priority);
106 throw std::runtime_error(
"Failed to get the max & min priorities of the scheduler.");
112 main(
int argc,
char const *
const *argv)
noexcept(
true) {
114 boost::program_options::options_description general(
115 "A program to discover the minimum and maximum scheduler-priorities on the current system and put them into a C++ header-file. For details regarding the properties of this program, see the documentation that came with the distribution. Copyright © J.M.McGuiness, coder@hussar.me.uk. http://libjmmcg.sf.net/ Distributed under the terms of the GPL v2.1.\n"+
exit_codes::to_string()+
"Arguments"
117 general.add_options()
118 (
"help",
"Print this help message.")
119 (
"version",
"Print the build number of this program.")
121 boost::program_options::options_description prog_opts(
"Program options.");
122 prog_opts.add_options()
123 (
"cpp_header",
boost::program_options::value<
std::string>()->required(),
"The file-path of the output C++ header-file.")
125 boost::program_options::options_description all(
"All options.");
126 all.add(general).add(prog_opts);
127 boost::program_options::variables_map vm;
128 boost::program_options::store(
boost::program_options::parse_command_line(argc, argv, all), vm);
129 if (vm.count(
"help")) {
130 std::cout<<all<<
std::endl;
133 if (vm.count(
"version")) {
137 boost::program_options::notify(vm);
139 std::ofstream cpp_header(vm[
"cpp_header"].as<std::string>().c_str());
140 const header_guard_t header_guard(std::filesystem::path(argv[0]).filename().string(), vm[
"cpp_header"].as<std::string>(), cpp_header);
141 auto const &sched_min_max=get_sched_min_max();
143 <<
"\nenum scheduler_policy : int {\n"
144 <<
"\tschedule_policy="<<schedule_policy<<
"\n"
146 "\nenum scheduler_min_max_priorities : int {\n"
147 "\tscheduler_min_priority="<<sched_min_max.first<<
",\n"
148 "\tscheduler_max_priority="<<sched_min_max.second<<
"\n"
152 }
catch (
std::exception
const &ex) {
153 std::cerr<<
"STL-derived exception. Details: "<<
boost::diagnostic_information(ex)<<
std::endl;
156 std::cerr<<
"Unknown exception."<<
std::endl;