Changeset 35:f8a5b321d0c3 in xplcommon for src/xplcommon/win32/Thread.h


Ignore:
Timestamp:
01/03/13 06:57:15 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added support for detached threads

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/xplcommon/win32/Thread.h

    r20 r35  
    5858
    5959    /**
     60     * Indicate if the thread is detached.
     61     */
     62    bool detached;
     63
     64    /**
    6065     * The thread handle.
    6166     */
     
    6368
    6469public:
     70    /**
     71     * Construct the thread object.
     72     */
     73    Thread(bool detached = false);
     74
    6575    /**
    6676     * Virtual destructor.
     
    8494     */
    8595    void join();
     96
     97    void release();
    8698};
    8799
     
    97109//------------------------------------------------------------------------------
    98110
     111inline Thread::Thread(bool detached) :
     112    detached(detached),
     113    handle(0)
     114{
     115}
     116
     117//------------------------------------------------------------------------------
     118
    99119inline Thread::~Thread()
    100120{
     
    106126{
    107127    handle = CreateThread(0, 0, &threadFn, this, 0, 0);
    108     return handle!=0;
     128    bool isOK = handle!=0;
     129    if (detached && handle!=0) {
     130        CloseHandle(handle);
     131        handle = 0;
     132    }
     133    return isOK;
    109134}
    110135
     
    113138inline void Thread::join()
    114139{
    115     WaitForSingleObject(handle, INFINITE);
     140    if (handle!=0) {
     141        WaitForSingleObject(handle, INFINITE);
     142        CloseHandle(handle);
     143    }
    116144}
    117145
Note: See TracChangeset for help on using the changeset viewer.