summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-11-29 20:45:18 +0200
committerSergey Poznyakoff <gray@gnu.org>2020-11-29 20:45:18 +0200
commit42e0f735b48ab0f05e80eeec335684b25a93c4a3 (patch)
tree08dd50b85225caef48e427d12cf27f12467bab79 /include
parentb28243aff348d58cd27a1f8e8fa066149537a2d0 (diff)
downloadmailutils-42e0f735b48ab0f05e80eeec335684b25a93c4a3.tar.gz
mailutils-42e0f735b48ab0f05e80eeec335684b25a93c4a3.tar.bz2
Optimize the observable interface
A bitmask of all requested event types is stored in the observable structure. When an event is reported, mu_observable_notify first check if the event type bit is set in that bitmap. If so, it starts iterating over observers. That should allow us to avoid the loop in most cases. * include/mailutils/observer.h (mu_observable_wants): New proto. * include/mailutils/sys/observer.h (_mu_observable): New member: types. * libmailutils/base/observer.c (mu_observable_attach): Compute bitmask of all types requested by attached observers. (mu_observable_detach): Likewise. (mu_observable_notify): Check if the event type is marked in the bitmap, skip iteration if it is not. (mu_observable_wants): New function.
Diffstat (limited to 'include')
-rw-r--r--include/mailutils/observer.h2
-rw-r--r--include/mailutils/sys/observer.h1
2 files changed, 3 insertions, 0 deletions
diff --git a/include/mailutils/observer.h b/include/mailutils/observer.h
index b0d62b221..a5779ebaa 100644
--- a/include/mailutils/observer.h
+++ b/include/mailutils/observer.h
@@ -68,6 +68,8 @@ extern int mu_observable_attach (mu_observable_t, size_t type,
mu_observer_t observer);
extern int mu_observable_detach (mu_observable_t, mu_observer_t observer);
extern int mu_observable_notify (mu_observable_t, int type, void *data);
+int mu_observable_wants (mu_observable_t observable, int type);
+
#ifdef __cplusplus
}
diff --git a/include/mailutils/sys/observer.h b/include/mailutils/sys/observer.h
index 74a183043..f6b8c4875 100644
--- a/include/mailutils/sys/observer.h
+++ b/include/mailutils/sys/observer.h
@@ -36,6 +36,7 @@ struct _mu_observer
struct _mu_observable
{
void *owner;
+ size_t types;
mu_list_t list;
};

Return to:

Send suggestions and report system problems to the System administrator.