[asterisk-commits] dhubbard: branch group/taskprocessors r110863 - in /team/group/taskprocessors...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Mar 25 21:44:03 CDT 2008
Author: dhubbard
Date: Tue Mar 25 21:44:03 2008
New Revision: 110863
URL: http://svn.digium.com/view/asterisk?view=rev&rev=110863
Log:
Get rid of some attribute stuff that was not used. Inch towards coding guidelines conformance. Change ast_taskproducer_alloc interface
Modified:
team/group/taskprocessors/apps/app_queue.c
team/group/taskprocessors/apps/app_voicemail.c
team/group/taskprocessors/include/asterisk/taskprocessor.h
team/group/taskprocessors/main/pbx.c
team/group/taskprocessors/main/taskprocessor.c
Modified: team/group/taskprocessors/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/group/taskprocessors/apps/app_queue.c?view=diff&rev=110863&r1=110862&r2=110863
==============================================================================
--- team/group/taskprocessors/apps/app_queue.c (original)
+++ team/group/taskprocessors/apps/app_queue.c Tue Mar 25 21:44:03 2008
@@ -132,8 +132,7 @@
{ QUEUE_STRATEGY_WRANDOM, "wrandom"},
};
-static struct taskproducer *taskproducer;
-static struct taskprocessor_singleton_info *taskprocessor;
+static struct ast_taskproducer *taskproducer;
#define DEFAULT_RETRY 5
#define DEFAULT_TIMEOUT 15
@@ -6165,7 +6164,6 @@
ao2_ref(queues, -1);
ao2_ref(taskproducer, -1);
- ao2_ref(taskprocessor, -1);
return res;
}
@@ -6211,8 +6209,7 @@
res |= ast_custom_function_register(&queuewaitingcount_function);
res |= ast_custom_function_register(&queuememberpenalty_function);
- taskprocessor = ast_taskprocessor_reference("app_queue", 0);
- taskproducer = ast_taskproducer_alloc(taskprocessor);
+ taskproducer = ast_taskproducer_alloc("app_queue");
if (!(device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, device_state_cb, NULL, AST_EVENT_IE_END)))
res = -1;
Modified: team/group/taskprocessors/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/group/taskprocessors/apps/app_voicemail.c?view=diff&rev=110863&r1=110862&r2=110863
==============================================================================
--- team/group/taskprocessors/apps/app_voicemail.c (original)
+++ team/group/taskprocessors/apps/app_voicemail.c Tue Mar 25 21:44:03 2008
@@ -620,8 +620,7 @@
uint32_t uniqueid;
};
-static struct taskprocessor_singleton_info *taskprocessor;
-static struct taskproducer *taskproducer;
+static struct ast_taskproducer *taskproducer;
static AST_RWLIST_HEAD_STATIC(mwi_subs, mwi_sub);
@@ -8902,8 +8901,6 @@
stop_poll_thread();
ao2_ref(taskproducer, -1);
- ao2_ref(taskprocessor, -1);
-
return res;
}
@@ -8917,8 +8914,7 @@
snprintf(VM_SPOOL_DIR, sizeof(VM_SPOOL_DIR), "%s/voicemail/", ast_config_AST_SPOOL_DIR);
/* this should probably go into load_config() */
- taskprocessor = ast_taskprocessor_reference("app_voicemail", 0);
- taskproducer = ast_taskproducer_alloc(taskprocessor);
+ taskproducer = ast_taskproducer_alloc("app_voicemail");
if ((res = load_config(0)))
return res;
Modified: team/group/taskprocessors/include/asterisk/taskprocessor.h
URL: http://svn.digium.com/view/asterisk/team/group/taskprocessors/include/asterisk/taskprocessor.h?view=diff&rev=110863&r1=110862&r2=110863
==============================================================================
--- team/group/taskprocessors/include/asterisk/taskprocessor.h (original)
+++ team/group/taskprocessors/include/asterisk/taskprocessor.h Tue Mar 25 21:44:03 2008
@@ -25,11 +25,11 @@
#define __taskprocessor_h__
struct a_task {
- int (* execute)(struct a_task* t);
+ int (*execute)(struct a_task *t);
void *_datap;
size_t _datapsize;
- void* _p_producer;
- void* _p_consumer;
+ void *_p_producer;
+ void *_p_consumer;
time_t _timestamp;
char _source[256];
AST_LIST_ENTRY(a_task) list;
@@ -51,33 +51,33 @@
pthread_t _poll_thread;
ast_mutex_t _taskprocessor_lock;
unsigned char _poll_thread_run;
- struct taskprocessor_singleton_stats* _stats;
+ struct taskprocessor_singleton_stats *_stats;
void *_private;
long _queue_size;
AST_LIST_HEAD(_queue, a_task) _queue;
AST_LIST_ENTRY(taskprocessor_singleton_info) list;
};
-struct taskproducer {
- struct taskprocessor_singleton_info* _taskprocessor;
+struct ast_taskproducer {
+ struct taskprocessor_singleton_info *_taskprocessor;
unsigned long _tasks_produced;
- int (* queue_task)(struct taskproducer* producer, struct a_task* task);
+ int (*queue_task)(struct ast_taskproducer *producer, struct a_task *task);
};
unsigned char _evtq_poll_thread_run;
int ast_taskprocessor_init(void);
-struct a_task* ast_task_alloc(int (*task_exe)(struct a_task *task), void* datap, char* src);
-int ast_task_free(struct a_task* task);
+struct a_task *ast_task_alloc(int (*task_exe)(struct a_task *task), void *datap, char *src);
+int ast_task_free(struct a_task *task);
-int ast_taskprocessor_push(struct taskprocessor_singleton_info* tp, struct a_task* t);
-struct a_task* ast_taskprocessor_pop(struct taskprocessor_singleton_info* tp);
-int ast_taskprocessor_depth(struct taskprocessor_singleton_info* tp);
+int ast_taskprocessor_push(struct taskprocessor_singleton_info *tp, struct a_task *t);
+struct a_task *ast_taskprocessor_pop(struct taskprocessor_singleton_info *tp);
+int ast_taskprocessor_depth(struct taskprocessor_singleton_info *tp);
struct taskprocessor_singleton_info *ast_taskprocessor_reference(const char *name, void *(*func)(void*));
int ast_taskprocessor_count(void);
-struct taskproducer* ast_taskproducer_alloc(struct taskprocessor_singleton_info* processor);
+struct ast_taskproducer *ast_taskproducer_alloc(const char *name);
#endif
Modified: team/group/taskprocessors/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/taskprocessors/main/pbx.c?view=diff&rev=110863&r1=110862&r2=110863
==============================================================================
--- team/group/taskprocessors/main/pbx.c (original)
+++ team/group/taskprocessors/main/pbx.c Tue Mar 25 21:44:03 2008
@@ -124,8 +124,7 @@
struct ast_context;
struct ast_app;
-static struct taskprocessor_singleton_info *taskprocessor;
-static struct taskproducer *taskproducer;
+static struct ast_taskproducer *taskproducer;
AST_THREADSTORAGE(switch_data);
@@ -7837,8 +7836,7 @@
/* Register manager application */
ast_manager_register2("ShowDialPlan", EVENT_FLAG_CONFIG | EVENT_FLAG_REPORTING, manager_show_dialplan, "List dialplan", mandescr_show_dialplan);
- taskprocessor = ast_taskprocessor_reference("pbx", 0);
- taskproducer = ast_taskproducer_alloc(taskprocessor);
+ taskproducer = ast_taskproducer_alloc("pbx-core");
if (!(device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, device_state_cb, NULL,
AST_EVENT_IE_END))) {
Modified: team/group/taskprocessors/main/taskprocessor.c
URL: http://svn.digium.com/view/asterisk/team/group/taskprocessors/main/taskprocessor.c?view=diff&rev=110863&r1=110862&r2=110863
==============================================================================
--- team/group/taskprocessors/main/taskprocessor.c (original)
+++ team/group/taskprocessors/main/taskprocessor.c Tue Mar 25 21:44:03 2008
@@ -37,13 +37,12 @@
static int _global_killflag = 0;
AST_MUTEX_DEFINE_STATIC(_global_killflag_lock);
-pthread_attr_t _attribute[100];
AST_LIST_HEAD_STATIC(_taskprocessor_singletons, taskprocessor_singleton_info);
static int _taskprocessor_singletons_list_size = 0;
-static void* tps_default_processor_function(void* data);
-static struct taskprocessor_singleton_info* tps_default_constructor(int poll_freq);
-static int tps_taskprocessor_add(struct taskprocessor_singleton_info* t);
+static void *tps_default_processor_function(void *data);
+static struct taskprocessor_singleton_info *tps_default_constructor(int poll_freq);
+static int tps_taskprocessor_add(struct taskprocessor_singleton_info *t);
static void tps_taskprocessor_destroy(void *tps);
static void tps_taskproducer_destroy(void *tp);
static int tps_taskprocessor_ping_handler(struct a_task* e);
@@ -72,12 +71,12 @@
* \param src where the task came from, this is going to be debug only
* \return A task prepared to be queued into a taskprocessor
*/
-struct a_task* ast_task_alloc(int (*task_exe)(struct a_task *task), void* datap, char* src)
+struct a_task *ast_task_alloc(int (*task_exe)(struct a_task *task), void *datap, char *src)
{
struct a_task *t;
t = ast_calloc(1,sizeof(*t));
if (!t) {
- ast_log(LOG_ERROR, "Poop. Failed to allocate memory for \'%s\'\n", src);
+ ast_log(LOG_ERROR, "Failed to allocate memory for \'%s\'\n", src);
return NULL;
}
t->execute = task_exe;
@@ -90,7 +89,7 @@
* \param task the task to be freed
* \return 0 on success
*/
-int ast_task_free(struct a_task* task)
+int ast_task_free(struct a_task *task)
{
if (task->_datap) {
ast_free(task->_datap);
@@ -131,7 +130,7 @@
static char *cli_taskprocessor_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int found = 0;
- struct a_task* t = NULL;
+ struct a_task *t = NULL;
struct taskprocessor_singleton_info *p = NULL;
switch (cmd) {
@@ -184,7 +183,7 @@
unsigned long qsize;
unsigned long maxqsize;
unsigned long processed;
- struct taskprocessor_singleton_info* p;
+ struct taskprocessor_singleton_info *p;
switch (cmd) {
case CLI_INIT:
@@ -221,10 +220,10 @@
* \note The default taskprocessor thread function can be overridden via ast_taskprocessor_reference()
* \return NULL
*/
-static void* tps_default_processor_function(void* data)
-{
- struct taskprocessor_singleton_info* i;
- struct a_task* t;
+static void *tps_default_processor_function(void *data)
+{
+ struct taskprocessor_singleton_info *i;
+ struct a_task *t;
struct timeval tv;
int size;
int killflag = 0;
@@ -259,8 +258,6 @@
}
ast_mutex_unlock(&i->_taskprocessor_lock);
ast_task_free(t);
- t = NULL;
-
ast_mutex_lock(&_global_killflag_lock);
killflag = _global_killflag;
ast_mutex_unlock(&_global_killflag_lock);
@@ -294,7 +291,7 @@
* \param task the ping task queued by the CLI operation
* \return 0 on success, -1 on error
*/
-static int tps_taskprocessor_ping_handler(struct a_task* task)
+static int tps_taskprocessor_ping_handler(struct a_task *task)
{
if (!task) {
ast_log(LOG_ERROR, "Huh? There is no task? This is totally unexpected!\n");
@@ -308,9 +305,9 @@
* \param poll_freq The polling frequency of the taskprocessor
* \return taskprocessor_singleton_info structure on success, NULL on error
*/
-static struct taskprocessor_singleton_info* tps_default_constructor(int poll_freq)
-{
- struct taskprocessor_singleton_info* tps;
+static struct taskprocessor_singleton_info *tps_default_constructor(int poll_freq)
+{
+ struct taskprocessor_singleton_info *tps;
tps = ao2_alloc(sizeof(*tps), tps_taskprocessor_destroy);
if (!tps) {
ast_log(LOG_ERROR, "cannot allocate memory for a taskprocessor_singleton_info structure.\n");
@@ -339,7 +336,7 @@
*/
struct taskprocessor_singleton_info *ast_taskprocessor_reference(const char *name, void *(*custom_func)(void*))
{
- int rc, index;
+ int rc;
struct taskprocessor_singleton_info *p;
if (!name) {
@@ -367,12 +364,9 @@
ao2_ref(p, -1);
return NULL;
}
- index = ast_taskprocessor_count();
- ast_log(LOG_DEBUG, "creating taskprocessor \'%s\' at index %d\n", name, index);
- pthread_attr_init(&_attribute[index]);
+ ast_log(LOG_DEBUG, "creating taskprocessor \'%s\', taskprocessor count: %d\n", name, ast_taskprocessor_count());
/* stay stopped if we are supposed to be stopped */
if (p->_poll_thread == AST_PTHREADT_STOP) {
- ast_log(LOG_DEBUG, "poll thread == AST_PTHREADT_STOP.\n");
ao2_ref(p, -1);
return NULL;
}
@@ -389,9 +383,9 @@
} else {
/* create the thread. This may seem silly, but it results in nicer 'core show threads' output */
if (custom_func) {
- rc = ast_pthread_create(&p->_poll_thread, &_attribute[index], custom_func, p);
+ rc = ast_pthread_create(&p->_poll_thread, NULL, custom_func, p);
} else {
- rc = ast_pthread_create(&p->_poll_thread, &_attribute[index], tps_default_processor_function, p);
+ rc = ast_pthread_create(&p->_poll_thread, NULL, tps_default_processor_function, p);
}
if (rc < 0) {
ast_mutex_unlock(&p->_taskprocessor_lock);
@@ -400,7 +394,6 @@
return NULL;
}
}
- pthread_attr_destroy(&_attribute[index]);
ast_mutex_unlock(&p->_taskprocessor_lock);
return p;
}
@@ -446,9 +439,9 @@
* \param t taskprocessor_singleton_info structure to add to the taskprocessor container
* \return 0 on success, -1 on error
*/
-static int tps_taskprocessor_add(struct taskprocessor_singleton_info* t)
-{
- struct taskprocessor_singleton_info* n = NULL;
+static int tps_taskprocessor_add(struct taskprocessor_singleton_info *t)
+{
+ struct taskprocessor_singleton_info *n = NULL;
AST_LIST_LOCK(&_taskprocessor_singletons);
AST_LIST_TRAVERSE(&_taskprocessor_singletons, n, list) {
@@ -482,12 +475,12 @@
* \param t task to push to taskprocessor
* \return 0 on success, -1 on error
*/
-int ast_taskprocessor_push(struct taskprocessor_singleton_info* tps, struct a_task* t)
+int ast_taskprocessor_push(struct taskprocessor_singleton_info *tps, struct a_task *t)
{
int lock_failures = 0;
if (!tps || !t) {
- ast_log(LOG_ERROR, "A %s is required for this function.\n", (tps)?"task":"taskprocessor");
+ ast_log(LOG_ERROR, "A \'%s\' is required for this function.\n", (tps)?"task":"taskprocessor");
return -1;
}
AST_LIST_LOCK(&tps->_queue);
@@ -512,9 +505,9 @@
* \param tps taskprocessor to pop task from
* \return task on success, NULL on error
*/
-struct a_task* ast_taskprocessor_pop(struct taskprocessor_singleton_info* tps)
-{
- struct a_task* t = NULL;
+struct a_task *ast_taskprocessor_pop(struct taskprocessor_singleton_info *tps)
+{
+ struct a_task *t = NULL;
int lock_failures = 0;
AST_LIST_LOCK(&tps->_queue);
@@ -541,7 +534,7 @@
* \param tps taskprocessor to return queue depth
* \return depth on success, -1 on error
*/
-int ast_taskprocessor_depth(struct taskprocessor_singleton_info* tps)
+int ast_taskprocessor_depth(struct taskprocessor_singleton_info *tps)
{
int size = -1;
int lock_failures = 0;
@@ -567,7 +560,7 @@
* \param producer wrapper around a taskprocessor and a queue() function
* \return 0 on success, -1 on error
*/
-static int tps_default_queue_task(struct taskproducer* producer, struct a_task* task)
+static int tps_default_queue_task(struct ast_taskproducer *producer, struct a_task *task)
{
if (!((producer)&&(producer->_taskprocessor)) || !task) {
ast_log(LOG_ERROR, "this function requires a proper \'%s\' structure.\n", (task)?"producer":"task");
@@ -585,19 +578,18 @@
}
/*! \brief Allocate and initialize a taskproducer structure with a default queue_task helper function
- * \param processor taskprocessor to queue tasks
+ * \param name of taskprocessor to reference
* \return taskproducer on success, NULL on error
*/
-struct taskproducer* ast_taskproducer_alloc(struct taskprocessor_singleton_info* processor)
-{
- struct taskproducer* p;
+struct ast_taskproducer *ast_taskproducer_alloc(const char *name)
+{
+ struct ast_taskproducer *p;
p = ao2_alloc(sizeof(*p), tps_taskproducer_destroy);
if (!p) {
ast_log(LOG_ERROR, "cannot allocate memory for a taskproducer structure.\n");
return NULL;
}
- p->_taskprocessor = processor;
- ao2_ref(processor, 1);
+ p->_taskprocessor = ast_taskprocessor_reference(name, 0);
p->queue_task = tps_default_queue_task;
return p;
}
@@ -608,8 +600,8 @@
*/
static void tps_taskproducer_destroy(void *tp)
{
- struct taskproducer *p;
- p = (struct taskproducer *)tp;
+ struct ast_taskproducer *p;
+ p = (struct ast_taskproducer *)tp;
ao2_ref(p->_taskprocessor, -1);
}
More information about the asterisk-commits
mailing list