[asterisk-commits] russell: branch russell/event_performance r183908 - /team/russell/event_perfo...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Mar 24 06:57:18 CDT 2009
Author: russell
Date: Tue Mar 24 06:57:15 2009
New Revision: 183908
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=183908
Log:
Move to a common cmp function
Modified:
team/russell/event_performance/main/event.c
Modified: team/russell/event_performance/main/event.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/event_performance/main/event.c?view=diff&rev=183908&r1=183907&r2=183908
==============================================================================
--- team/russell/event_performance/main/event.c (original)
+++ team/russell/event_performance/main/event.c Tue Mar 24 06:57:15 2009
@@ -125,31 +125,31 @@
#define NUM_CACHE_BUCKETS 563
#endif
+static int ast_event_cmp(void *obj, void *arg, int flags);
static int ast_event_hash_mwi(const void *obj, const int flags);
-static int ast_event_cmp_mwi(void *obj, void *arg, int flags);
static int ast_event_hash_devstate(const void *obj, const int flags);
-static int ast_event_cmp_devstate(void *obj, void *arg, int flags);
static int ast_event_hash_devstate_change(const void *obj, const int flags);
-static int ast_event_cmp_devstate_change(void *obj, void *arg, int flags);
+
+#define MAX_CACHE_ARGS 8
/*!
* \brief Event types that are kept in the cache.
*/
static const struct {
ao2_hash_fn *hash_fn;
- ao2_callback_fn *cmp_fn;
+ enum ast_event_ie_type cache_args[MAX_CACHE_ARGS];
} cached_event_types[AST_EVENT_TOTAL] = {
[AST_EVENT_MWI] = {
.hash_fn = ast_event_hash_mwi,
- .cmp_fn = ast_event_cmp_mwi,
+ .cache_args = { AST_EVENT_IE_MAILBOX, AST_EVENT_IE_CONTEXT },
},
[AST_EVENT_DEVICE_STATE] = {
.hash_fn = ast_event_hash_devstate,
- .cmp_fn = ast_event_cmp_devstate,
+ .cache_args = { AST_EVENT_IE_DEVICE, },
},
[AST_EVENT_DEVICE_STATE_CHANGE] = {
.hash_fn = ast_event_hash_devstate_change,
- .cmp_fn = ast_event_cmp_devstate_change,
+ .cache_args = { AST_EVENT_IE_DEVICE, AST_EVENT_IE_EID, },
},
};
@@ -1047,7 +1047,6 @@
int ast_event_queue_and_cache(struct ast_event *event)
{
- ao2_callback_fn *cb_fn;
struct ao2_container *container;
struct ast_event_ref tmp_event_ref = {
.event = event,
@@ -1058,14 +1057,9 @@
goto queue_event;
}
- if (!(cb_fn = cached_event_types[ast_event_get_type(event)].cmp_fn)) {
- ast_log(LOG_WARNING, "cache requested for non-cached event type\n");
- goto queue_event;
- }
-
/* Remove matches from the cache */
ao2_callback(container, OBJ_POINTER | OBJ_UNLINK | OBJ_MULTIPLE | OBJ_NODATA,
- cb_fn, &tmp_event_ref);
+ ast_event_cmp, &tmp_event_ref);
queue_event:
return ast_event_queue(event);
@@ -1146,75 +1140,18 @@
return ast_str_hash_add(context, ast_str_hash(mailbox));
}
-static int ast_event_cmp_mwi(void *obj, void *arg, int flags)
+static int ast_event_hash_devstate(const void *obj, const int flags)
{
const struct ast_event *event = obj;
- const struct ast_event *event2 = arg;
- struct ast_event_ie_val ie_val = {
- .ie_type = AST_EVENT_IE_MAILBOX,
- };
-
- if (!match_ie_val(event, &ie_val, event2)) {
- return 0;
- }
-
- ie_val.ie_type = AST_EVENT_IE_CONTEXT;
-
- if (!match_ie_val(event, &ie_val, event2)) {
- return 0;
- }
-
- return CMP_MATCH;
-}
-
-static int ast_event_hash_devstate(const void *obj, const int flags)
+
+ return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE));
+}
+
+static int ast_event_hash_devstate_change(const void *obj, const int flags)
{
const struct ast_event *event = obj;
return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE));
-}
-
-static int ast_event_cmp_devstate(void *obj, void *arg, int flags)
-{
- const struct ast_event *event = obj;
- const struct ast_event *event2 = arg;
- struct ast_event_ie_val ie_val = {
- .ie_type = AST_EVENT_IE_DEVICE,
- };
-
- if (!match_ie_val(event, &ie_val, event2)) {
- return 0;
- }
-
- return CMP_MATCH;
-}
-
-static int ast_event_hash_devstate_change(const void *obj, const int flags)
-{
- const struct ast_event *event = obj;
-
- return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE));
-}
-
-static int ast_event_cmp_devstate_change(void *obj, void *arg, int flags)
-{
- const struct ast_event *event = obj;
- const struct ast_event *event2 = arg;
- struct ast_event_ie_val ie_val = {
- .ie_type = AST_EVENT_IE_DEVICE,
- };
-
- if (!match_ie_val(event, &ie_val, event2)) {
- return 0;
- }
-
- ie_val.ie_type = AST_EVENT_IE_EID;
-
- if (!match_ie_val(event, &ie_val, event2)) {
- return 0;
- }
-
- return CMP_MATCH;
}
static int ast_event_hash(const void *obj, const int flags)
@@ -1237,7 +1174,9 @@
{
struct ast_event_ref *event_ref, *event_ref2;
struct ast_event *event, *event2;
- ao2_callback_fn *cmp_fn;
+ int res = CMP_MATCH;
+ int i;
+ enum ast_event_ie_type *cache_args;
event_ref = obj;
event = event_ref->event;
@@ -1245,11 +1184,20 @@
event_ref2 = arg;
event2 = event_ref2->event;
- if (!(cmp_fn = cached_event_types[ast_event_get_type(event)].cmp_fn)) {
- return 0;
- }
-
- return cmp_fn(event, event2, flags);
+ cache_args = cached_event_types[ast_event_get_type(event)].cache_args;
+
+ for (i = 0; i < ARRAY_LEN(cached_event_types[0].cache_args) && cache_args[i]; i++) {
+ struct ast_event_ie_val ie_val = {
+ .ie_type = cache_args[i],
+ };
+
+ if (!match_ie_val(event, &ie_val, event2)) {
+ res = 0;
+ break;
+ }
+ }
+
+ return res;
}
int ast_event_init(void)
More information about the asterisk-commits
mailing list