Skip to content

Commit

Permalink
Disable ConcurrencyCheck by default and set using environment variable
Browse files Browse the repository at this point in the history
Currently, it is disabled at compile time. Will be quite useful to be able
turn this on in system test setup, especially in large scale setups

CONCURRENCY_CHECK_ENABLE is set in scons before launching any unit test

Closes-Bug: 1681907
Change-Id: Ib796a717c5c0cee685702be0d9f08d82c3b41859
  • Loading branch information
ananth-at-camphor-networks committed Apr 11, 2017
1 parent f723899 commit f21a4a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/base/task_annotations.cc
Expand Up @@ -6,7 +6,8 @@

#include "base/task.h"

bool ConcurrencyChecker::disable_ = getenv("CONCURRENCY_CHECK_DISABLE") != NULL;
bool ConcurrencyChecker::enable_ = getenv("CONCURRENCY_CHECK_ENABLE") != NULL &&
!strcasecmp(getenv("CONCURRENCY_CHECK_ENABLE"), "true");

ConcurrencyChecker::ConcurrencyChecker(const char *task_ids[], size_t count) {
TaskScheduler *scheduler = TaskScheduler::GetInstance();
Expand Down
31 changes: 12 additions & 19 deletions src/base/task_annotations.h
Expand Up @@ -2,18 +2,19 @@
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/

#ifndef __BASE__TASK_ANNOTATIONS_H__
#define __BASE__TASK_ANNOTATIONS_H__
#ifndef SRC_BASE_TASK_ANNOTATIONS_H_
#define SRC_BASE_TASK_ANNOTATIONS_H_

#include <stdlib.h>
#include <set>
#include <string>

#include <boost/scoped_ptr.hpp>

#include "base/task.h"
class ConcurrencyChecker {
public:
static bool disable_;
static bool enable_;
ConcurrencyChecker();
ConcurrencyChecker(const char *task_ids[], size_t count);
void Check();
Expand All @@ -35,28 +36,20 @@ class ConcurrencyScope {
boost::scoped_ptr<ScopeTask> unit_test_task_;
};

#if defined(DEBUG)
#define CHECK_CONCURRENCY(...) \
do { \
if (ConcurrencyChecker::disable_) break; \
if (!ConcurrencyChecker::enable_) 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(); \

#define CHECK_CONCURRENCY_MAIN_THR() \
do { \
if (!ConcurrencyChecker::enable_) break; \
ConcurrencyChecker checker; \
checker.CheckIfMainThr(); \
} while (0)
#else
#define CHECK_CONCURRENCY_MAIN_THR(...)
#endif

#endif
#endif // SRC_BASE_TASK_ANNOTATIONS_H_

0 comments on commit f21a4a9

Please sign in to comment.