Skip to content

Commit 470b4c7

Browse files
Adding runtime-toggling enable/disabled option on services
1 parent fafba44 commit 470b4c7

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

include/taskr/runtime.hpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -449,19 +449,23 @@ class Runtime
449449

450450
private:
451451

452-
__INLINE__ void tryRunService(Service* service)
452+
__INLINE__ void tryRunService(Service* const service)
453453
{
454-
// Checking if service is active (or inactive -- waiting for its wait interval to pass)
455-
if (service->isActive())
454+
// Checking if service is enabled
455+
if (service->isEnabled())
456456
{
457-
// TraCR set trace of thread executing a service
458-
#ifdef ENABLE_INSTRUMENTATION
459-
INSTRUMENTATION_THREAD_MARK_SET(thread_idx.exec_serv);
460-
#endif
461-
462-
// Now run service
463-
service->run();
464-
}
457+
// Checking if service is active (or inactive, i.e., waiting for its wait interval to pass)
458+
if (service->isActive())
459+
{
460+
// TraCR set trace of thread executing a service
461+
#ifdef ENABLE_INSTRUMENTATION
462+
INSTRUMENTATION_THREAD_MARK_SET(thread_idx.exec_serv);
463+
#endif
464+
465+
// Now run service
466+
service->run();
467+
}
468+
}
465469
}
466470

467471
__INLINE__ taskr::Task *serviceWorkerLoop(const workerId_t serviceWorkerId)

include/taskr/service.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ class Service
6161
*/
6262
Service(serviceFc_t fc, const size_t interval = 0) : _fc(fc), _interval(interval) { }
6363

64+
/**
65+
* Function to enable the execution of the service at runtime
66+
*/
67+
__INLINE__ void enable() { _enabled = true; }
68+
69+
/**
70+
* Function to disable the execution of the service at runtime
71+
*/
72+
__INLINE__ void disable() { _enabled = false; }
73+
74+
/**
75+
* Function to check whether the service is enabled
76+
*
77+
* @return True, if it is enabled; false, otherwise
78+
*/
79+
__INLINE__ bool isEnabled() const { return _enabled; }
6480
/**
6581
* This function indicates whether the minimum interval has passed between the last execution.
6682
*
@@ -106,6 +122,11 @@ class Service
106122
*/
107123
size_t _interval;
108124

125+
/**
126+
* Value that indicates whether the service is enabled or disabled
127+
*/
128+
bool _enabled = true;
129+
109130
/**
110131
* Time point storing the last time this service was executed
111132
*/

0 commit comments

Comments
 (0)