1 #if !defined(_BTK_IMPL_THREAD_HPP_)     2 #define _BTK_IMPL_THREAD_HPP_     3 #include <SDL2/SDL_thread.h>     4 #include <SDL2/SDL_mutex.h>     8 #include "../exception.hpp"    12         template<
class T,
class ...Args>
    15             std::tuple<Args...> args;
    17             static int SDLCALL Run(
void *__self){
    18                 std::unique_ptr<ThreadInvoker> ptr(static_cast<ThreadInvoker*>(__self));
    19                 std::apply(ptr->callable,ptr->args);
    34             template<
class Callable,
class ...Args>
    35             Thread(Callable &&callable,Args ...args){
    37                     <std::remove_reference_t<Callable>,Args...>;
    40                 auto *invoker = 
new InvokerType{
    41                     std::forward<Callable>(callable),
    42                     {std::forward<Args>(args)...}
    44                 thrd = SDL_CreateThread(
    50             template<
class Callable,
class ...Args>
    51             Thread(
const char *name,Callable &&callable,Args ...args){
    53                     <std::remove_reference_t<Callable>,Args...>;
    56                 auto *invoker = 
new InvokerType{
    57                     std::forward<Callable>(callable),
    58                     {std::forward<Args>(args)...}
    60                 thrd = SDL_CreateThread(
    73                 SDL_WaitThread(thrd,
nullptr);
    79                 SDL_WaitThread(thrd,
nullptr);
    86                 SDL_DetachThread(thrd);
   100             void lock() noexcept{
   101                 SDL_AtomicLock(&slock);
   103             void unlock() noexcept{
   104                 SDL_AtomicUnlock(&slock);
   106             bool try_lock() noexcept{
   107                 return SDL_AtomicTryLock(&slock);
   110             SDL_SpinLock slock = 0;
   115 #endif // _BTK_IMPL_THREAD_HPP_ Definition: thread.hpp:24
This header include many useful containers. 
Definition: async.hpp:7
Definition: thread.hpp:98
Thread(Callable &&callable, Args ...args)
Construct a new Thread object. 
Definition: thread.hpp:35
Definition: thread.hpp:13