AsyncTask::is_runnable

This commit is contained in:
David Rose 2008-09-29 05:59:41 +00:00
parent c59bfe5459
commit 2266110083
5 changed files with 36 additions and 2 deletions

View File

@ -349,6 +349,21 @@ unlock_and_do_task() {
return status;
}
////////////////////////////////////////////////////////////////////
// Function: AsyncTask::is_runnable
// Access: Protected, Virtual
// Description: Override this function to return true if the task can
// be successfully executed, false if it cannot. Mainly
// intended as a sanity check when attempting to add the
// task to a task manager.
//
// This function is called with the lock held.
////////////////////////////////////////////////////////////////////
bool AsyncTask::
is_runnable() {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: AsyncTask::do_task
// Access: Protected, Virtual

View File

@ -111,6 +111,7 @@ protected:
void jump_to_task_chain(AsyncTaskManager *manager);
DoneStatus unlock_and_do_task();
virtual bool is_runnable();
virtual DoneStatus do_task();
virtual void upon_birth();
virtual void upon_death(bool clean_exit);

View File

@ -167,6 +167,8 @@ remove_task_chain(const string &name) {
////////////////////////////////////////////////////////////////////
void AsyncTaskManager::
add(AsyncTask *task) {
nassertv(task->is_runnable());
MutexHolder holder(_lock);
if (task_cat.is_debug()) {

View File

@ -79,7 +79,7 @@ set_function(PyObject *function) {
_function = function;
Py_INCREF(_function);
if (!PyCallable_Check(_function)) {
if (_function != Py_None && !PyCallable_Check(_function)) {
nassert_raise("Invalid function passed to PythonTask");
}
}
@ -306,6 +306,21 @@ __getattr__(const string &attr_name) const {
}
}
////////////////////////////////////////////////////////////////////
// Function: PythonTask::is_runnable
// Access: Protected, Virtual
// Description: Override this function to return true if the task can
// be successfully executed, false if it cannot. Mainly
// intended as a sanity check when attempting to add the
// task to a task manager.
//
// This function is called with the lock held.
////////////////////////////////////////////////////////////////////
bool PythonTask::
is_runnable() {
return _function != Py_None;
}
////////////////////////////////////////////////////////////////////
// Function: PythonTask::do_task
// Access: Protected, Virtual

View File

@ -27,7 +27,7 @@
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_PIPELINE PythonTask : public AsyncTask {
PUBLISHED:
PythonTask(PyObject *function, const string &name = string());
PythonTask(PyObject *function = Py_None, const string &name = string());
virtual ~PythonTask();
ALLOC_DELETED_CHAIN(PythonTask);
@ -48,6 +48,7 @@ PUBLISHED:
PyObject *__getattr__(const string &attr_name) const;
protected:
virtual bool is_runnable();
virtual DoneStatus do_task();
DoneStatus do_python_task();
virtual void upon_birth();