Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef __ctrlplane__task_trigger__ 7 : #define __ctrlplane__task_trigger__ 8 : 9 : #include <atomic> 10 : 11 : #include <boost/function.hpp> 12 : 13 : class TaskTrigger { 14 : public: 15 : typedef boost::function<bool()> FunctionPtr; 16 : TaskTrigger(const FunctionPtr& func, int task_id, int task_instance); 17 : ~TaskTrigger(); 18 : void Set(); 19 : void Reset(); 20 : // For Test only 21 307 : void set_disable() { 22 307 : bool current = disabled_.exchange(true); 23 307 : assert(!current); 24 307 : } 25 306 : void set_enable() { 26 306 : bool current = disabled_.exchange(false); 27 306 : assert(current); 28 306 : Set(); 29 306 : } 30 1867670 : bool disabled() { 31 1867670 : return disabled_; 32 : } 33 : 34 : // For Test only 35 16 : void set_deferred() { 36 16 : bool current = deferred_.exchange(true); 37 16 : assert(!current); 38 16 : } 39 16 : void clear_deferred() { 40 16 : bool current = deferred_.exchange(false); 41 16 : assert(current); 42 16 : } 43 1867229 : bool deferred() const { return deferred_; } 44 2058643 : bool IsSet() const { return trigger_; } 45 : 46 : private: 47 : class WorkerTask; 48 : 49 : FunctionPtr func_; 50 : int task_id_; 51 : int task_instance_; 52 : std::atomic<bool> trigger_; 53 : std::atomic<bool> disabled_; 54 : std::atomic<bool> deferred_; 55 : }; 56 : 57 : #endif /* defined(__ctrlplane__task_trigger__) */