runnable.cpp 708 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "runnable.h"

namespace TUMVis {
    namespace {
        void invokeThread(Runnable* r) {
            r->run();
        }
    }

    Runnable::Runnable() 
        : _stopExecution()
        , _thread() 
    {
        _stopExecution = false;
    }

    Runnable::~Runnable() {
        stop();
    }

    void Runnable::stop() {
        _stopExecution = true; 
        try { 
            _thread.join(); 
        } 
        catch(std::exception& e) { 
            LERRORC("TUMVis.core.tools.Runnable", "Caught exception during _thread.join: " << e.what());
        } 
    }

    void Runnable::start() { 
        _thread = std::thread(&invokeThread, this);
    }
}