sigslot.cpp 1.41 KB
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
#include "sigslot.h"

namespace sigslot {

    signal_manager::signal_manager() {

    }

    signal_manager::~signal_manager() {

    }

    void signal_manager::triggerSignal(_signal_handle_base* signal) const {
        signal->emitSignal();
        delete signal;
    }

    bool signal_manager::queueSignal(_signal_handle_base* signal) {
        tgtAssert(signal != 0, "Signal must not be 0.");
        if (signal == 0)
            return false;

        _signalQueue.push(signal);
        _evaluationCondition.notify_all();
        return true;
    }

    void signal_manager::run() {
29
        _this_thread_id = std::this_thread::get_id();
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        std::unique_lock<tbb::mutex> lock(_ecMutex);

        while (! _stopExecution) {
            // try pop the next event from the event queue
            _signal_handle_base* signal;
            if (_signalQueue.try_pop(signal)) {
                signal->emitSignal();
                delete signal;
            }
            else {
                // there currently is no event in this queue -> go sleep
                _evaluationCondition.wait(lock);
            }
        }
    }

    void signal_manager::stop() {
        _evaluationCondition.notify_all(); 
        tgt::Runnable::stop();
    }

51
52
53
54
    bool signal_manager::isCurrentThreadSignalManagerThread() const {
        return std::this_thread::get_id() == _this_thread_id;
    }

55
56
57
58

    const std::string signal_manager::loggerCat_;

}