Welcome to mirror list, hosted at ThFree Co, Russian Federation.

thread_checker.hpp « base - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e5f44b74863e349628091b0055860dd3cefb7823 (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
#pragma once

#include "base/assert.hpp"
#include "base/macros.hpp"

#include "std/thread.hpp"

/// This class remembers id of a thread on which it was created, and
/// then can be used to verify that CalledOnOriginalThread() is called
/// from a thread on which it was created.
class ThreadChecker
{
public:
  ThreadChecker();

  /// \return True if this method is called from a thread on which
  ///         current ThreadChecker's instance was created, false otherwise.
  bool CalledOnOriginalThread() const;

private:
  thread::id const m_id;

  DISALLOW_COPY_AND_MOVE(ThreadChecker);
};

#if defined(DEBUG)
  #define DECLARE_THREAD_CHECKER(threadCheckerName) ThreadChecker threadCheckerName
  #define ASSERT_THREAD_CHECKER(threadCheckerName, msg) ASSERT(threadCheckerName.CalledOnOriginalThread(), msg)
  #define DECLARE_AND_ASSERT_THREAD_CHECKER(msg) \
  { \
    static const ThreadChecker threadChecker; \
    ASSERT(threadChecker.CalledOnOriginalThread(), (msg)); \
  }
#else
  #define DECLARE_THREAD_CHECKER(threadCheckerName)
  #define ASSERT_THREAD_CHECKER(threadCheckerName, msg)
  #define DECLARE_AND_ASSERT_THREAD_CHECKER(msg)
#endif