medfall

A super great game engine
Log | Files | Refs

dyn_thread.hpp (1048B)


      1 /*  Relacy Race Detector
      2  *  Copyright (c) 2008-2013, Dmitry S. Vyukov
      3  *  All rights reserved.
      4  *  This software is provided AS-IS with no warranty, either express or implied.
      5  *  This software is distributed under a license and may not be copied,
      6  *  modified or distributed except as expressly authorized under the
      7  *  terms of the license contained in the file LICENSE in this distribution.
      8  */
      9 
     10 #ifndef RL_DYN_THREAD_HPP
     11 #define RL_DYN_THREAD_HPP
     12 #ifdef _MSC_VER
     13 #   pragma once
     14 #endif
     15 
     16 #include "base.hpp"
     17 #include "context_base.hpp"
     18 #include "stdlib/semaphore.hpp"
     19 
     20 
     21 namespace rl
     22 {
     23 
     24 
     25 class dyn_thread : nocopy<>
     26 {
     27 public:
     28     dyn_thread()
     29     {
     30         handle_ = 0;
     31     }
     32 
     33     void start(void*(*fn)(void*), void* arg)
     34     {
     35         RL_VERIFY(handle_ == 0);
     36         handle_ = ctx().create_thread(fn, arg);
     37     }
     38 
     39     void join()
     40     {
     41         RL_VERIFY(handle_);
     42         handle_->wait(false, false, $);
     43         handle_ = 0;
     44     }
     45 
     46 private:
     47     win_waitable_object* handle_;
     48 };
     49 
     50 
     51 }
     52 
     53 #endif