forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenericAsyncTask.cxx
More file actions
103 lines (93 loc) · 2.61 KB
/
genericAsyncTask.cxx
File metadata and controls
103 lines (93 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file genericAsyncTask.cxx
* @author drose
* @date 2008-10-03
*/
#include "genericAsyncTask.h"
#include "pnotify.h"
TypeHandle GenericAsyncTask::_type_handle;
/**
*
*/
GenericAsyncTask::
GenericAsyncTask(const std::string &name) :
AsyncTask(name)
{
_function = nullptr;
_upon_birth = nullptr;
_upon_death = nullptr;
_user_data = nullptr;
}
/**
*
*/
GenericAsyncTask::
GenericAsyncTask(const std::string &name, GenericAsyncTask::TaskFunc *function, void *user_data) :
AsyncTask(name),
_function(function),
_user_data(user_data)
{
_upon_birth = nullptr;
_upon_death = nullptr;
}
/**
* 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 GenericAsyncTask::
is_runnable() {
return _function != nullptr;
}
/**
* Override this function to do something useful for the task.
*
* This function is called with the lock *not* held.
*/
AsyncTask::DoneStatus GenericAsyncTask::
do_task() {
nassertr(_function != nullptr, DS_interrupt);
return (*_function)(this, _user_data);
}
/**
* Override this function to do something useful when the task has been added
* to the active queue.
*
* This function is called with the lock *not* held.
*/
void GenericAsyncTask::
upon_birth(AsyncTaskManager *manager) {
AsyncTask::upon_birth(manager);
if (_upon_birth != nullptr) {
(*_upon_birth)(this, _user_data);
}
}
/**
* Override this function to do something useful when the task has been
* removed from the active queue. The parameter clean_exit is true if the
* task has been removed because it exited normally (returning DS_done), or
* false if it was removed for some other reason (e.g.
* AsyncTaskManager::remove()). By the time this method is called, _manager
* has been cleared, so the parameter manager indicates the original
* AsyncTaskManager that owned this task.
*
* The normal behavior is to throw the done_event only if clean_exit is true.
*
* This function is called with the lock *not* held.
*/
void GenericAsyncTask::
upon_death(AsyncTaskManager *manager, bool clean_exit) {
AsyncTask::upon_death(manager, clean_exit);
if (_upon_death != nullptr) {
(*_upon_death)(this, clean_exit, _user_data);
}
}