-
Notifications
You must be signed in to change notification settings - Fork 390
/
task_annotations.h
62 lines (54 loc) · 1.71 KB
/
task_annotations.h
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef __BASE__TASK_ANNOTATIONS_H__
#define __BASE__TASK_ANNOTATIONS_H__
#include <stdlib.h>
#include <set>
#include <boost/scoped_ptr.hpp>
#include "base/task.h"
class ConcurrencyChecker {
public:
static bool disable_;
ConcurrencyChecker();
ConcurrencyChecker(const char *task_ids[], size_t count);
void Check();
void CheckIfMainThr();
static bool IsInMainThr() { return (Task::Running() == NULL); }
private:
typedef std::set<int> TaskIdSet;
TaskIdSet id_set_;
};
class ConcurrencyScope {
public:
explicit ConcurrencyScope(int task_id);
explicit ConcurrencyScope(const std::string &task_id);
~ConcurrencyScope();
private:
class ScopeTask;
void SetRunningTask(int task_id);
boost::scoped_ptr<ScopeTask> unit_test_task_;
};
#if defined(DEBUG)
#define CHECK_CONCURRENCY(...) \
do { \
if (ConcurrencyChecker::disable_) break; \
const char *_X_array[] = { __VA_ARGS__ }; \
ConcurrencyChecker checker( \
_X_array, sizeof(_X_array) / sizeof(char *)); \
checker.Check(); \
} while (0)
#else
#define CHECK_CONCURRENCY(...)
#endif
#if defined(DEBUG)
#define CHECK_CONCURRENCY_MAIN_THR() \
do { \
if (ConcurrencyChecker::disable_) break; \
ConcurrencyChecker checker; \
checker.CheckIfMainThr(); \
} while (0)
#else
#define CHECK_CONCURRENCY_MAIN_THR(...)
#endif
#endif