OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
task_annotations.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef SRC_BASE_TASK_ANNOTATIONS_H_
6 #define SRC_BASE_TASK_ANNOTATIONS_H_
7 
8 #include <stdlib.h>
9 #include <set>
10 #include <string>
11 
12 #include <boost/scoped_ptr.hpp>
13 
14 #include "base/task.h"
16 public:
17  static bool enable_;
19  ConcurrencyChecker(const char *task_ids[], size_t count);
20  void Check();
21  void CheckIfMainThr();
22  static bool IsInMainThr() { return (Task::Running() == NULL); }
23 private:
24  typedef std::set<int> TaskIdSet;
26 };
27 
29 public:
30  explicit ConcurrencyScope(int task_id);
31  explicit ConcurrencyScope(const std::string &task_id);
33 private:
34  class ScopeTask;
35  void SetRunningTask(int task_id);
36  boost::scoped_ptr<ScopeTask> unit_test_task_;
37 };
38 
39 #define CHECK_CONCURRENCY(...) \
40  do { \
41  if (!ConcurrencyChecker::enable_) break; \
42  const char *_X_array[] = { __VA_ARGS__ }; \
43  ConcurrencyChecker checker( \
44  _X_array, sizeof(_X_array) / sizeof(char *)); \
45  checker.Check(); \
46  } while (0)
47 
48 #define CHECK_CONCURRENCY_MAIN_THR() \
49  do { \
50  if (!ConcurrencyChecker::enable_) break; \
51  ConcurrencyChecker checker; \
52  checker.CheckIfMainThr(); \
53  } while (0)
54 
55 #endif // SRC_BASE_TASK_ANNOTATIONS_H_
static Task * Running()
Returns a pointer to the current task the code is executing under.
Definition: task.cc:1562
void SetRunningTask(int task_id)
boost::scoped_ptr< ScopeTask > unit_test_task_
std::set< int > TaskIdSet
static bool IsInMainThr()
ConcurrencyScope(int task_id)