summaryrefslogtreecommitdiffstats
path: root/src/ui/operation-blocker.h
blob: b9d714c3252ece781fffdffcd61c4eb072e303c9 (plain)
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
36
37
38
// SPDX-License-Identifier: GPL-2.0-or-later

#ifndef SEEN_OPERATION_BLOCKER_H
#define SEEN_OPERATION_BLOCKER_H

// cooperative counter-based pending operation blocking

class OperationBlocker {
public:
    OperationBlocker() = default;
    
    bool pending() const {
        return _counter > 0;
    }

    class scoped_block {
    public:
        scoped_block(unsigned int& counter): _c(counter) {
            ++_c;
        }

        ~scoped_block() {
            --_c;
        }

    private:
        unsigned int& _c;
    };

    scoped_block block() {
        return scoped_block(_counter);
    }

private:
    unsigned int _counter = 0;
};

#endif