LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-common/base - task_annotations.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 1 1 100.0 %
Date: 2026-08-03 02:19:58 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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"
      15             : class ConcurrencyChecker {
      16             : public:
      17             :     static bool enable_;
      18             :     ConcurrencyChecker();
      19             :     ConcurrencyChecker(const char *task_ids[], size_t count);
      20             :     void Check();
      21             :     void CheckIfMainThr();
      22         467 :     static bool IsInMainThr() { return (Task::Running() == NULL); }
      23             : private:
      24             :     typedef std::set<int> TaskIdSet;
      25             :     TaskIdSet id_set_;
      26             : };
      27             : 
      28             : class ConcurrencyScope {
      29             : public:
      30             :     explicit ConcurrencyScope(int task_id);
      31             :     explicit ConcurrencyScope(const std::string &task_id);
      32             :     ~ConcurrencyScope();
      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_

Generated by: LCOV version 1.14