diff options
author | Andrew Zaborowski <andrew.zaborowski@intel.com> | 2020-05-31 02:56:45 +0200 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2020-06-04 09:14:21 -0500 |
commit | 1e10d136459d991bbcd1cd306147fddd9b0bf4a5 (patch) | |
tree | cf319cb59ba2afefa40a4d836b5c887cac8bffdf | |
parent | d012a7f2ac3b494c458f9a50ad0ac001f4095475 (diff) | |
download | iwd-1e10d136459d991bbcd1cd306147fddd9b0bf4a5.tar.gz |
frame-xchg: Use frame_watch_group_match in frame_watch_group_get
-rw-r--r-- | src/frame-xchg.c | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/src/frame-xchg.c b/src/frame-xchg.c index 447119970..f713c07ea 100644 --- a/src/frame-xchg.c +++ b/src/frame-xchg.c @@ -439,21 +439,30 @@ err: return NULL; } -static struct watch_group *frame_watch_group_get(uint64_t wdev_id, uint32_t id) +struct watch_group_match_info { + uint64_t wdev_id; + uint32_t id; +}; + +static bool frame_watch_group_match(const void *a, const void *b) { - const struct l_queue_entry *entry; - struct watch_group *group; + const struct watch_group *group = a; + const struct watch_group_match_info *info = b; - for (entry = l_queue_get_entries(watch_groups); entry; - entry = entry->next) { - group = entry->data; + return group->wdev_id == info->wdev_id && group->id == info->id; +} - if (group->id == id && (id == 0 || group->wdev_id == wdev_id)) - return group; +static struct watch_group *frame_watch_group_get(uint64_t wdev_id, uint32_t id) +{ + struct watch_group_match_info info = { id == 0 ? 0 : wdev_id, id }; + struct watch_group *group = l_queue_find(watch_groups, + frame_watch_group_match, &info); + + if (!group) { + group = frame_watch_group_new(wdev_id, id); + l_queue_push_tail(watch_groups, group); } - group = frame_watch_group_new(wdev_id, id); - l_queue_push_tail(watch_groups, group); return group; } @@ -590,19 +599,6 @@ bool frame_watch_add(uint64_t wdev_id, uint32_t group_id, uint16_t frame_type, return true; } -struct watch_group_match_info { - uint64_t wdev_id; - uint32_t id; -}; - -static bool frame_watch_group_match(const void *a, const void *b) -{ - const struct watch_group *group = a; - const struct watch_group_match_info *info = b; - - return group->wdev_id == info->wdev_id && group->id == info->id; -} - bool frame_watch_group_remove(uint64_t wdev_id, uint32_t group_id) { struct watch_group_match_info info = { wdev_id, group_id }; |