-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCompilationThread.h
More file actions
52 lines (43 loc) · 1.31 KB
/
CompilationThread.h
File metadata and controls
52 lines (43 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2015 XLGAMES Inc.
//
// Distributed under the MIT License (See
// accompanying file "LICENSE" or the website
// http://www.opensource.org/licenses/mit-license.php)
#pragma once
#include "AssetsCore.h"
#include "IArtifact.h"
#include "../Utility/Threading/LockFree.h"
#include <memory>
#include <thread>
#include <functional>
namespace Utility { class ThreadPool; }
namespace Assets
{
/// <summary>Used by the compiler types to manage background operations</summary>
class CompilationThread
{
public:
void Push(
std::shared_ptr<::Assets::ArtifactFuture> future,
std::function<void(::Assets::ArtifactFuture&)> operation);
void StallOnPendingOperations(bool cancelAll);
CompilationThread();
~CompilationThread();
protected:
std::thread _thread;
XlHandle _events[2];
volatile bool _workerQuit;
struct Element
{
std::weak_ptr<::Assets::ArtifactFuture> _future;
std::function<void(::Assets::ArtifactFuture&)> _operation;
};
using Queue = LockFree::FixedSizeQueue<Element, 256>;
Queue _queue;
Queue _delayedQueue;
void ThreadFunction();
};
void QueueCompileOperation(
const std::shared_ptr<::Assets::ArtifactFuture>& future,
std::function<void(::Assets::ArtifactFuture&)>&& operation);
}