diff --git a/panda/src/pipeline/genericThread.I b/panda/src/pipeline/genericThread.I index 11634fd226..a7b8fbb047 100644 --- a/panda/src/pipeline/genericThread.I +++ b/panda/src/pipeline/genericThread.I @@ -15,31 +15,14 @@ * Replaces the function that is called when the thread runs. */ INLINE void GenericThread:: -set_function(GenericThread::ThreadFunc *function) { - _function = function; +set_function(std::function function) { + _function = std::move(function); } /** * Returns the function that is called when the thread runs. */ -INLINE GenericThread::ThreadFunc *GenericThread:: +INLINE const std::function &GenericThread:: get_function() const { return _function; } - -/** - * Replaces the void pointer that is passed to the thread function. This is - * any arbitrary pointer; the thread object does no processing on it. - */ -INLINE void GenericThread:: -set_user_data(void *user_data) { - _user_data = user_data; -} - -/** - * Returns the void pointer that is passed to the thread function. - */ -INLINE void *GenericThread:: -get_user_data() const { - return _user_data; -} diff --git a/panda/src/pipeline/genericThread.cxx b/panda/src/pipeline/genericThread.cxx index 64eb0b4814..3d5248667f 100644 --- a/panda/src/pipeline/genericThread.cxx +++ b/panda/src/pipeline/genericThread.cxx @@ -14,6 +14,8 @@ #include "genericThread.h" #include "pnotify.h" +#ifndef CPPPARSER + TypeHandle GenericThread::_type_handle; /** @@ -23,8 +25,6 @@ GenericThread:: GenericThread(const std::string &name, const std::string &sync_name) : Thread(name, sync_name) { - _function = nullptr; - _user_data = nullptr; } /** @@ -33,8 +33,17 @@ GenericThread(const std::string &name, const std::string &sync_name) : GenericThread:: GenericThread(const std::string &name, const std::string &sync_name, GenericThread::ThreadFunc *function, void *user_data) : Thread(name, sync_name), - _function(function), - _user_data(user_data) + _function(std::bind(function, user_data)) +{ +} + +/** + * + */ +GenericThread:: +GenericThread(const std::string &name, const std::string &sync_name, std::function function) : + Thread(name, sync_name), + _function(std::move(function)) { } @@ -43,6 +52,8 @@ GenericThread(const std::string &name, const std::string &sync_name, GenericThre */ void GenericThread:: thread_main() { - nassertv(_function != nullptr); - (*_function)(_user_data); + nassertv(_function); + _function(); } + +#endif diff --git a/panda/src/pipeline/genericThread.h b/panda/src/pipeline/genericThread.h index 6e6a6ade6a..b13185af1d 100644 --- a/panda/src/pipeline/genericThread.h +++ b/panda/src/pipeline/genericThread.h @@ -17,6 +17,9 @@ #include "pandabase.h" #include "thread.h" +#ifndef CPPPARSER +#include + /** * A generic thread type that allows calling a C-style thread function without * having to subclass. @@ -27,19 +30,16 @@ public: GenericThread(const std::string &name, const std::string &sync_name); GenericThread(const std::string &name, const std::string &sync_name, ThreadFunc *function, void *user_data); + GenericThread(const std::string &name, const std::string &sync_name, std::function function); - INLINE void set_function(ThreadFunc *function); - INLINE ThreadFunc *get_function() const; - - INLINE void set_user_data(void *user_data); - INLINE void *get_user_data() const; + INLINE void set_function(std::function function); + INLINE const std::function &get_function() const; protected: virtual void thread_main(); private: - ThreadFunc *_function; - void *_user_data; + std::function _function; public: static TypeHandle get_class_type() { @@ -61,4 +61,6 @@ private: #include "genericThread.I" -#endif +#endif // CPPPARSER + +#endif // GENERICTHREAD_H