mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 13:25:45 +02:00
task: track number of Task objects in program and provide report
This is a simple lightweight counter that tracks the number of Task objects that exist. Useful for leak detection. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
parent
b7f9ce3f08
commit
d5ff35eacf
@ -47,6 +47,10 @@ namespace crucible {
|
|||||||
/// Usually used to reschedule the currently executing Task.
|
/// Usually used to reschedule the currently executing Task.
|
||||||
static Task current_task();
|
static Task current_task();
|
||||||
|
|
||||||
|
/// Returns number of currently existing Task objects.
|
||||||
|
/// Good for spotting leaks.
|
||||||
|
static size_t instance_count();
|
||||||
|
|
||||||
/// Ordering operator for containers
|
/// Ordering operator for containers
|
||||||
bool operator<(const Task &that) const;
|
bool operator<(const Task &that) const;
|
||||||
|
|
||||||
|
26
lib/task.cc
26
lib/task.cc
@ -65,6 +65,9 @@ namespace crucible {
|
|||||||
/// Sequential identifier for next task
|
/// Sequential identifier for next task
|
||||||
static atomic<TaskId> s_next_id;
|
static atomic<TaskId> s_next_id;
|
||||||
|
|
||||||
|
/// Sequential identifier for next task
|
||||||
|
static atomic<size_t> s_instance_count;
|
||||||
|
|
||||||
/// Identifier for this task
|
/// Identifier for this task
|
||||||
TaskId m_id;
|
TaskId m_id;
|
||||||
|
|
||||||
@ -89,6 +92,7 @@ namespace crucible {
|
|||||||
TaskState(const TaskState &) = delete;
|
TaskState(const TaskState &) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
~TaskState();
|
||||||
TaskState(string title, function<void()> exec_fn);
|
TaskState(string title, function<void()> exec_fn);
|
||||||
|
|
||||||
/// Run the task at least once. If task is already running, appends
|
/// Run the task at least once. If task is already running, appends
|
||||||
@ -112,9 +116,13 @@ namespace crucible {
|
|||||||
/// If current task is neither running nor waiting, this
|
/// If current task is neither running nor waiting, this
|
||||||
/// places the argument task on a worker queue immediately.
|
/// places the argument task on a worker queue immediately.
|
||||||
void append(const TaskStatePtr &task);
|
void append(const TaskStatePtr &task);
|
||||||
|
|
||||||
|
/// How masy Tasks are there? Good for catching leaks
|
||||||
|
static size_t instance_count();
|
||||||
};
|
};
|
||||||
|
|
||||||
atomic<TaskId> TaskState::s_next_id;
|
atomic<TaskId> TaskState::s_next_id;
|
||||||
|
atomic<size_t> TaskState::s_instance_count;
|
||||||
|
|
||||||
class TaskMasterState : public enable_shared_from_this<TaskMasterState> {
|
class TaskMasterState : public enable_shared_from_this<TaskMasterState> {
|
||||||
mutex m_mutex;
|
mutex m_mutex;
|
||||||
@ -202,12 +210,30 @@ namespace crucible {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TaskState::~TaskState()
|
||||||
|
{
|
||||||
|
--s_instance_count;
|
||||||
|
}
|
||||||
|
|
||||||
TaskState::TaskState(string title, function<void()> exec_fn) :
|
TaskState::TaskState(string title, function<void()> exec_fn) :
|
||||||
m_exec_fn(exec_fn),
|
m_exec_fn(exec_fn),
|
||||||
m_title(title),
|
m_title(title),
|
||||||
m_id(++s_next_id)
|
m_id(++s_next_id)
|
||||||
{
|
{
|
||||||
THROW_CHECK0(invalid_argument, !m_title.empty());
|
THROW_CHECK0(invalid_argument, !m_title.empty());
|
||||||
|
++s_instance_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
TaskState::instance_count()
|
||||||
|
{
|
||||||
|
return s_instance_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
Task::instance_count()
|
||||||
|
{
|
||||||
|
return TaskState::instance_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user