Commit 8d50a81b authored by Pekka Pessi's avatar Pekka Pessi

su_wait.h: added su_root_clone()

darcs-hash:20090203163133-db55f-b52361c8a09b810201f5741e95f57549ad51b1f1.gz
parent 78a8d6cc
......@@ -487,6 +487,9 @@ SOFIAPUBFUN int su_root_has_thread(su_root_t *root);
SOFIAPUBFUN int su_root_set_max_defer(su_root_t *, su_duration_t max_defer);
SOFIAPUBFUN su_duration_t su_root_get_max_defer(su_root_t const *self);
SOFIAPUBFUN su_root_t *su_root_clone(su_root_t *root, su_root_magic_t *magic)
__attribute__((__malloc__));
/* Timers */
SOFIAPUBFUN su_timer_t *su_timer_create(su_task_r const, su_duration_t msec)
__attribute__((__malloc__));
......
......@@ -409,6 +409,48 @@ su_root_t *su_root_create(su_root_magic_t *magic)
return su_root_create_with_port(magic, su_port_create());
}
/* Initializer used by su_root_clone() */
static int
su_root_clone_initializer(su_root_t *root,
su_root_magic_t *magic)
{
*(su_root_t **)magic = root;
return 0;
}
/** Create a a new root object sharing port/thread with existing one.
*
* Allocate and initialize the instance of su_root_t.
*
* @param magic pointer to user data
*
* @return A pointer to allocated su_root_t instance, NULL on error.
*
* @NEW_1_12_11
*/
su_root_t *
su_root_clone(su_root_t *self, su_root_magic_t *magic)
{
int threading = 0, error;
su_clone_r clone;
su_root_t *cloned = NULL;
if (self == NULL)
return NULL;
threading = self->sur_threading, self->sur_threading = 0;
error = su_clone_start(self, clone,
(void *)&cloned, su_root_clone_initializer, NULL);
self->sur_threading = threading;
if (error)
return NULL;
su_clone_forget(clone); /* destroyed with su_root_destroy() */
su_root_set_magic(cloned, magic);
return cloned;
}
/**@internal
*
* Create a reactor object using given message port.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment