summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-11-21 14:31:14 -0300
committerGitHub <noreply@github.com>2017-11-21 14:31:14 -0300
commit640856f4d4f4e4d10e9f793caf6ac6f4d22678e6 (patch)
tree961c1f670833437b9e31a45122fc2b5793a9bbab /core
parent30dadb12281924ccb59efc8df4b3b9ee68c6e3a4 (diff)
parentf9a38d2309043de9e0c763ae72aa81b25c1dfca7 (diff)
Merge pull request #11895 from m4nu3lf/rendering/separate_thread
Restore rendering on a separate thread
Diffstat (limited to 'core')
-rw-r--r--core/command_queue_mt.cpp24
-rw-r--r--core/command_queue_mt.h1509
2 files changed, 325 insertions, 1208 deletions
diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp
index 8e2aa24c22..2028a18a06 100644
--- a/core/command_queue_mt.cpp
+++ b/core/command_queue_mt.cpp
@@ -76,6 +76,30 @@ CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() {
return &sync_sems[idx];
}
+bool CommandQueueMT::dealloc_one() {
+tryagain:
+ if (dealloc_ptr == write_ptr) {
+ // The queue is empty
+ return false;
+ }
+
+ uint32_t size = *(uint32_t *)&command_mem[dealloc_ptr];
+
+ if (size == 0) {
+ // End of command buffer wrap down
+ dealloc_ptr = 0;
+ goto tryagain;
+ }
+
+ if (size & 1) {
+ // Still used, nothing can be deallocated
+ return false;
+ }
+
+ dealloc_ptr += (size >> 1) + sizeof(uint32_t);
+ return true;
+}
+
CommandQueueMT::CommandQueueMT(bool p_sync) {
read_ptr = 0;
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h
index e37d593f9f..697fec3fc4 100644
--- a/core/command_queue_mt.h
+++ b/core/command_queue_mt.h
@@ -39,6 +39,230 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
+#define COMMA(N) _COMMA_##N
+#define _COMMA_0
+#define _COMMA_1 ,
+#define _COMMA_2 ,
+#define _COMMA_3 ,
+#define _COMMA_4 ,
+#define _COMMA_5 ,
+#define _COMMA_6 ,
+#define _COMMA_7 ,
+#define _COMMA_8 ,
+#define _COMMA_9 ,
+#define _COMMA_10 ,
+#define _COMMA_11 ,
+#define _COMMA_12 ,
+
+// 1-based comma separed list of ITEMs
+#define COMMA_SEP_LIST(ITEM, LENGTH) _COMMA_SEP_LIST_##LENGTH(ITEM)
+#define _COMMA_SEP_LIST_12(ITEM) \
+ _COMMA_SEP_LIST_11(ITEM) \
+ , ITEM(12)
+#define _COMMA_SEP_LIST_11(ITEM) \
+ _COMMA_SEP_LIST_10(ITEM) \
+ , ITEM(11)
+#define _COMMA_SEP_LIST_10(ITEM) \
+ _COMMA_SEP_LIST_9(ITEM) \
+ , ITEM(10)
+#define _COMMA_SEP_LIST_9(ITEM) \
+ _COMMA_SEP_LIST_8(ITEM) \
+ , ITEM(9)
+#define _COMMA_SEP_LIST_8(ITEM) \
+ _COMMA_SEP_LIST_7(ITEM) \
+ , ITEM(8)
+#define _COMMA_SEP_LIST_7(ITEM) \
+ _COMMA_SEP_LIST_6(ITEM) \
+ , ITEM(7)
+#define _COMMA_SEP_LIST_6(ITEM) \
+ _COMMA_SEP_LIST_5(ITEM) \
+ , ITEM(6)
+#define _COMMA_SEP_LIST_5(ITEM) \
+ _COMMA_SEP_LIST_4(ITEM) \
+ , ITEM(5)
+#define _COMMA_SEP_LIST_4(ITEM) \
+ _COMMA_SEP_LIST_3(ITEM) \
+ , ITEM(4)
+#define _COMMA_SEP_LIST_3(ITEM) \
+ _COMMA_SEP_LIST_2(ITEM) \
+ , ITEM(3)
+#define _COMMA_SEP_LIST_2(ITEM) \
+ _COMMA_SEP_LIST_1(ITEM) \
+ , ITEM(2)
+#define _COMMA_SEP_LIST_1(ITEM) \
+ _COMMA_SEP_LIST_0(ITEM) \
+ ITEM(1)
+#define _COMMA_SEP_LIST_0(ITEM)
+
+// 1-based semicolon separed list of ITEMs
+#define SEMIC_SEP_LIST(ITEM, LENGTH) _SEMIC_SEP_LIST_##LENGTH(ITEM)
+#define _SEMIC_SEP_LIST_12(ITEM) \
+ _SEMIC_SEP_LIST_11(ITEM); \
+ ITEM(12)
+#define _SEMIC_SEP_LIST_11(ITEM) \
+ _SEMIC_SEP_LIST_10(ITEM); \
+ ITEM(11)
+#define _SEMIC_SEP_LIST_10(ITEM) \
+ _SEMIC_SEP_LIST_9(ITEM); \
+ ITEM(10)
+#define _SEMIC_SEP_LIST_9(ITEM) \
+ _SEMIC_SEP_LIST_8(ITEM); \
+ ITEM(9)
+#define _SEMIC_SEP_LIST_8(ITEM) \
+ _SEMIC_SEP_LIST_7(ITEM); \
+ ITEM(8)
+#define _SEMIC_SEP_LIST_7(ITEM) \
+ _SEMIC_SEP_LIST_6(ITEM); \
+ ITEM(7)
+#define _SEMIC_SEP_LIST_6(ITEM) \
+ _SEMIC_SEP_LIST_5(ITEM); \
+ ITEM(6)
+#define _SEMIC_SEP_LIST_5(ITEM) \
+ _SEMIC_SEP_LIST_4(ITEM); \
+ ITEM(5)
+#define _SEMIC_SEP_LIST_4(ITEM) \
+ _SEMIC_SEP_LIST_3(ITEM); \
+ ITEM(4)
+#define _SEMIC_SEP_LIST_3(ITEM) \
+ _SEMIC_SEP_LIST_2(ITEM); \
+ ITEM(3)
+#define _SEMIC_SEP_LIST_2(ITEM) \
+ _SEMIC_SEP_LIST_1(ITEM); \
+ ITEM(2)
+#define _SEMIC_SEP_LIST_1(ITEM) \
+ _SEMIC_SEP_LIST_0(ITEM) \
+ ITEM(1)
+#define _SEMIC_SEP_LIST_0(ITEM)
+
+// 1-based space separed list of ITEMs
+#define SPACE_SEP_LIST(ITEM, LENGTH) _SPACE_SEP_LIST_##LENGTH(ITEM)
+#define _SPACE_SEP_LIST_12(ITEM) \
+ _SPACE_SEP_LIST_11(ITEM) \
+ ITEM(12)
+#define _SPACE_SEP_LIST_11(ITEM) \
+ _SPACE_SEP_LIST_10(ITEM) \
+ ITEM(11)
+#define _SPACE_SEP_LIST_10(ITEM) \
+ _SPACE_SEP_LIST_9(ITEM) \
+ ITEM(10)
+#define _SPACE_SEP_LIST_9(ITEM) \
+ _SPACE_SEP_LIST_8(ITEM) \
+ ITEM(9)
+#define _SPACE_SEP_LIST_8(ITEM) \
+ _SPACE_SEP_LIST_7(ITEM) \
+ ITEM(8)
+#define _SPACE_SEP_LIST_7(ITEM) \
+ _SPACE_SEP_LIST_6(ITEM) \
+ ITEM(7)
+#define _SPACE_SEP_LIST_6(ITEM) \
+ _SPACE_SEP_LIST_5(ITEM) \
+ ITEM(6)
+#define _SPACE_SEP_LIST_5(ITEM) \
+ _SPACE_SEP_LIST_4(ITEM) \
+ ITEM(5)
+#define _SPACE_SEP_LIST_4(ITEM) \
+ _SPACE_SEP_LIST_3(ITEM) \
+ ITEM(4)
+#define _SPACE_SEP_LIST_3(ITEM) \
+ _SPACE_SEP_LIST_2(ITEM) \
+ ITEM(3)
+#define _SPACE_SEP_LIST_2(ITEM) \
+ _SPACE_SEP_LIST_1(ITEM) \
+ ITEM(2)
+#define _SPACE_SEP_LIST_1(ITEM) \
+ _SPACE_SEP_LIST_0(ITEM) \
+ ITEM(1)
+#define _SPACE_SEP_LIST_0(ITEM)
+
+#define ARG(N) p##N
+#define PARAM(N) P##N p##N
+#define TYPE_PARAM(N) class P##N
+#define PARAM_DECL(N) typename GetSimpleTypeT<P##N>::type_t p##N
+
+#define DECL_CMD(N) \
+ template <class T, class M COMMA(N) COMMA_SEP_LIST(TYPE_PARAM, N)> \
+ struct Command##N : public CommandBase { \
+ T *instance; \
+ M method; \
+ SEMIC_SEP_LIST(PARAM_DECL, N); \
+ virtual void call() { \
+ (instance->*method)(COMMA_SEP_LIST(ARG, N)); \
+ } \
+ };
+
+#define DECL_CMD_RET(N) \
+ template <class T, class M, COMMA_SEP_LIST(TYPE_PARAM, N) COMMA(N) class R> \
+ struct CommandRet##N : public SyncCommand { \
+ R *ret; \
+ T *instance; \
+ M method; \
+ SEMIC_SEP_LIST(PARAM_DECL, N); \
+ virtual void call() { \
+ *ret = (instance->*method)(COMMA_SEP_LIST(ARG, N)); \
+ } \
+ };
+
+#define DECL_CMD_SYNC(N) \
+ template <class T, class M COMMA(N) COMMA_SEP_LIST(TYPE_PARAM, N)> \
+ struct CommandSync##N : public SyncCommand { \
+ T *instance; \
+ M method; \
+ SEMIC_SEP_LIST(PARAM_DECL, N); \
+ virtual void call() { \
+ (instance->*method)(COMMA_SEP_LIST(ARG, N)); \
+ } \
+ };
+
+#define TYPE_ARG(N) P##N
+#define CMD_TYPE(N) Command##N<T, M COMMA(N) COMMA_SEP_LIST(TYPE_ARG, N)>
+#define CMD_ASSIGN_PARAM(N) cmd->p##N = p##N
+
+#define DECL_PUSH(N) \
+ template <class T, class M COMMA(N) COMMA_SEP_LIST(TYPE_PARAM, N)> \
+ void push(T *p_instance, M p_method COMMA(N) COMMA_SEP_LIST(PARAM, N)) { \
+ CMD_TYPE(N) *cmd = allocate_and_lock<CMD_TYPE(N)>(); \
+ cmd->instance = p_instance; \
+ cmd->method = p_method; \
+ SEMIC_SEP_LIST(CMD_ASSIGN_PARAM, N); \
+ unlock(); \
+ if (sync) sync->post(); \
+ }
+
+#define CMD_RET_TYPE(N) CommandRet##N<T, M, COMMA_SEP_LIST(TYPE_ARG, N) COMMA(N) R>
+
+#define DECL_PUSH_AND_RET(N) \
+ template <class T, class M, COMMA_SEP_LIST(TYPE_PARAM, N) COMMA(N) class R> \
+ void push_and_ret(T *p_instance, M p_method, COMMA_SEP_LIST(PARAM, N) COMMA(N) R *r_ret) { \
+ SyncSemaphore *ss = _alloc_sync_sem(); \
+ CMD_RET_TYPE(N) *cmd = allocate_and_lock<CMD_RET_TYPE(N)>(); \
+ cmd->instance = p_instance; \
+ cmd->method = p_method; \
+ SEMIC_SEP_LIST(CMD_ASSIGN_PARAM, N); \
+ cmd->ret = r_ret; \
+ cmd->sync_sem = ss; \
+ unlock(); \
+ if (sync) sync->post(); \
+ ss->sem->wait(); \
+ }
+
+#define CMD_SYNC_TYPE(N) CommandSync##N<T, M COMMA(N) COMMA_SEP_LIST(TYPE_ARG, N)>
+
+#define DECL_PUSH_AND_SYNC(N) \
+ template <class T, class M COMMA(N) COMMA_SEP_LIST(TYPE_PARAM, N)> \
+ void push_and_sync(T *p_instance, M p_method COMMA(N) COMMA_SEP_LIST(PARAM, N)) { \
+ SyncSemaphore *ss = _alloc_sync_sem(); \
+ CMD_SYNC_TYPE(N) *cmd = allocate_and_lock<CMD_SYNC_TYPE(N)>(); \
+ cmd->instance = p_instance; \
+ cmd->method = p_method; \
+ SEMIC_SEP_LIST(CMD_ASSIGN_PARAM, N); \
+ cmd->sync_sem = ss; \
+ unlock(); \
+ if (sync) sync->post(); \
+ ss->sem->wait(); \
+ }
+
+#define MAX_CMD_PARAMS 12
+
class CommandQueueMT {
struct SyncSemaphore {
@@ -50,556 +274,35 @@ class CommandQueueMT {
struct CommandBase {
virtual void call() = 0;
+ virtual void post(){};
virtual ~CommandBase(){};
};
- template <class T, class M>
- struct Command0 : public CommandBase {
-
- T *instance;
- M method;
-
- virtual void call() { (instance->*method)(); }
- };
-
- template <class T, class M, class P1>
- struct Command1 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
-
- virtual void call() { (instance->*method)(p1); }
- };
-
- template <class T, class M, class P1, class P2>
- struct Command2 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
-
- virtual void call() { (instance->*method)(p1, p2); }
- };
-
- template <class T, class M, class P1, class P2, class P3>
- struct Command3 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
-
- virtual void call() { (instance->*method)(p1, p2, p3); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4>
- struct Command4 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5>
- struct Command5 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6>
- struct Command6 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
- struct Command7 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
- struct Command8 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9>
- struct Command9 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
- typename GetSimpleTypeT<P9>::type_t p9;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10>
- struct Command10 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
- typename GetSimpleTypeT<P9>::type_t p9;
- typename GetSimpleTypeT<P10>::type_t p10;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10, class P11>
- struct Command11 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
- typename GetSimpleTypeT<P9>::type_t p9;
- typename GetSimpleTypeT<P10>::type_t p10;
- typename GetSimpleTypeT<P11>::type_t p11;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10, class P11, class P12>
- struct Command12 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
- typename GetSimpleTypeT<P9>::type_t p9;
- typename GetSimpleTypeT<P10>::type_t p10;
- typename GetSimpleTypeT<P11>::type_t p11;
- typename GetSimpleTypeT<P12>::type_t p12;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); }
- };
-
- /* comands that return */
-
- template <class T, class M, class R>
- struct CommandRet0 : public CommandBase {
-
- T *instance;
- M method;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)();
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class R>
- struct CommandRet1 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class R>
- struct CommandRet2 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class R>
- struct CommandRet3 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2, p3);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class R>
- struct CommandRet4 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2, p3, p4);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class R>
- struct CommandRet5 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2, p3, p4, p5);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class R>
- struct CommandRet6 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2, p3, p4, p5, p6);
- sync->sem->post();
- sync->in_use = false;
- }
- };
+ struct SyncCommand : public CommandBase {
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class R>
- struct CommandRet7 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2, p3, p4, p5, p6, p7);
- sync->sem->post();
- sync->in_use = false;
- }
- };
+ SyncSemaphore *sync_sem;
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class R>
- struct CommandRet8 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8);
- sync->sem->post();
- sync->in_use = false;
+ virtual void post() {
+ sync_sem->sem->post();
+ sync_sem->in_use = false;
}
};
- /** commands that don't return but sync */
+ DECL_CMD(0)
+ SPACE_SEP_LIST(DECL_CMD, 12)
/* comands that return */
+ DECL_CMD_RET(0)
+ SPACE_SEP_LIST(DECL_CMD_RET, 12)
- template <class T, class M>
- struct CommandSync0 : public CommandBase {
-
- T *instance;
- M method;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)();
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1>
- struct CommandSync1 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2>
- struct CommandSync2 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3>
- struct CommandSync3 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2, p3);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4>
- struct CommandSync4 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2, p3, p4);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5>
- struct CommandSync5 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2, p3, p4, p5);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6>
- struct CommandSync6 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2, p3, p4, p5, p6);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
- struct CommandSync7 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2, p3, p4, p5, p6, p7);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
- struct CommandSync8 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8);
- sync->sem->post();
- sync->in_use = false;
- }
- };
+ /* commands that don't return but sync */
+ DECL_CMD_SYNC(0)
+ SPACE_SEP_LIST(DECL_CMD_SYNC, 12)
/***** BASE *******/
enum {
- COMMAND_MEM_SIZE_KB = 256,
+ COMMAND_MEM_SIZE_KB = 256 * 1024,
COMMAND_MEM_SIZE = COMMAND_MEM_SIZE_KB * 1024,
SYNC_SEMAPHORES = 8
};
@@ -607,6 +310,7 @@ class CommandQueueMT {
uint8_t command_mem[COMMAND_MEM_SIZE];
uint32_t read_ptr;
uint32_t write_ptr;
+ uint32_t dealloc_ptr;
SyncSemaphore sync_sems[SYNC_SEMAPHORES];
Mutex *mutex;
Semaphore *sync;
@@ -619,18 +323,30 @@ class CommandQueueMT {
tryagain:
- if (write_ptr < read_ptr) {
- // behind read_ptr, check that there is room
- if ((read_ptr - write_ptr) <= alloc_size)
+ if (write_ptr < dealloc_ptr) {
+ // behind dealloc_ptr, check that there is room
+ if ((dealloc_ptr - write_ptr) <= alloc_size) {
+
+ // There is no more room, try to deallocate something
+ if (dealloc_one()) {
+ goto tryagain;
+ }
return NULL;
- } else if (write_ptr >= read_ptr) {
- // ahead of read_ptr, check that there is room
+ }
+ } else if (write_ptr >= dealloc_ptr) {
+ // ahead of dealloc_ptr, check that there is room
- if ((COMMAND_MEM_SIZE - write_ptr) < alloc_size + 4) {
+ if ((COMMAND_MEM_SIZE - write_ptr) < alloc_size + sizeof(uint32_t)) {
// no room at the end, wrap down;
- if (read_ptr == 0) // don't want write_ptr to become read_ptr
+ if (dealloc_ptr == 0) { // don't want write_ptr to become dealloc_ptr
+
+ // There is no more room, try to deallocate something
+ if (dealloc_one()) {
+ goto tryagain;
+ }
return NULL;
+ }
// if this happens, it's a bug
ERR_FAIL_COND_V((COMMAND_MEM_SIZE - write_ptr) < sizeof(uint32_t), NULL);
@@ -642,9 +358,11 @@ class CommandQueueMT {
goto tryagain;
}
}
- // allocate the size
+ // Allocate the size and the 'in use' bit.
+ // First bit used to mark if command is still in use (1)
+ // or if it has been destroyed and can be deallocated (0).
uint32_t *p = (uint32_t *)&command_mem[write_ptr];
- *p = sizeof(T);
+ *p = (sizeof(T) << 1) | 1;
write_ptr += sizeof(uint32_t);
// allocate the command
T *cmd = memnew_placement(&command_mem[write_ptr], T);
@@ -669,15 +387,16 @@ class CommandQueueMT {
return ret;
}
- bool flush_one() {
-
+ bool flush_one(bool p_lock = true) {
+ if (p_lock) lock();
tryagain:
// tried to read an empty queue
if (read_ptr == write_ptr)
return false;
- uint32_t size = *(uint32_t *)(&command_mem[read_ptr]);
+ uint32_t size_ptr = read_ptr;
+ uint32_t size = *(uint32_t *)&command_mem[read_ptr] >> 1;
if (size == 0) {
//end of ringbuffer, wrap
@@ -689,11 +408,17 @@ class CommandQueueMT {
CommandBase *cmd = reinterpret_cast<CommandBase *>(&command_mem[read_ptr]);
+ read_ptr += size;
+
+ if (p_lock) unlock();
cmd->call();
- cmd->~CommandBase();
+ if (p_lock) lock();
- read_ptr += size;
+ cmd->post();
+ cmd->~CommandBase();
+ *(uint32_t *)&command_mem[size_ptr] &= ~1;
+ if (p_lock) unlock();
return true;
}
@@ -701,681 +426,33 @@ class CommandQueueMT {
void unlock();
void wait_for_flush();
SyncSemaphore *_alloc_sync_sem();
+ bool dealloc_one();
public:
/* NORMAL PUSH COMMANDS */
+ DECL_PUSH(0)
+ SPACE_SEP_LIST(DECL_PUSH, 12)
- template <class T, class M>
- void push(T *p_instance, M p_method) {
-
- Command0<T, M> *cmd = allocate_and_lock<Command0<T, M> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1>
- void push(T *p_instance, M p_method, P1 p1) {
-
- Command1<T, M, P1> *cmd = allocate_and_lock<Command1<T, M, P1> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2>
- void push(T *p_instance, M p_method, P1 p1, P2 p2) {
-
- Command2<T, M, P1, P2> *cmd = allocate_and_lock<Command2<T, M, P1, P2> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3) {
-
- Command3<T, M, P1, P2, P3> *cmd = allocate_and_lock<Command3<T, M, P1, P2, P3> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4) {
-
- Command4<T, M, P1, P2, P3, P4> *cmd = allocate_and_lock<Command4<T, M, P1, P2, P3, P4> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {
-
- Command5<T, M, P1, P2, P3, P4, P5> *cmd = allocate_and_lock<Command5<T, M, P1, P2, P3, P4, P5> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) {
-
- Command6<T, M, P1, P2, P3, P4, P5, P6> *cmd = allocate_and_lock<Command6<T, M, P1, P2, P3, P4, P5, P6> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) {
-
- Command7<T, M, P1, P2, P3, P4, P5, P6, P7> *cmd = allocate_and_lock<Command7<T, M, P1, P2, P3, P4, P5, P6, P7> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) {
-
- Command8<T, M, P1, P2, P3, P4, P5, P6, P7, P8> *cmd = allocate_and_lock<Command8<T, M, P1, P2, P3, P4, P5, P6, P7, P8> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
-
- unlock();
-
- if (sync) sync->post();
- }
+ /* PUSH AND RET COMMANDS */
+ DECL_PUSH_AND_RET(0)
+ SPACE_SEP_LIST(DECL_PUSH_AND_RET, 12)
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) {
-
- Command9<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9> *cmd = allocate_and_lock<Command9<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
- cmd->p9 = p9;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10) {
-
- Command10<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> *cmd = allocate_and_lock<Command10<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
- cmd->p9 = p9;
- cmd->p10 = p10;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10, class P11>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, P11 p11) {
-
- Command11<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11> *cmd = allocate_and_lock<Command11<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
- cmd->p9 = p9;
- cmd->p10 = p10;
- cmd->p11 = p11;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10, class P11, class P12>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, P11 p11, P12 p12) {
-
- Command12<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12> *cmd = allocate_and_lock<Command12<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
- cmd->p9 = p9;
- cmd->p10 = p10;
- cmd->p11 = p11;
- cmd->p12 = p12;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- /*** PUSH AND RET COMMANDS ***/
-
- template <class T, class M, class R>
- void push_and_ret(T *p_instance, M p_method, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet0<T, M, R> *cmd = allocate_and_lock<CommandRet0<T, M, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet1<T, M, P1, R> *cmd = allocate_and_lock<CommandRet1<T, M, P1, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet2<T, M, P1, P2, R> *cmd = allocate_and_lock<CommandRet2<T, M, P1, P2, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet3<T, M, P1, P2, P3, R> *cmd = allocate_and_lock<CommandRet3<T, M, P1, P2, P3, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet4<T, M, P1, P2, P3, P4, R> *cmd = allocate_and_lock<CommandRet4<T, M, P1, P2, P3, P4, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet5<T, M, P1, P2, P3, P4, P5, R> *cmd = allocate_and_lock<CommandRet5<T, M, P1, P2, P3, P4, P5, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet6<T, M, P1, P2, P3, P4, P5, P6, R> *cmd = allocate_and_lock<CommandRet6<T, M, P1, P2, P3, P4, P5, P6, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet7<T, M, P1, P2, P3, P4, P5, P6, P7, R> *cmd = allocate_and_lock<CommandRet7<T, M, P1, P2, P3, P4, P5, P6, P7, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet8<T, M, P1, P2, P3, P4, P5, P6, P7, P8, R> *cmd = allocate_and_lock<CommandRet8<T, M, P1, P2, P3, P4, P5, P6, P7, P8, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M>
- void push_and_sync(T *p_instance, M p_method) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync0<T, M> *cmd = allocate_and_lock<CommandSync0<T, M> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1>
- void push_and_sync(T *p_instance, M p_method, P1 p1) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync1<T, M, P1> *cmd = allocate_and_lock<CommandSync1<T, M, P1> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync2<T, M, P1, P2> *cmd = allocate_and_lock<CommandSync2<T, M, P1, P2> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync3<T, M, P1, P2, P3> *cmd = allocate_and_lock<CommandSync3<T, M, P1, P2, P3> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync4<T, M, P1, P2, P3, P4> *cmd = allocate_and_lock<CommandSync4<T, M, P1, P2, P3, P4> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync5<T, M, P1, P2, P3, P4, P5> *cmd = allocate_and_lock<CommandSync5<T, M, P1, P2, P3, P4, P5> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync6<T, M, P1, P2, P3, P4, P5, P6> *cmd = allocate_and_lock<CommandSync6<T, M, P1, P2, P3, P4, P5, P6> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync7<T, M, P1, P2, P3, P4, P5, P6, P7> *cmd = allocate_and_lock<CommandSync7<T, M, P1, P2, P3, P4, P5, P6, P7> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync8<T, M, P1, P2, P3, P4, P5, P6, P7, P8> *cmd = allocate_and_lock<CommandSync8<T, M, P1, P2, P3, P4, P5, P6, P7, P8> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
+ /* PUSH AND RET SYNC COMMANDS*/
+ DECL_PUSH_AND_SYNC(0)
+ SPACE_SEP_LIST(DECL_PUSH_AND_SYNC, 12)
void wait_and_flush_one() {
ERR_FAIL_COND(!sync);
sync->wait();
- lock();
flush_one();
- unlock();
}
void flush_all() {
//ERR_FAIL_COND(sync);
lock();
- while (true) {
- bool exit = !flush_one();
- if (exit)
- break;
- }
+ while (flush_one(false))
+ ;
unlock();
}
@@ -1383,4 +460,20 @@ public:
~CommandQueueMT();
};
+#undef ARG
+#undef PARAM
+#undef TYPE_PARAM
+#undef PARAM_DECL
+#undef DECL_CMD
+#undef DECL_CMD_RET
+#undef DECL_CMD_SYNC
+#undef TYPE_ARG
+#undef CMD_TYPE
+#undef CMD_ASSIGN_PARAM
+#undef DECL_PUSH
+#undef CMD_RET_TYPE
+#undef DECL_PUSH_AND_RET
+#undef CMD_SYNC_TYPE
+#undef DECL_CMD_SYNC
+
#endif