* \param listener The listener
*/
void (*emptied)(struct ast_taskprocessor_listener *listener);
+ /*!
+ * \brief Indicates the taskprocessor wishes to die.
+ *
+ * All operations on the task processor must to be stopped in
+ * this callback.
+ *
+ * After this callback returns, it is NOT safe to operate on the
+ * listener's reference to the taskprocessor.
+ *
+ * \param listener The listener
+ */
+ void (*shutdown)(struct ast_taskprocessor_listener *listener);
/*!
* \brief Destroy the listener's private data
*
struct ast_taskprocessor_listener *listener = obj;
listener->callbacks->destroy(listener->private_data);
+}
+static void listener_shutdown(struct ast_taskprocessor_listener *listener)
+{
+ listener->callbacks->shutdown(listener);
ao2_ref(listener->tps, -1);
listener->tps = NULL;
}
return pvt;
}
-static void default_listener_destroy(void *obj)
+static void default_listener_shutdown(struct ast_taskprocessor_listener *listener)
{
- struct default_taskprocessor_listener_pvt *pvt = obj;
-
+ struct default_taskprocessor_listener_pvt *pvt = listener->private_data;
default_tps_wake_up(pvt, 1);
pthread_join(pvt->poll_thread, NULL);
pvt->poll_thread = AST_PTHREADT_NULL;
+}
+
+static void default_listener_destroy(void *obj)
+{
+ struct default_taskprocessor_listener_pvt *pvt = obj;
ast_mutex_destroy(&pvt->lock);
ast_cond_destroy(&pvt->cond);
ast_free(pvt);
.alloc = default_listener_alloc,
.task_pushed = default_task_pushed,
.emptied = default_emptied,
+ .shutdown = default_listener_shutdown,
.destroy = default_listener_destroy,
};
ao2_unlink(tps_singletons, tps);
listener = tps->listener;
tps->listener = NULL;
+ listener_shutdown(listener);
ao2_ref(listener, -1);
return NULL;
}
{
struct tps_task *t;
int size;
-
+
if (!(t = tps_taskprocessor_pop(tps))) {
return 0;
}
int num_pushed;
int num_emptied;
int num_was_empty;
+ int shutdown;
};
static void *test_alloc(struct ast_taskprocessor_listener *listener)
++pvt->num_emptied;
}
+static void test_shutdown(struct ast_taskprocessor_listener *listener)
+{
+ struct test_listener_pvt *pvt = listener->private_data;
+ pvt->shutdown = 1;
+}
+
static void test_destroy(void *private_data)
{
struct test_listener_pvt *pvt = private_data;
.alloc = test_alloc,
.task_pushed = test_task_pushed,
.emptied = test_emptied,
+ .shutdown = test_shutdown,
.destroy = test_destroy,
};