Skip to content

Commit 369e9ef

Browse files
committed
feat: add Runnable implementation
1 parent 2f70136 commit 369e9ef

File tree

3 files changed

+184
-0
lines changed

3 files changed

+184
-0
lines changed

engine/foundation/core/core_files.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ set(FILES
129129
# private/string
130130
private/string/string_hash.cpp
131131

132+
# private/threading
133+
private/threading/runnable.cpp
134+
132135
# private/time
133136
private/time/stopwatch.cpp
134137

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
////////////////////////////////////////////////////////////////////////////////////////////////////
2+
// Copyright (c) 2019 - 2023 RacoonStudios
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
5+
// software and associated documentation files (the "Software"), to deal in the Software
6+
// without restriction, including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8+
// to whom the Software is furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all copies or
11+
// substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18+
// DEALINGS IN THE SOFTWARE.
19+
////////////////////////////////////////////////////////////////////////////////////////////////////
20+
21+
22+
//[-------------------------------------------------------]
23+
//[ Includes ]
24+
//[-------------------------------------------------------]
25+
#include "core/threading/runnable.h"
26+
27+
28+
//[-------------------------------------------------------]
29+
//[ Namespace ]
30+
//[-------------------------------------------------------]
31+
namespace core {
32+
33+
34+
//[-------------------------------------------------------]
35+
//[ Forward declarations ]
36+
//[-------------------------------------------------------]
37+
38+
39+
//[-------------------------------------------------------]
40+
//[ Classes ]
41+
//[-------------------------------------------------------]
42+
bool Runnable::init() {
43+
return true;
44+
}
45+
46+
void Runnable::stop() {
47+
48+
}
49+
50+
void Runnable::exit() {
51+
52+
}
53+
54+
void Runnable::post_work(bool killed) {
55+
56+
}
57+
58+
59+
//[-------------------------------------------------------]
60+
//[ Namespace ]
61+
//[-------------------------------------------------------]
62+
} // core
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
////////////////////////////////////////////////////////////////////////////////////////////////////
2+
// Copyright (c) 2024 RacoonStudios
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
5+
// software and associated documentation files (the "Software"), to deal in the Software
6+
// without restriction, including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8+
// to whom the Software is furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all copies or
11+
// substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18+
// DEALINGS IN THE SOFTWARE.
19+
////////////////////////////////////////////////////////////////////////////////////////////////////
20+
21+
22+
//[-------------------------------------------------------]
23+
//[ Header guard ]
24+
//[-------------------------------------------------------]
25+
#pragma once
26+
27+
28+
//[-------------------------------------------------------]
29+
//[ Includes ]
30+
//[-------------------------------------------------------]
31+
#include "core/core.h"
32+
33+
34+
//[-------------------------------------------------------]
35+
//[ Namespace ]
36+
//[-------------------------------------------------------]
37+
namespace core {
38+
39+
40+
//[-------------------------------------------------------]
41+
//[ Forward declarations ]
42+
//[-------------------------------------------------------]
43+
44+
45+
//[-------------------------------------------------------]
46+
//[ Classes ]
47+
//[-------------------------------------------------------]
48+
/**
49+
* @class
50+
* Runnable
51+
*
52+
* @brief
53+
* Runnable implementation, which are used within the multi-threading pipeline.
54+
*/
55+
class Runnable {
56+
57+
//[-------------------------------------------------------]
58+
//[ Public functions ]
59+
//[-------------------------------------------------------]
60+
public:
61+
62+
/**
63+
* @brief
64+
* Constructor.
65+
*/
66+
Runnable() = default;
67+
68+
/**
69+
* @brief
70+
* Destructor.
71+
*/
72+
virtual ~Runnable() = default;
73+
74+
75+
/**
76+
* @brief
77+
* Called on initialization.
78+
*
79+
* @return
80+
*/
81+
virtual bool init();
82+
83+
/**
84+
* @brief
85+
* This method is called on stop.
86+
*/
87+
virtual void stop();
88+
89+
/**
90+
* @brief
91+
* This method is called on exit.
92+
*/
93+
virtual void exit();
94+
95+
/**
96+
* @brief
97+
* This method is called when the threads reaches the end of the runnable instance.
98+
*
99+
* @param[in] killed
100+
* True if the thread itself was killed.
101+
*/
102+
virtual void post_work(bool killed);
103+
104+
105+
/**
106+
* @brief
107+
* Runs the runnable instance.
108+
*
109+
* @return
110+
* The return code of the runnable.
111+
*/
112+
virtual int32 run() = 0;
113+
};
114+
115+
116+
//[-------------------------------------------------------]
117+
//[ Namespace ]
118+
//[-------------------------------------------------------]
119+
} // core

0 commit comments

Comments
 (0)