Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
IQueuedWork.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#include "Templates/RefCounting.h"
7
8/** Special flags that can be associated with queued work. */
10{
11 None,
12
13 /**
14 * Tells the scheduler if this task is allowed to run during another task's
15 * busy wait. The default should be true for most case but it
16 * is sometime useful to avoid it if this task is going to wait on another one,
17 * and that other task busy waits, this could cause a cycle that could deadlock.
18 * (i.e. T1 -> busywait -> picks T2 that then waits on T1 -> deadlock
19 * In this case, we can decide that T2 should never be picked up by busy waits.
20 */
21 DoNotRunInsideBusyWait = (1 << 0),
22
23 Count
24};
25
27
28/**
29* Interface for internal data of queued work objects.
30*
31* This interface can be used to track some data between the individual function invokations of the FQueuedThreadPool
32* Usually it is used to store some internal state to support cancellation without having to look it up from a map.
33*/
35{
36public:
37 /**
38 * called during retraction, when a task is pulled from being worked on.
39 * the return value specifies if the cancellation succeded
40 */
41 virtual bool Retract() = 0;
42
43public:
44
45 /**
46 * Virtual destructor so that child implementations are guaranteed a chance
47 * to clean up any resources they allocated.
48 */
50};
51
52/**
53 * Interface for queued work objects.
54 *
55 * This interface is a type of runnable object that requires no per thread
56 * initialization. It is meant to be used with pools of threads in an
57 * abstract way that prevents the pool from needing to know any details
58 * about the object being run. This allows queuing of disparate tasks and
59 * servicing those tasks with a generic thread pool.
60 */
62{
63public:
64 /**
65 * This is where the real thread work is done. All work that is done for
66 * this queued object should be done from within the call to this function.
67 */
68 virtual void DoThreadedWork() = 0;
69
70 /**
71 * Tells the queued work that it is being abandoned so that it can do
72 * per object clean up as needed. This will only be called if it is being
73 * abandoned before completion. NOTE: This requires the object to delete
74 * itself using whatever heap it was allocated in.
75 */
76 virtual void Abandon() = 0;
77
78 /**
79 * Returns any special work flags.
80 */
82
83 /**
84 * Returns an approximation of the peak memory (in bytes) this task could require during it's execution.
85 */
86 virtual int64 GetRequiredMemory() const { return -1 /* Negative value means unknown */; }
87public:
88
89 /**
90 * Virtual destructor so that child implementations are guaranteed a chance
91 * to clean up any resources they allocated.
92 */
93 virtual ~IQueuedWork() { }
94
95 /**
96 * Internal data can be used by the pool
97 */
98 using IInternalDataType = TRefCountPtr<IQueuedWorkInternalData>;
99 IInternalDataType InternalData;
100};
#define ENUM_CLASS_FLAGS(Enum)
EQueuedWorkFlags
Definition IQueuedWork.h:10
virtual ~IQueuedWork()
Definition IQueuedWork.h:93
virtual int64 GetRequiredMemory() const
Definition IQueuedWork.h:86
virtual void DoThreadedWork()=0
virtual EQueuedWorkFlags GetQueuedWorkFlags() const
Definition IQueuedWork.h:81
virtual void Abandon()=0
IInternalDataType InternalData
Definition IQueuedWork.h:99
virtual bool Retract()=0
virtual ~IQueuedWorkInternalData()
Definition IQueuedWork.h:49