@ -25,11 +25,10 @@ namespace port {
// -- is that it dynamically allocates its internals that are automatically
// -- is that it dynamically allocates its internals that are automatically
// freed when the thread terminates and not on the destruction of the
// freed when the thread terminates and not on the destruction of the
// object. This makes it difficult to control the source of memory
// object. This makes it difficult to control the source of memory
// allocation
// allocation
// - This implements Pimpl so we can easily replace the guts of the
// - This implements Pimpl so we can easily replace the guts of the
// object in our private version if necessary.
// object in our private version if necessary.
class WindowsThread {
class WindowsThread {
struct Data ;
struct Data ;
std : : shared_ptr < Data > data_ ;
std : : shared_ptr < Data > data_ ;
@ -37,15 +36,14 @@ class WindowsThread {
void Init ( std : : function < void ( ) > & & ) ;
void Init ( std : : function < void ( ) > & & ) ;
public :
public :
using native_handle_type = void * ;
typedef void * native_handle_type ;
// Construct with no thread
// Construct with no thread
WindowsThread ( ) ;
WindowsThread ( ) ;
// Template constructor
// Template constructor
//
//
// This templated constructor accomplishes several things
// This templated constructor accomplishes several things
//
//
// - Allows the class as whole to be not a template
// - Allows the class as whole to be not a template
@ -68,17 +66,12 @@ public:
// dependent type that both checks the signature conformance to ensure
// dependent type that both checks the signature conformance to ensure
// that all of the necessary arguments are provided and allows pimpl
// that all of the necessary arguments are provided and allows pimpl
// implementation.
// implementation.
template < class Fn ,
template < class Fn , class . . . Args ,
class . . . Args ,
class = typename std : : enable_if < ! std : : is_same <
class = typename std : : enable_if <
typename std : : decay < Fn > : : type , WindowsThread > : : value > : : type >
! std : : is_same < typename std : : decay < Fn > : : type ,
explicit WindowsThread ( Fn & & fx , Args & & . . . ax ) : WindowsThread ( ) {
WindowsThread > : : value > : : type >
explicit WindowsThread ( Fn & & fx , Args & & . . . ax ) :
WindowsThread ( ) {
// Use binder to create a single callable entity
// Use binder to create a single callable entity
auto binder = std : : bind ( std : : forward < Fn > ( fx ) ,
auto binder = std : : bind ( std : : forward < Fn > ( fx ) , std : : forward < Args > ( ax ) . . . ) ;
std : : forward < Args > ( ax ) . . . ) ;
// Use std::function to take advantage of the type erasure
// Use std::function to take advantage of the type erasure
// so we can still hide implementation within pimpl
// so we can still hide implementation within pimpl
// This also makes sure that the binder signature is compliant
// This also makes sure that the binder signature is compliant
@ -87,7 +80,6 @@ public:
Init ( std : : move ( target ) ) ;
Init ( std : : move ( target ) ) ;
}
}
~ WindowsThread ( ) ;
~ WindowsThread ( ) ;
WindowsThread ( const WindowsThread & ) = delete ;
WindowsThread ( const WindowsThread & ) = delete ;