OpenSDN source code
task_annotations.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
7 
8 #include <strings.h>
9 #include "base/task.h"
10 
11 bool ConcurrencyChecker::enable_ = getenv("CONCURRENCY_CHECK_ENABLE") != NULL &&
12  !strcasecmp(getenv("CONCURRENCY_CHECK_ENABLE"), "true");
13 
14 ConcurrencyChecker::ConcurrencyChecker(const char *task_ids[], size_t count) {
16  for (size_t i = 0; i < count; i++) {
17  id_set_.insert(scheduler->GetTaskId(task_ids[i]));
18  }
19 }
20 
22 }
23 
25  Task *current = Task::Running();
26  assert(current != NULL);
27  assert(id_set_.count(current->task_code_id()) > 0);
28 }
29 
31  Task *current = Task::Running();
32  assert(current == NULL);
33 }
34 
36 public:
37  ScopeTask(int task_id) : Task(task_id) {
38  };
39  bool Run() {
40  return false;
41  }
42  std::string Description() const { return "ConcurrencyScope::ScopeTask"; }
44  }
45 };
46 
48  SetRunningTask(task_id);
49 }
50 
51 ConcurrencyScope::ConcurrencyScope(const std::string &name) {
53  SetRunningTask(scheduler->GetTaskId(name));
54 }
55 
58  unit_test_task_.reset(new ScopeTask(task_id));
59  scheduler->SetRunningTask(unit_test_task_.get());
60 }
61 
64  scheduler->ClearRunningTask();
65 }
std::string Description() const
Gives a description of the task.
bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
ConcurrencyScope(int task_id)
void SetRunningTask(int task_id)
boost::scoped_ptr< ScopeTask > unit_test_task_
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:307
int GetTaskId(const std::string &name)
Definition: task.cc:884
void ClearRunningTask()
Definition: task.cc:981
static TaskScheduler * GetInstance()
Definition: task.cc:574
void SetRunningTask(Task *)
This function should not be called in production code. It is only for unit testing to control current...
Definition: task.cc:976
Task is a class to describe a computational task within OpenSDN control plane applications....
Definition: task.h:82
static Task * Running()
Returns a pointer to the current task the code is executing under.
Definition: task.cc:1533
int task_code_id() const
Returns the code ID of this task.
Definition: task.h:136