File: lock_guard.h

package info (click to toggle)
securefs 0.11.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,684 kB
  • sloc: cpp: 11,757; python: 486; sh: 11; makefile: 7
file content (24 lines) | stat: -rw-r--r-- 626 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma once
#include "thread_safety_annotations.hpp"

namespace securefs
{
template <class Lockable>
class THREAD_ANNOTATION_SCOPED_CAPABILITY LockGuard
{
private:
    Lockable* m_lock;

public:
    explicit LockGuard(Lockable& lock, bool exclusive) THREAD_ANNOTATION_ACQUIRE(lock)
        : m_lock(&lock)
    {
        lock.lock(exclusive);
    }
    ~LockGuard() THREAD_ANNOTATION_RELEASE() { m_lock->unlock(); }
    LockGuard(LockGuard&&) = delete;
    LockGuard(const LockGuard&) = delete;
    LockGuard& operator=(LockGuard&&) = delete;
    LockGuard& operator=(const LockGuard&) = delete;
};
}    // namespace securefs