[asterisk-commits] murf: trunk r114183 - /trunk/main/event.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 16 15:28:09 CDT 2008
Author: murf
Date: Wed Apr 16 15:28:08 2008
New Revision: 114183
URL: http://svn.digium.com/view/asterisk?view=rev&rev=114183
Log:
Introducing a small optimization to event_unsubscribe; events now use a Doubly-Linked list for events, gives fast deletions, for the sake of channel driver mwi events. From team/murf/bug11210.
Modified:
trunk/main/event.c
Modified: trunk/main/event.c
URL: http://svn.digium.com/view/asterisk/trunk/main/event.c?view=diff&rev=114183&r1=114182&r2=114183
==============================================================================
--- trunk/main/event.c (original)
+++ trunk/main/event.c Wed Apr 16 15:28:08 2008
@@ -30,6 +30,7 @@
#include "asterisk/_private.h"
#include "asterisk/event.h"
#include "asterisk/linkedlists.h"
+#include "asterisk/dlinkedlists.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/unaligned.h"
@@ -109,14 +110,14 @@
void *userdata;
uint32_t uniqueid;
AST_LIST_HEAD_NOLOCK(, ast_event_ie_val) ie_vals;
- AST_RWLIST_ENTRY(ast_event_sub) entry;
+ AST_RWDLLIST_ENTRY(ast_event_sub) entry;
};
static uint32_t sub_uniqueid;
/*! \brief Event subscriptions
* The event subscribers are indexed by which event they are subscribed to */
-static AST_RWLIST_HEAD(ast_event_sub_list, ast_event_sub) ast_event_subs[AST_EVENT_TOTAL];
+static AST_RWDLLIST_HEAD(ast_event_sub_list, ast_event_sub) ast_event_subs[AST_EVENT_TOTAL];
/*! \brief Cached events
* The event cache is indexed on the event type. The purpose of this is
@@ -163,8 +164,8 @@
}
va_end(ap);
- AST_RWLIST_RDLOCK(&ast_event_subs[type]);
- AST_RWLIST_TRAVERSE(&ast_event_subs[type], sub, entry) {
+ AST_RWDLLIST_RDLOCK(&ast_event_subs[type]);
+ AST_RWDLLIST_TRAVERSE(&ast_event_subs[type], sub, entry) {
AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) {
AST_LIST_TRAVERSE(&sub->ie_vals, sub_ie_val, entry) {
if (sub_ie_val->ie_type == ie_val->ie_type)
@@ -188,15 +189,15 @@
if (!ie_val)
break;
}
- AST_RWLIST_UNLOCK(&ast_event_subs[type]);
+ AST_RWDLLIST_UNLOCK(&ast_event_subs[type]);
if (sub) /* All parameters were matched */
return AST_EVENT_SUB_EXISTS;
- AST_RWLIST_RDLOCK(&ast_event_subs[AST_EVENT_ALL]);
- if (!AST_LIST_EMPTY(&ast_event_subs[AST_EVENT_ALL]))
+ AST_RWDLLIST_RDLOCK(&ast_event_subs[AST_EVENT_ALL]);
+ if (!AST_DLLIST_EMPTY(&ast_event_subs[AST_EVENT_ALL]))
res = AST_EVENT_SUB_EXISTS;
- AST_RWLIST_UNLOCK(&ast_event_subs[AST_EVENT_ALL]);
+ AST_RWDLLIST_UNLOCK(&ast_event_subs[AST_EVENT_ALL]);
return res;
}
@@ -222,8 +223,8 @@
if (event_type == -1)
return;
- AST_RWLIST_RDLOCK(&ast_event_subs[event_type]);
- AST_RWLIST_TRAVERSE(&ast_event_subs[event_type], sub, entry) {
+ AST_RWDLLIST_RDLOCK(&ast_event_subs[event_type]);
+ AST_RWDLLIST_TRAVERSE(&ast_event_subs[event_type], sub, entry) {
if (event_sub == sub)
continue;
@@ -255,7 +256,7 @@
ast_event_destroy(event);
}
- AST_RWLIST_UNLOCK(&ast_event_subs[event_type]);
+ AST_RWDLLIST_UNLOCK(&ast_event_subs[event_type]);
}
struct ast_event_sub *ast_event_subscribe(enum ast_event_type type, ast_event_cb_t cb,
@@ -331,9 +332,9 @@
ast_event_queue(event);
}
- AST_RWLIST_WRLOCK(&ast_event_subs[type]);
- AST_RWLIST_INSERT_TAIL(&ast_event_subs[type], sub, entry);
- AST_RWLIST_UNLOCK(&ast_event_subs[type]);
+ AST_RWDLLIST_WRLOCK(&ast_event_subs[type]);
+ AST_RWDLLIST_INSERT_TAIL(&ast_event_subs[type], sub, entry);
+ AST_RWDLLIST_UNLOCK(&ast_event_subs[type]);
return sub;
}
@@ -352,9 +353,9 @@
{
struct ast_event *event;
- AST_RWLIST_WRLOCK(&ast_event_subs[sub->type]);
- AST_LIST_REMOVE(&ast_event_subs[sub->type], sub, entry);
- AST_RWLIST_UNLOCK(&ast_event_subs[sub->type]);
+ AST_RWDLLIST_WRLOCK(&ast_event_subs[sub->type]);
+ AST_DLLIST_REMOVE(&ast_event_subs[sub->type], sub, entry);
+ AST_RWDLLIST_UNLOCK(&ast_event_subs[sub->type]);
if (ast_event_check_subscriber(AST_EVENT_UNSUB,
AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
@@ -765,8 +766,8 @@
host_event_type = ntohs(event_ref->event->type);
/* Subscribers to this specific event first */
- AST_RWLIST_RDLOCK(&ast_event_subs[host_event_type]);
- AST_RWLIST_TRAVERSE(&ast_event_subs[host_event_type], sub, entry) {
+ AST_RWDLLIST_RDLOCK(&ast_event_subs[host_event_type]);
+ AST_RWDLLIST_TRAVERSE(&ast_event_subs[host_event_type], sub, entry) {
struct ast_event_ie_val *ie_val;
AST_LIST_TRAVERSE(&sub->ie_vals, ie_val, entry) {
if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_EXISTS &&
@@ -787,13 +788,13 @@
continue;
sub->cb(event_ref->event, sub->userdata);
}
- AST_RWLIST_UNLOCK(&ast_event_subs[host_event_type]);
+ AST_RWDLLIST_UNLOCK(&ast_event_subs[host_event_type]);
/* Now to subscribers to all event types */
- AST_RWLIST_RDLOCK(&ast_event_subs[AST_EVENT_ALL]);
- AST_RWLIST_TRAVERSE(&ast_event_subs[AST_EVENT_ALL], sub, entry)
+ AST_RWDLLIST_RDLOCK(&ast_event_subs[AST_EVENT_ALL]);
+ AST_RWDLLIST_TRAVERSE(&ast_event_subs[AST_EVENT_ALL], sub, entry)
sub->cb(event_ref->event, sub->userdata);
- AST_RWLIST_UNLOCK(&ast_event_subs[AST_EVENT_ALL]);
+ AST_RWDLLIST_UNLOCK(&ast_event_subs[AST_EVENT_ALL]);
ast_event_ref_destroy(event_ref);
}
@@ -806,7 +807,7 @@
int i;
for (i = 0; i < AST_EVENT_TOTAL; i++)
- AST_RWLIST_HEAD_INIT(&ast_event_subs[i]);
+ AST_RWDLLIST_HEAD_INIT(&ast_event_subs[i]);
for (i = 0; i < AST_EVENT_TOTAL; i++)
AST_RWLIST_HEAD_INIT(&ast_event_cache[i]);
More information about the asterisk-commits
mailing list