[sr-dev] git:master: cfg framework: support for no per-child callbacks procs

Miklos Tirpak miklos at iptel.org
Wed Sep 30 09:26:46 CEST 2009


Module: sip-router
Branch: master
Commit: 4a9a969de84eef3aac616d49ec02c25aceff2a68
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=4a9a969de84eef3aac616d49ec02c25aceff2a68

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Miklos Tirpak <miklos at iptel.org>
Date:   Tue Sep 29 17:18:37 2009 +0200

cfg framework: support for no per-child callbacks procs

Support for using the config framework from processes that
cannot or do not need to execute cfg per-child callbacks.
For example a process that only monitors some cfg values that do
not involve per-child callbacks, does not ever need to execute
one.

Signed-off-by: Miklos Tirpak <miklos at iptel.org>

---

 cfg/cfg_struct.c |   18 +++++++++++++++++-
 cfg/cfg_struct.h |   16 ++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/cfg/cfg_struct.c b/cfg/cfg_struct.c
index ad613ee..c204573 100644
--- a/cfg/cfg_struct.c
+++ b/cfg/cfg_struct.c
@@ -418,6 +418,22 @@ int cfg_late_child_init(void)
 	return 0;
 }
 
+
+/* per-child init function for non-cb executing processes.
+ * Mark this process as not wanting to execute any per-child config
+ * callback (it will have only limited config functionality, but is useful
+ * when a process needs only to watch some non-callback cfg. values,
+ * e.g. the main attendant process, debug and memlog).
+ * It needs to be called from the forked process.
+ * cfg_register_child must _not_ be called.
+ */
+int cfg_child_no_cb_init(void)
+{
+	/* set the callback list pointer to the beginning of the list */
+	cfg_child_cb = CFG_NO_CHILD_CBS;
+	return 0;
+}
+
 /* per-child process destroy function
  * Should be called only when the child process exits,
  * but SER continues running
@@ -436,7 +452,7 @@ void cfg_child_destroy(void)
 		cfg_local = NULL;
 	}
 
-	if (!cfg_child_cb) return;
+	if (!cfg_child_cb || cfg_child_cb==CFG_NO_CHILD_CBS) return;
 
 	/* The lock must be held to make sure that the global config
 	is not replaced meantime, and the other child processes do not
diff --git a/cfg/cfg_struct.h b/cfg/cfg_struct.h
index e7ac4e3..0eafc51 100644
--- a/cfg/cfg_struct.h
+++ b/cfg/cfg_struct.h
@@ -120,6 +120,10 @@ extern cfg_child_cb_t	**cfg_child_cb_first;
 extern cfg_child_cb_t	**cfg_child_cb_last;
 extern cfg_child_cb_t	*cfg_child_cb;
 
+/* magic value for cfg_child_cb for processes that do not want to
+   execute per-child callbacks */
+#define CFG_NO_CHILD_CBS ((void*)(long)(-1))
+
 /* macros for easier variable access */
 #define CFG_VAR_TYPE(var)	CFG_VAR_MASK((var)->def->type)
 #define CFG_INPUT_TYPE(var)	CFG_INPUT_MASK((var)->def->type)
@@ -149,6 +153,16 @@ int cfg_child_init(void);
  */
 int cfg_late_child_init(void);
 
+/* per-child init function for non-cb executing processes.
+ * Mark this process as not wanting to execute any per-child config
+ * callback (it will have only limited config functionality, but is useful
+ * when a process needs only to watch some non-callback cfg. values,
+ * e.g. the main attendant process, debug and memlog).
+ * It needs to be called from the forked process.
+ * cfg_register_child must _not_ be called.
+ */
+int cfg_child_no_cb_init(void);
+
 /* per-child process destroy function
  * Should be called only when the child process exits,
  * but SER continues running.
@@ -233,6 +247,8 @@ static inline void cfg_update_local(void)
 	)
 		*(group->handle) = cfg_local->vars + group->offset;
 
+	if (unlikely(cfg_child_cb==CFG_NO_CHILD_CBS))
+		return;
 	/* call the per-process callbacks */
 	while (cfg_child_cb != last_cb) {
 		prev_cb = cfg_child_cb;




More information about the sr-dev mailing list