浏览代码

JobSystemThreadPool, a couple more helpers

Lucien Greathouse 1 年之前
父节点
当前提交
78302e4998
共有 3 个文件被更改,包括 50 次插入7 次删除
  1. 3 0
      HelloWorld/main.cpp
  2. 16 1
      JoltC/Functions.h
  3. 31 6
      JoltC/JoltC.cpp

+ 3 - 0
HelloWorld/main.cpp

@@ -9,6 +9,9 @@ int main() {
 
 	JPC_TempAllocatorImpl* temp_allocator = JPC_TempAllocatorImpl_new(10 * 1024 * 1024);
 
+	JPC_JobSystemThreadPool* job_system = JPC_JobSystemThreadPool_new2(JPC_MAX_PHYSICS_JOBS, JPC_MAX_PHYSICS_BARRIERS);
+
+	JPC_JobSystemThreadPool_delete(job_system);
 	JPC_TempAllocatorImpl_delete(temp_allocator);
 
 	printf("Hello, world!\n");

+ 16 - 1
JoltC/Functions.h

@@ -2,6 +2,9 @@
 
 #define JPC_API extern __declspec(dllexport)
 
+// C-compatible typedefs that match Jolt's internal primitive typedefs.
+#define uint unsigned int
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -12,9 +15,21 @@ JPC_API void JPC_RegisterTypes();
 
 typedef struct JPC_TempAllocatorImpl JPC_TempAllocatorImpl;
 
-JPC_API JPC_TempAllocatorImpl* JPC_TempAllocatorImpl_new(unsigned int size);
+JPC_API JPC_TempAllocatorImpl* JPC_TempAllocatorImpl_new(uint size);
 JPC_API void JPC_TempAllocatorImpl_delete(JPC_TempAllocatorImpl* object);
 
+typedef struct JPC_JobSystemThreadPool JPC_JobSystemThreadPool;
+
+JPC_API JPC_JobSystemThreadPool* JPC_JobSystemThreadPool_new2(
+	uint inMaxJobs,
+	uint inMaxBarriers);
+JPC_API JPC_JobSystemThreadPool* JPC_JobSystemThreadPool_new3(
+	uint inMaxJobs,
+	uint inMaxBarriers,
+	int inNumThreads);
+
+JPC_API void JPC_JobSystemThreadPool_delete(JPC_JobSystemThreadPool* object);
+
 #ifdef __cplusplus
 }
 #endif

+ 31 - 6
JoltC/JoltC.cpp

@@ -1,15 +1,19 @@
-#include "JoltC/JoltC.h"
-
 #include "Jolt/Jolt.h"
 
+#include "Jolt/Core/Core.h"
 #include "Jolt/Core/Factory.h"
+#include "Jolt/Core/JobSystemThreadPool.h"
 #include "Jolt/Core/Memory.h"
 #include "Jolt/Core/TempAllocator.h"
 #include "Jolt/RegisterTypes.h"
-#include "Jolt/Core/Core.h"
 
-static auto to_jpc(JPH::TempAllocatorImpl *in) { return reinterpret_cast<JPC_TempAllocatorImpl*>(in); }
-static auto to_jph(JPC_TempAllocatorImpl *in) { return reinterpret_cast<JPH::TempAllocatorImpl*>(in); }
+#include "JoltC/JoltC.h"
+
+#define OPAQUE_WRAPPER(c_type, cpp_type) \
+	static auto to_jpc(cpp_type *in) { return reinterpret_cast<c_type*>(in); } \
+	static auto to_jph(c_type *in) { return reinterpret_cast<cpp_type*>(in); }
+
+OPAQUE_WRAPPER(JPC_TempAllocatorImpl, JPH::TempAllocatorImpl)
 
 JPC_API void JPC_RegisterDefaultAllocator() {
 	JPH::RegisterDefaultAllocator();
@@ -23,10 +27,31 @@ JPC_API void JPC_RegisterTypes() {
 	JPH::RegisterTypes();
 }
 
-JPC_API JPC_TempAllocatorImpl* JPC_TempAllocatorImpl_new(unsigned int size) {
+JPC_API JPC_TempAllocatorImpl* JPC_TempAllocatorImpl_new(uint size) {
 	return to_jpc(new JPH::TempAllocatorImpl(size));
 }
 
 JPC_API void JPC_TempAllocatorImpl_delete(JPC_TempAllocatorImpl* object) {
 	delete to_jph(object);
+}
+
+OPAQUE_WRAPPER(JPC_JobSystemThreadPool, JPH::JobSystemThreadPool)
+
+JPC_API JPC_JobSystemThreadPool* JPC_JobSystemThreadPool_new2(
+	uint inMaxJobs,
+	uint inMaxBarriers)
+{
+	return to_jpc(new JPH::JobSystemThreadPool(inMaxJobs, inMaxBarriers));
+}
+
+JPC_API JPC_JobSystemThreadPool* JPC_JobSystemThreadPool_new3(
+	uint inMaxJobs,
+	uint inMaxBarriers,
+	int inNumThreads)
+{
+	return to_jpc(new JPH::JobSystemThreadPool(inMaxJobs, inMaxBarriers, inNumThreads));
+}
+
+JPC_API void JPC_JobSystemThreadPool_delete(JPC_JobSystemThreadPool* object) {
+	delete to_jph(object);
 }