Skip to content

Commit

Permalink
Move thread.cpp to utils/
Browse files Browse the repository at this point in the history
  • Loading branch information
stuarthayhurst committed Sep 16, 2024
1 parent a1a147a commit 335cec5
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 130 deletions.
2 changes: 1 addition & 1 deletion src/ammonite/ammonite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include "utils/debug.hpp"
#include "utils/logging.hpp"
#include "utils/random.hpp"
#include "utils/thread.hpp"
#include "utils/timer.hpp"

#include "camera.hpp"
#include "enums.hpp"
#include "environment.hpp"
#include "input.hpp"
#include "interface.hpp"
#include "thread.hpp"
#include "types.hpp"
#include "window.hpp"

Expand Down
6 changes: 3 additions & 3 deletions src/ammonite/lighting/lighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "../core/threadManager.hpp"
#include "../models/modelInterface.hpp"
#include "../models/internal/modelTracker.hpp"
#include "../thread.hpp"
#include "../utils/thread.hpp"
#include "../types.hpp"

namespace ammonite {
Expand Down Expand Up @@ -182,7 +182,7 @@ namespace ammonite {
workerData = new LightWorkerData[lightCount];
} else {
for (unsigned int i = 0; i < lightCount; i++) {
ammonite::thread::resetCompletionUnsafe(syncs + i);
ammonite::utils::thread::resetCompletionUnsafe(syncs + i);
}
}

Expand All @@ -196,7 +196,7 @@ namespace ammonite {
&syncs[0], lightCount);

for (unsigned int i = 0; i < lightCount; i++) {
ammonite::thread::waitWorkCompleteUnsafe(syncs + i);
ammonite::utils::thread::waitWorkCompleteUnsafe(syncs + i);
}

//If the light count hasn't changed, sub the data instead of recreating the buffer
Expand Down
72 changes: 0 additions & 72 deletions src/ammonite/thread.cpp

This file was deleted.

26 changes: 0 additions & 26 deletions src/ammonite/thread.hpp

This file was deleted.

74 changes: 74 additions & 0 deletions src/ammonite/utils/thread.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "../types.hpp"
#include "../core/threadManager.hpp"

namespace ammonite {
namespace utils {
namespace thread {
unsigned int getThreadPoolSize() {
return ammonite::thread::internal::getThreadPoolSize();
}

void submitWork(AmmoniteWork work, void* userPtr) {
ammonite::thread::internal::submitWork(work, userPtr, nullptr);
}

void submitWork(AmmoniteWork work, void* userPtr, AmmoniteCompletion* completion) {
ammonite::thread::internal::submitWork(work, userPtr, completion);
}

//userBuffer and completions may be null
void submitMultiple(AmmoniteWork work, void* userBuffer, int stride,
AmmoniteCompletion* completions, unsigned int jobCount) {
ammonite::thread::internal::submitMultiple(work, userBuffer, stride, completions, jobCount);
}

//Wait for completion to be finished
void waitWorkComplete(AmmoniteCompletion* completion) {
//Wait for completion to become true
if (completion != nullptr) {
completion->wait(false);
}
}

//Wait for completion to be finished, without a nullptr check
void waitWorkCompleteUnsafe(AmmoniteCompletion* completion) {
//Wait for completion to become true
completion->wait(false);
}

//Reset completion to be used again
void resetCompletion(AmmoniteCompletion* completion) {
//Reset the completion to false
if (completion != nullptr) {
completion->clear();
}
}

//Reset completion to be used again, without a nullptr check
void resetCompletionUnsafe(AmmoniteCompletion* completion) {
//Reset the completion to false
completion->clear();
}

void blockThreadsAsync() {
ammonite::thread::internal::blockThreads(false);
}

void blockThreadsSync() {
ammonite::thread::internal::blockThreads(true);
}

void unblockThreadsAsync() {
ammonite::thread::internal::unblockThreads(false);
}

void unblockThreadsSync() {
ammonite::thread::internal::unblockThreads(true);
}

void finishWork() {
ammonite::thread::internal::finishWork();
}
}
}
}
28 changes: 28 additions & 0 deletions src/ammonite/utils/thread.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef THREAD
#define THREAD

#include "../types.hpp"

namespace ammonite {
namespace utils {
namespace thread {
unsigned int getThreadPoolSize();
void submitWork(AmmoniteWork work, void* userPtr);
void submitWork(AmmoniteWork work, void* userPtr, AmmoniteCompletion* completion);
void submitMultiple(AmmoniteWork work, void* userBuffer, int stride,
AmmoniteCompletion* completions, unsigned int jobCount);
void waitWorkComplete(AmmoniteCompletion* completion);
void waitWorkCompleteUnsafe(AmmoniteCompletion* completion);
void resetCompletion(AmmoniteCompletion* completion);
void resetCompletionUnsafe(AmmoniteCompletion* completion);

void blockThreadsAsync();
void blockThreadsSync();
void unblockThreadsSync();
void unblockThreadsAsync();
void finishWork();
}
}
}

#endif
Loading

0 comments on commit 335cec5

Please sign in to comment.