Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Runnable.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6
7/**
8 * Interface for "runnable" objects.
9 *
10 * A runnable object is an object that is "run" on an arbitrary thread. The call usage pattern is
11 * Init(), Run(), Exit(). The thread that is going to "run" this object always uses those calling
12 * semantics. It does this on the thread that is created so that any thread specific uses (TLS, etc.)
13 * are available in the contexts of those calls. A "runnable" does all initialization in Init().
14 *
15 * If initialization fails, the thread stops execution and returns an error code. If it succeeds,
16 * Run() is called where the real threaded work is done. Upon completion, Exit() is called to allow
17 * correct clean up.
18 */
20{
21public:
22
23 /**
24 * Initializes the runnable object.
25 *
26 * This method is called in the context of the thread object that aggregates this, not the
27 * thread that passes this runnable to a new thread.
28 *
29 * @return True if initialization was successful, false otherwise
30 * @see Run, Stop, Exit
31 */
32 virtual bool Init()
33 {
34 return true;
35 }
36
37 /**
38 * Runs the runnable object.
39 *
40 * This is where all per object thread work is done. This is only called if the initialization was successful.
41 *
42 * @return The exit code of the runnable object
43 * @see Init, Stop, Exit
44 */
45 virtual uint32 Run() = 0;
46
47 /**
48 * Stops the runnable object.
49 *
50 * This is called if a thread is requested to terminate early.
51 * @see Init, Run, Exit
52 */
53 virtual void Stop() { }
54
55 /**
56 * Exits the runnable object.
57 *
58 * Called in the context of the aggregating thread to perform any cleanup.
59 * @see Init, Run, Stop
60 */
61 virtual void Exit() { }
62
63 /**
64 * Gets single thread interface pointer used for ticking this runnable when multi-threading is disabled.
65 * If the interface is not implemented, this runnable will not be ticked when FPlatformProcess::SupportsMultithreading() is false.
66 *
67 * @return Pointer to the single thread interface or nullptr if not implemented.
68 */
70 {
71 return nullptr;
72 }
73
74 /** Virtual destructor */
75 virtual ~FRunnable() { }
76};
virtual uint32 Run()=0
virtual void Exit()
Definition Runnable.h:61
virtual ~FRunnable()
Definition Runnable.h:75
virtual void Stop()
Definition Runnable.h:53
virtual bool Init()
Definition Runnable.h:32
virtual class FSingleThreadRunnable * GetSingleThreadInterface()
Definition Runnable.h:69