utility.hpp 628 B

12345678910111213141516171819202122232425262728
  1. #ifndef UTILITY_HPP
  2. #define UTILITY_HPP
  3. #include <cassert>
  4. #include <cstdint>
  5. #include <BS_thread_pool.hpp>
  6. template<size_t Align = 1>
  7. size_t alignment_round(size_t size, const size_t align = Align) {
  8. assert(std::popcount(align) == 1);
  9. if (size & (align - 1)) {
  10. size = (size + align) & ~(align - 1);
  11. }
  12. return size;
  13. }
  14. extern BS::thread_pool *g_thread_pool;
  15. template<typename Func>
  16. void thread_pool_detach_task(Func &&func) {
  17. g_thread_pool->detach_task(std::forward<Func>(func));
  18. }
  19. #define TP_DETACH(func) thread_pool_detach_task(func)
  20. #define TP_SYNC g_thread_pool->wait()
  21. #endif //UTILITY_HPP