📄 sc_fork.h
字号:
delete i; }};#ifndef SC_FORK_NO_TEMP_SPCL// Template specialization for "void" return type.template <class a1T, class a2T, class a3T, class a4T>class sc_4_arg_function <void, a1T, a2T, a3T, a4T>{public: typedef void returnT; typedef returnT (*functionT)(a1T, a2T, a3T, a4T); static sc_join_handle spawn(returnT* ret, functionT func, a1T a1, a2T a2, a3T a3, a4T a4, const sc_spawn_options * options=0) { info* i = new info(ret, func, a1, a2, a3, a4); return sc_spawn_low_level(exec, i, options); }private: struct info { returnT* _ret; functionT _func; a1T _a1; a2T _a2; a3T _a3; a4T _a4; info(returnT* ret, functionT func, a1T a1, a2T a2, a3T a3, a4T a4) : _ret(ret), _func(func), _a1(a1), _a2(a2), _a3(a3), _a4(a4) {} }; static void exec(void* a) { info* i = (info*) a; (*i->_func)(i->_a1, i->_a2, i->_a3, i->_a4); delete i; }};#endiftemplate <class returnT, class a1T, class a2T, class a3T, class a4T>inline sc_join_handlesc_spawn_function(returnT *ret, returnT (*func)(a1T, a2T, a3T, a4T), a1T a1, a2T a2, a3T a3, a4T a4){ return(sc_4_arg_function<returnT, a1T, a2T, a3T, a4T> ::spawn(ret, func, a1, a2, a3, a4));}template <class returnT, class a1T, class a2T, class a3T, class a4T>inline sc_join_handlesc_spawn_function(const sc_spawn_options& opts, returnT *ret, returnT (*func)(a1T, a2T, a3T, a4T), a1T a1, a2T a2, a3T a3, a4T a4){ return(sc_4_arg_function<returnT, a1T, a2T, a3T, a4T> ::spawn(ret, func, a1, a2, a3, a4, &opts));}// Template for spawning non-static methods within classes// that have no arguments in a type safe way.template <class returnT, class objectT>class sc_0_arg_method{public: typedef returnT (objectT::*methodT)(); static sc_join_handle spawn( returnT* ret, objectT* obj, methodT method, const sc_spawn_options * options=0) { info* i = new info(ret, obj, method); return sc_spawn_low_level(exec, i, options); }private: struct info { returnT* _ret; objectT* _obj; methodT _method; info(returnT* ret, objectT* obj, methodT method) : _ret(ret), _obj(obj), _method(method) {} }; static void exec(void* a) { info* i = (info*) a; methodT method = i->_method; if (i->_ret == 0) (i->_obj->*method)(); else *(i->_ret) = (i->_obj->*method)(); delete i; }};#ifndef SC_FORK_NO_TEMP_SPCL// Template specialization for void return typetemplate <class objectT>class sc_0_arg_method <void, objectT>{public: typedef void returnT; typedef returnT (objectT::*methodT)(); static sc_join_handle spawn( returnT* ret, objectT* obj, methodT method, const sc_spawn_options * options=0) { info* i = new info(ret, obj, method); return sc_spawn_low_level(exec, i, options); }private: struct info { returnT* _ret; objectT* _obj; methodT _method; info(returnT* ret, objectT* obj, methodT method) : _ret(ret), _obj(obj), _method(method) {} }; static void exec(void* a) { info* i = (info*) a; methodT method = i->_method; (i->_obj->*method)(); delete i; }};#endiftemplate <class returnT, class objectT>inline sc_join_handlesc_spawn_method(returnT *ret, objectT* obj, returnT (objectT::*func)()){ return(sc_0_arg_method<returnT, objectT> ::spawn(ret, obj, func));}template <class returnT, class objectT>inline sc_join_handlesc_spawn_method(const sc_spawn_options& opts, returnT *ret, objectT* obj, returnT (objectT::*func)()){ return(sc_0_arg_method<returnT, objectT> ::spawn(ret, obj, func, &opts));}// Template for spawning non-static methods within classes// that have a single argument in a type safe way.template <class returnT, class objectT, class a1T>class sc_1_arg_method{public: typedef returnT (objectT::*methodT)(a1T); static sc_join_handle spawn( returnT* ret, objectT* obj, methodT method, a1T a1, const sc_spawn_options * options=0) { info* i = new info(ret, obj, method, a1); return sc_spawn_low_level(exec, i, options); }private: struct info { returnT* _ret; objectT* _obj; methodT _method; a1T _a1; info(returnT* ret, objectT* obj, methodT method, a1T a1) : _ret(ret), _obj(obj), _method(method), _a1(a1) {} }; static void exec(void* a) { info* i = (info*) a; methodT method = i->_method; if (i->_ret == 0) (i->_obj->*method)(i->_a1); else *(i->_ret) = (i->_obj->*method)(i->_a1); delete i; }};#ifndef SC_FORK_NO_TEMP_SPCL// Template specialization for void return typetemplate <class objectT, class a1T>class sc_1_arg_method <void, objectT, a1T>{public: typedef void returnT; typedef returnT (objectT::*methodT)(a1T); static sc_join_handle spawn( returnT* ret, objectT* obj, methodT method, a1T a1, const sc_spawn_options * options=0) { info* i = new info(ret, obj, method, a1); return sc_spawn_low_level(exec, i, options); }private: struct info { returnT* _ret; objectT* _obj; methodT _method; a1T _a1; info(returnT* ret, objectT* obj, methodT method, a1T a1) : _ret(ret), _obj(obj), _method(method), _a1(a1) {} }; static void exec(void* a) { info* i = (info*) a; methodT method = i->_method; (i->_obj->*method)(i->_a1); delete i; }};#endiftemplate <class returnT, class objectT, class a1T>inline sc_join_handlesc_spawn_method(returnT *ret, objectT* obj, returnT (objectT::*func)(a1T), a1T a1){ return(sc_1_arg_method<returnT, objectT, a1T> ::spawn(ret, obj, func, a1));}template <class returnT, class objectT, class a1T>inline sc_join_handlesc_spawn_method(const sc_spawn_options& opts, returnT *ret, objectT* obj, returnT (objectT::*func)(a1T), a1T a1){ return(sc_1_arg_method<returnT, objectT, a1T> ::spawn(ret, obj, func, a1, &opts));}// Template for spawning non-static methods within classes// that have two arguments in a type safe way.template <class returnT, class objectT, class a1T, class a2T>class sc_2_arg_method{public: typedef returnT (objectT::*methodT)(a1T, a2T); static sc_join_handle spawn( returnT* ret, objectT* obj, methodT method, a1T a1, a2T a2, const sc_spawn_options * options=0) { info* i = new info(ret, obj, method, a1, a2); return sc_spawn_low_level(exec, i, options); }private: struct info { returnT* _ret; objectT* _obj; methodT _method; a1T _a1; a2T _a2; info(returnT* ret, objectT* obj, methodT method, a1T a1, a2T a2) : _ret(ret), _obj(obj), _method(method), _a1(a1), _a2(a2) {} }; static void exec(void* a) { info* i = (info*) a; methodT method = i->_method; if (i->_ret == 0) (i->_obj->*method)(i->_a1, i->_a2); else *(i->_ret) = (i->_obj->*method)(i->_a1, i->_a2); delete i; }};#ifndef SC_FORK_NO_TEMP_SPCL// Template specialization for void return typetemplate <class objectT, class a1T, class a2T>class sc_2_arg_method <void, objectT, a1T, a2T>{public: typedef void returnT; typedef returnT (objectT::*methodT)(a1T, a2T); static sc_join_handle spawn( returnT* ret, objectT* obj, methodT method, a1T a1, a2T a2, const sc_spawn_options * options=0) { info* i = new info(ret, obj, method, a1, a2); return sc_spawn_low_level(exec, i, options); }private: struct info { returnT* _ret; objectT* _obj; methodT _method; a1T _a1; a2T _a2; info(returnT* ret, objectT* obj, methodT method, a1T a1, a2T a2) : _ret(ret), _obj(obj), _method(method), _a1(a1), _a2(a2) {} }; static void exec(void* a) { info* i = (info*) a; methodT method = i->_method; (i->_obj->*method)(i->_a1, i->_a2); delete i; }};#endiftemplate <class returnT, class objectT, class a1T, class a2T>inline sc_join_handlesc_spawn_method(returnT *ret, objectT* obj, returnT (objectT::*func)(a1T, a2T), a1T a1, a2T a2){ return(sc_2_arg_method<returnT, objectT, a1T, a2T> ::spawn(ret, obj, func, a1, a2));}template <class returnT, class objectT, class a1T, class a2T>inline sc_join_handlesc_spawn_method(const sc_spawn_options& opts, returnT *ret, objectT* obj, returnT (objectT::*func)(a1T, a2T), a1T a1, a2T a2){ return(sc_2_arg_method<returnT, objectT, a1T, a2T> ::spawn(ret, obj, func, a1, a2, &opts));}// Template for spawning non-static methods within classes// that have 3 arguments in a type safe way.template <class returnT, class objectT, class a1T, class a2T, class a3T>class sc_3_arg_method{public: typedef returnT (objectT::*methodT)(a1T, a2T, a3T); static sc_join_handle spawn( returnT* ret, objectT* obj, methodT method, a1T a1, a2T a2, a3T a3, const sc_spawn_options * options=0) { info* i = new info(ret, obj, method, a1, a2, a3); return sc_spawn_low_level(exec, i, options); }private: struct info { returnT* _ret; objectT* _obj; methodT _method; a1T _a1; a2T _a2; a3T _a3; info(returnT* ret, objectT* obj, methodT method, a1T a1, a2T a2, a3T a3) : _ret(ret), _obj(obj), _method(method), _a1(a1), _a2(a2), _a3(a3) {} }; static void exec(void* a) { info* i = (info*) a; methodT method = i->_method; if (i->_ret == 0) (i->_obj->*method)(i->_a1, i->_a2, i->_a3); else *(i->_ret) = (i->_obj->*method)(i->_a1, i->_a2, i->_a3); delete i; }};#ifndef SC_FORK_NO_TEMP_SPCL// Template specialization for void return typetemplate <class objectT, class a1T, class a2T, class a3T>class sc_3_arg_method <void, objectT, a1T, a2T, a3T>{public: typedef void returnT; typedef returnT (objectT::*methodT)(a1T, a2T, a3T); static sc_join_handle spawn( returnT* ret, objectT* obj, methodT method, a1T a1, a2T a2, a3T a3, const sc_spawn_options * options=0) { info* i = new info(ret, obj, method, a1, a2, a3); return sc_spawn_low_level(exec, i, options); }private: struct info { returnT* _ret; objectT* _obj; methodT _method; a1T _a1; a2T _a2; a3T _a3; info(returnT* ret, objectT* obj, methodT method, a1T a1, a2T a2, a3T a3) : _ret(ret), _obj(obj), _method(method), _a1(a1), _a2(a2), _a3(a3) {} }; static void exec(void* a) { info* i = (info*) a; methodT method = i->_method; (i->_obj->*method)(i->_a1, i->_a2, i->_a3); delete i; }};#endiftemplate <class returnT, class objectT, class a1T, class a2T, class a3T>inline sc_join_handlesc_spawn_method(returnT *ret, objectT* obj, returnT (objectT::*func)(a1T, a2T, a3T), a1T a1, a2T a2, a3T a3){ return(sc_3_arg_method<returnT, objectT, a1T, a2T, a3T> ::spawn(ret, obj, func, a1, a2, a3));}template <class returnT, class objectT, class a1T, class a2T, class a3T>inline sc_join_handlesc_spawn_method(const sc_spawn_options& opts, returnT *ret, objectT* obj, returnT (objectT::*func)(a1T, a2T, a3T), a1T a1, a2T a2, a3T a3){ return(sc_3_arg_method<returnT, objectT, a1T, a2T, a3T> ::spawn(ret, obj, func, a1, a2, a3, &opts));}// Template for spawning non-static methods within classes// that have 4 arguments in a type safe way.template <class returnT, class objectT, class a1T, class a2T, class a3T, class a4T>class sc_4_arg_method{public: typedef returnT (objectT::*methodT)(a1T, a2T, a3T, a4T); static sc_join_handle spawn( returnT* ret, objectT* obj, methodT method, a1T a1, a2T a2, a3T a3, a4T a4, const sc_spawn_options * options=0) { info* i = new info(ret, obj, method, a1, a2, a3, a4); return sc_spawn_low_level(exec, i, options); }private: struct info { returnT* _ret; objectT* _obj; methodT _method; a1T _a1; a2T _a2; a3T _a3; a4T _a4; info(returnT* ret, objectT* obj, methodT method, a1T a1, a2T a2, a3T a3, a4T a4) : _ret(ret), _obj(obj), _method(method), _a1(a1), _a2(a2), _a3(a3), _a4(a4) {} }; static void exec(void* a) { info* i = (info*) a; methodT method = i->_method; if (i->_ret == 0) (i->_obj->*method)(i->_a1, i->_a2, i->_a3, i->_a4); else *(i->_ret) = (i->_obj->*method)(i->_a1, i->_a2, i->_a3, i->_a4); delete i; }};#ifndef SC_FORK_NO_TEMP_SPCL// Template specialization for void return typetemplate <class objectT, class a1T, class a2T, class a3T, class a4T>class sc_4_arg_method <void, objectT, a1T, a2T, a3T, a4T>{public: typedef void returnT; typedef returnT (objectT::*methodT)(a1T, a2T, a3T, a4T); static sc_join_handle spawn( returnT* ret, objectT* obj, methodT method, a1T a1, a2T a2, a3T a3, a4T a4, const sc_spawn_options * options=0) { info* i = new info(ret, obj, method, a1, a2, a3, a4); return sc_spawn_low_level(exec, i, options); }private: struct info { returnT* _ret; objectT* _obj; methodT _method; a1T _a1; a2T _a2; a3T _a3; a4T _a4; info(returnT* ret, objectT* obj, methodT method, a1T a1, a2T a2, a3T a3, a4T a4) : _ret(ret), _obj(obj), _method(method), _a1(a1), _a2(a2), _a3(a3), _a4(a4) {} }; static void exec(void* a) { info* i = (info*) a; methodT method = i->_method; (i->_obj->*method)(i->_a1, i->_a2, i->_a3, i->_a4); delete i; }};#endiftemplate <class returnT, class objectT, class a1T, class a2T, class a3T, class a4T>inline sc_join_handlesc_spawn_method(returnT *ret, objectT* obj, returnT (objectT::*func)(a1T, a2T, a3T, a4T), a1T a1, a2T a2, a3T a3, a4T a4){ return(sc_4_arg_method<returnT, objectT, a1T, a2T, a3T, a4T> ::spawn(ret, obj, func, a1, a2, a3, a4));}template <class returnT, class objectT, class a1T, class a2T, class a3T, class a4T>inline sc_join_handlesc_spawn_method(const sc_spawn_options& opts, returnT *ret, objectT* obj, returnT (objectT::*func)(a1T, a2T, a3T, a4T), a1T a1, a2T a2, a3T a3, a4T a4){ return(sc_4_arg_method<returnT, objectT, a1T, a2T, a3T, a4T> ::spawn(ret, obj, func, a1, a2, a3, a4, &opts));}// Public function to allow one process to wait for another to complete:inline void sc_process_join(sc_join_handle p){ thread_pool::global_thread_pool->join(p);}#define SC_FORK { sc_join_handle sc_fork_V[] = {#define SC_JOIN }; for (unsigned sc_fork_I=0; \ sc_fork_I < sizeof(sc_fork_V)/sizeof(sc_fork_V[0]); sc_fork_I++) \ sc_process_join(sc_fork_V[sc_fork_I]); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -