btftoolchain
runnable.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 #include "common.h"
6 
7 namespace btf
8 {
9 
18 class Runnable
19 {
20  public:
24  enum class States
25  {
27  terminated,
28 
30  running,
31 
33  suspended,
34 
36  unknown
37  };
38 
42  enum class Events
43  {
45  start,
46 
48  terminate,
49 
51  suspend,
52 
54  resume,
55 
57  unknown
58  };
59 
64 
71 
77  static std::string eventToString(Events ev);
78 
84  static Events stringToEvent(const std::string& str);
85 
90  bool isRunning() const;
91 
96  bool wasSuspendedByTaskPreempt() const;
97 
102  void setWasSuspendedByTaskPreempt(bool val);
103 
104  private:
106  States state_;
107 
109  bool was_suspended_by_task_preempt_{false};
110 };
111 } // namespace btf
Class for Runnable Events (see BTF Specification Chapter 2.3.3).
Definition: runnable.h:19
void setWasSuspendedByTaskPreempt(bool val)
Sets the variable "was_suspended_by_task_preempt".
Definition: runnable.cpp:135
bool wasSuspendedByTaskPreempt() const
Checks, if the current runnable is suspended due to a preemption.
Definition: runnable.cpp:130
Events
Possible types of runnable events.
Definition: runnable.h:43
@ terminate
The terminate event indicates that a runnable (target) that has been called by a process (source) has...
@ suspend
The suspend event indicates that a runnable (target) has to pause its execution as its calling proces...
@ resume
The resume event indicates that a runnable (target) can continue execution as its process (source) re...
@ unknown
Default state.
@ start
The start event indicates that a runnable (target) gets called by a process (source) and starts execu...
ErrorCodes doStateTransition(Events core_event)
Transitions the current state depending on the event.
Definition: runnable.cpp:13
bool isRunning() const
Checks, if the current runnable is in the state running.
Definition: runnable.cpp:125
Runnable(States state=States::unknown)
Constructor of the class Runnable.
Definition: runnable.cpp:9
static Events stringToEvent(const std::string &str)
Converts a string into the enum Events.
Definition: runnable.cpp:101
static std::string eventToString(Events ev)
Converts the enum Events into string.
Definition: runnable.cpp:84
States
Possible types of runnable states.
Definition: runnable.h:25
@ suspended
The runnable instance stops execution as the process instance has to be removed from core.
@ running
The runnable instance executes on a core.
@ unknown
Default state.
@ terminated
The runnable instance has finished execution or hasn’t been started yet.
Definition: btf.h:43
ErrorCodes
Error Codes for the btf library.
Definition: common.h:13