From c4bc1a8434f2a34840ea6f63064fa998ecfae738 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Sat, 17 Jan 2015 18:07:58 +0100 Subject: bus-proxy: share policy between threads This implements a shared policy cache with read-write locks. We no longer parse the XML policy in each thread. This will allow us to easily implement ReloadConfig(). --- src/bus-proxyd/bus-xml-policy.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/bus-proxyd/bus-xml-policy.h') diff --git a/src/bus-proxyd/bus-xml-policy.h b/src/bus-proxyd/bus-xml-policy.h index 125c84cd6e..762cb663a0 100644 --- a/src/bus-proxyd/bus-xml-policy.h +++ b/src/bus-proxyd/bus-xml-policy.h @@ -22,6 +22,7 @@ ***/ #include +#include #include "list.h" #include "hashmap.h" @@ -75,6 +76,15 @@ typedef struct Policy { Hashmap *group_items; } Policy; +typedef struct SharedPolicy { + pthread_mutex_t lock; + pthread_rwlock_t rwlock; + Policy buffer; + Policy *policy; +} SharedPolicy; + +/* policy */ + int policy_load(Policy *p, char **files); void policy_free(Policy *p); @@ -106,3 +116,15 @@ PolicyItemType policy_item_type_from_string(const char *s) _pure_; const char* policy_item_class_to_string(PolicyItemClass t) _const_; PolicyItemClass policy_item_class_from_string(const char *s) _pure_; + +/* shared policy */ + +int shared_policy_new(SharedPolicy **out); +SharedPolicy *shared_policy_free(SharedPolicy *sp); + +int shared_policy_reload(SharedPolicy *sp, char **configuration); +int shared_policy_preload(SharedPolicy *sp, char **configuration); +Policy *shared_policy_acquire(SharedPolicy *sp); +void shared_policy_release(SharedPolicy *sp, Policy *p); + +DEFINE_TRIVIAL_CLEANUP_FUNC(SharedPolicy*, shared_policy_free); -- cgit v1.2.3-54-g00ecf