Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 713 vs 714 for /trunk/Source Code/Platform/Video/GFXState.cpp

Diff revisions: vs.
  @@ -7,82 +7,10 @@
7 7
8 8 GPUState::GPUState()
9 9 {
10 - _loaderThread = nullptr;
11 - _loadingThreadAvailable = false;
12 - // Atomic boolean use to signal the loading thread to stop
13 - _closeLoadingThread = false;
14 - _loadQueueDataReady = false;
15 10 }
16 11
17 12 GPUState::~GPUState()
18 13 {
19 - stopLoaderThread();
20 - }
21 -
22 - bool GPUState::startLoaderThread(const DELEGATE_CBK<>& loadingFunction) {
23 - DIVIDE_ASSERT(_loaderThread == nullptr,
24 - "GPUState::startLoaderThread error: double init detected!");
25 -
26 - if (Config::USE_GPU_THREADED_LOADING) {
27 - _loaderThread = MemoryManager_NEW std::thread(loadingFunction);
28 - }
29 -
30 - return true;
31 - }
32 -
33 - bool GPUState::stopLoaderThread() {
34 - if (_loaderThread != nullptr) {
35 - if (Config::USE_GPU_THREADED_LOADING) {
36 - DIVIDE_ASSERT(_loaderThread != nullptr,
37 - "GPUState::stopLoaderThread error: stop called without "
38 - "calling start first!");
39 - closeLoadingThread(true);
40 - {
41 - std::unique_lock<std::mutex> lk(_loadQueueMutex);
42 - _loadQueueDataReady = true;
43 - _loadQueueCV.notify_one();
44 - }
45 - while (loadingThreadAvailable()) {
46 - std::this_thread::sleep_for(std::chrono::milliseconds(10));
47 - }
48 - _loaderThread->join();
49 - MemoryManager::DELETE(_loaderThread);
50 - }
51 - return true;
52 - }
53 -
54 - return false;
55 - }
56 -
57 - void GPUState::addToLoadQueue(const DELEGATE_CBK<>& callback) {
58 - #ifdef _DEBUG
59 - U32 retryCount = 0;
60 - static const U32 retyLimit = 3;
61 - #endif
62 - while (!_loadQueue.push(callback)) {
63 - std::this_thread::sleep_for(std::chrono::milliseconds(10));
64 - #ifdef _DEBUG
65 - assert(++retryCount < retyLimit);
66 - #endif
67 - }
68 - std::unique_lock<std::mutex> lk(_loadQueueMutex);
69 - _loadQueueDataReady = true;
70 - _loadQueueCV.notify_one();
71 - }
72 -
73 - void GPUState::consumeOneFromQueue() {
74 - std::unique_lock<std::mutex> lk(_loadQueueMutex);
75 - _loadQueueCV.wait(lk, [this] {return _loadQueueDataReady; });
76 - // Try to pull a new element from the queue and process it
77 - while (!_closeLoadingThread && _loadQueue.consume_one(
78 - [](DELEGATE_CBK<>& cbk) {
79 - cbk();
80 - }))
81 - {
82 - }
83 - _loadQueueDataReady = false;
84 - lk.unlock();
85 - _loadQueueCV.notify_one();
86 14 }
87 15
88 16 void GPUState::registerDisplayMode(U8 displayIndex, const GPUVideoMode& mode) {