PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/usr/include/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp

https://bitbucket.org/codingwizard/omxplayer_rpi_copy
C++ Header | 331 lines | 301 code | 22 blank | 8 comment | 60 complexity | 57f72dfd6f33dd1176c879116bbaebdc MD5 | raw file
  1. // boost process_cpu_clocks.cpp -----------------------------------------------------------//
  2. // Copyright Beman Dawes 1994, 2006, 2008
  3. // Copyright Vicente J. Botet Escriba 2009
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // See http://www.boost.org/LICENSE_1_0.txt
  6. // See http://www.boost.org/libs/chrono for documentation.
  7. //--------------------------------------------------------------------------------------//
  8. #include <boost/chrono/config.hpp>
  9. #include <boost/chrono/process_cpu_clocks.hpp>
  10. #include <boost/assert.hpp>
  11. #include <sys/time.h> //for gettimeofday and timeval
  12. #include <sys/times.h> //for times
  13. # include <unistd.h>
  14. namespace boost
  15. {
  16. namespace chrono
  17. {
  18. namespace chrono_detail
  19. {
  20. inline long tick_factor() // multiplier to convert ticks
  21. // to nanoseconds; -1 if unknown
  22. {
  23. static long factor = 0;
  24. if (!factor)
  25. {
  26. if ((factor = ::sysconf(_SC_CLK_TCK)) <= 0)
  27. factor = -1;
  28. else
  29. {
  30. BOOST_ASSERT(factor <= 1000000000l); // doesn't handle large ticks
  31. factor = 1000000000l / factor; // compute factor
  32. if (!factor)
  33. factor = -1;
  34. }
  35. }
  36. return factor;
  37. }
  38. }
  39. process_real_cpu_clock::time_point process_real_cpu_clock::now() BOOST_NOEXCEPT
  40. {
  41. #if 0
  42. tms tm;
  43. clock_t c = ::times(&tm);
  44. if (c == clock_t(-1)) // error
  45. {
  46. BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  47. } else
  48. {
  49. long factor = chrono_detail::tick_factor();
  50. if (factor != -1)
  51. {
  52. return time_point(nanoseconds(c * factor));
  53. } else
  54. {
  55. BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  56. }
  57. }
  58. return time_point();
  59. #else
  60. clock_t c = ::clock();
  61. if (c == clock_t(-1)) // error
  62. {
  63. BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  64. }
  65. return time_point(
  66. duration(c*(1000000000l/CLOCKS_PER_SEC))
  67. );
  68. #endif
  69. }
  70. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  71. process_real_cpu_clock::time_point process_real_cpu_clock::now(system::error_code & ec)
  72. {
  73. #if 0
  74. tms tm;
  75. clock_t c = ::times(&tm);
  76. if (c == clock_t(-1)) // error
  77. {
  78. if (BOOST_CHRONO_IS_THROWS(ec))
  79. {
  80. boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_real_cpu_clock"));
  81. } else
  82. {
  83. ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
  84. return time_point();
  85. }
  86. } else
  87. {
  88. long factor = chrono_detail::tick_factor();
  89. if (factor != -1)
  90. {
  91. if (!BOOST_CHRONO_IS_THROWS(ec))
  92. {
  93. ec.clear();
  94. }
  95. return time_point(nanoseconds(c * factor));
  96. } else
  97. {
  98. if (BOOST_CHRONO_IS_THROWS(ec))
  99. {
  100. boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_real_cpu_clock"));
  101. } else
  102. {
  103. ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
  104. return time_point();
  105. }
  106. }
  107. }
  108. #else
  109. clock_t c = ::clock();
  110. if (c == clock_t(-1)) // error
  111. {
  112. if (BOOST_CHRONO_IS_THROWS(ec))
  113. {
  114. boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_real_cpu_clock"));
  115. } else
  116. {
  117. ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
  118. return time_point();
  119. }
  120. }
  121. return time_point(
  122. duration(c*(1000000000l/CLOCKS_PER_SEC))
  123. );
  124. #endif
  125. }
  126. #endif
  127. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  128. process_user_cpu_clock::time_point process_user_cpu_clock::now(system::error_code & ec)
  129. {
  130. tms tm;
  131. clock_t c = ::times(&tm);
  132. if (c == clock_t(-1)) // error
  133. {
  134. if (BOOST_CHRONO_IS_THROWS(ec))
  135. {
  136. boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_user_cpu_clock"));
  137. } else
  138. {
  139. ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
  140. return time_point();
  141. }
  142. } else
  143. {
  144. long factor = chrono_detail::tick_factor();
  145. if (factor != -1)
  146. {
  147. if (!BOOST_CHRONO_IS_THROWS(ec))
  148. {
  149. ec.clear();
  150. }
  151. return time_point(nanoseconds((tm.tms_utime + tm.tms_cutime) * factor));
  152. } else
  153. {
  154. if (BOOST_CHRONO_IS_THROWS(ec))
  155. {
  156. boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_user_cpu_clock"));
  157. } else
  158. {
  159. ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
  160. return time_point();
  161. }
  162. }
  163. }
  164. }
  165. #endif
  166. process_user_cpu_clock::time_point process_user_cpu_clock::now() BOOST_NOEXCEPT
  167. {
  168. tms tm;
  169. clock_t c = ::times(&tm);
  170. if (c == clock_t(-1)) // error
  171. {
  172. BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  173. } else
  174. {
  175. long factor = chrono_detail::tick_factor();
  176. if (factor != -1)
  177. {
  178. return time_point(nanoseconds((tm.tms_utime + tm.tms_cutime)
  179. * factor));
  180. } else
  181. {
  182. BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  183. }
  184. }
  185. return time_point();
  186. }
  187. process_system_cpu_clock::time_point process_system_cpu_clock::now() BOOST_NOEXCEPT
  188. {
  189. tms tm;
  190. clock_t c = ::times(&tm);
  191. if (c == clock_t(-1)) // error
  192. {
  193. BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  194. } else
  195. {
  196. long factor = chrono_detail::tick_factor();
  197. if (factor != -1)
  198. {
  199. return time_point(nanoseconds((tm.tms_stime + tm.tms_cstime)
  200. * factor));
  201. } else
  202. {
  203. BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  204. }
  205. }
  206. return time_point();
  207. }
  208. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  209. process_system_cpu_clock::time_point process_system_cpu_clock::now(system::error_code & ec)
  210. {
  211. tms tm;
  212. clock_t c = ::times(&tm);
  213. if (c == clock_t(-1)) // error
  214. {
  215. if (BOOST_CHRONO_IS_THROWS(ec))
  216. {
  217. boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_system_cpu_clock"));
  218. } else
  219. {
  220. ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
  221. return time_point();
  222. }
  223. } else
  224. {
  225. long factor = chrono_detail::tick_factor();
  226. if (factor != -1)
  227. {
  228. if (!BOOST_CHRONO_IS_THROWS(ec))
  229. {
  230. ec.clear();
  231. }
  232. return time_point(nanoseconds((tm.tms_stime + tm.tms_cstime) * factor));
  233. } else
  234. {
  235. if (BOOST_CHRONO_IS_THROWS(ec))
  236. {
  237. boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_system_cpu_clock"));
  238. } else
  239. {
  240. ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
  241. return time_point();
  242. }
  243. }
  244. }
  245. }
  246. #endif
  247. process_cpu_clock::time_point process_cpu_clock::now() BOOST_NOEXCEPT
  248. {
  249. tms tm;
  250. clock_t c = ::times(&tm);
  251. if (c == clock_t(-1)) // error
  252. {
  253. BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  254. } else
  255. {
  256. long factor = chrono_detail::tick_factor();
  257. if (factor != -1)
  258. {
  259. time_point::rep
  260. r(c * factor, (tm.tms_utime + tm.tms_cutime) * factor, (tm.tms_stime
  261. + tm.tms_cstime) * factor);
  262. return time_point(duration(r));
  263. } else
  264. {
  265. BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  266. }
  267. }
  268. return time_point();
  269. }
  270. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  271. process_cpu_clock::time_point process_cpu_clock::now(system::error_code & ec)
  272. {
  273. tms tm;
  274. clock_t c = ::times(&tm);
  275. if (c == clock_t(-1)) // error
  276. {
  277. if (BOOST_CHRONO_IS_THROWS(ec))
  278. {
  279. boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_clock"));
  280. } else
  281. {
  282. ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
  283. return time_point();
  284. }
  285. } else
  286. {
  287. long factor = chrono_detail::tick_factor();
  288. if (factor != -1)
  289. {
  290. time_point::rep
  291. r(c * factor, (tm.tms_utime + tm.tms_cutime) * factor, (tm.tms_stime
  292. + tm.tms_cstime) * factor);
  293. return time_point(duration(r));
  294. } else
  295. {
  296. if (BOOST_CHRONO_IS_THROWS(ec))
  297. {
  298. boost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_clock"));
  299. } else
  300. {
  301. ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY);
  302. return time_point();
  303. }
  304. }
  305. }
  306. }
  307. #endif
  308. }
  309. }