diff --git a/lib/isc/trampoline.c b/lib/isc/trampoline.c index 5d0429dfe9..e254aea411 100644 --- a/lib/isc/trampoline.c +++ b/lib/isc/trampoline.c @@ -143,8 +143,8 @@ done: return (trampoline); } -static void -trampoline_put(isc__trampoline_t *trampoline) { +void +isc__trampoline_detach(isc__trampoline_t *trampoline) { LOCK(&isc__trampoline_lock); REQUIRE(trampoline->tid > 0 && (size_t)trampoline->tid < isc__trampoline_max); @@ -163,11 +163,8 @@ trampoline_put(isc__trampoline_t *trampoline) { return; } -isc_threadresult_t -isc__trampoline_run(isc_threadarg_t arg) { - isc__trampoline_t *trampoline = (isc__trampoline_t *)arg; - isc_threadresult_t result; - +void +isc__trampoline_attach(isc__trampoline_t *trampoline) { REQUIRE(trampoline->tid > 0 && (size_t)trampoline->tid < isc__trampoline_max); REQUIRE(trampoline->self == ISC__TRAMPOLINE_UNUSED); @@ -175,11 +172,19 @@ isc__trampoline_run(isc_threadarg_t arg) { /* Initialize the trampoline */ isc_tid_v = trampoline->tid; trampoline->self = isc_thread_self(); +} + +isc_threadresult_t +isc__trampoline_run(isc_threadarg_t arg) { + isc__trampoline_t *trampoline = (isc__trampoline_t *)arg; + isc_threadresult_t result; + + isc__trampoline_attach(trampoline); /* Run the main function */ result = (trampoline->start)(trampoline->arg); - trampoline_put(trampoline); + isc__trampoline_detach(trampoline); return (result); } diff --git a/lib/isc/trampoline_p.h b/lib/isc/trampoline_p.h index 0543ce67f3..cfd9c948d8 100644 --- a/lib/isc/trampoline_p.h +++ b/lib/isc/trampoline_p.h @@ -63,6 +63,17 @@ isc__trampoline_get(isc_threadfunc_t start_routine, isc_threadarg_t arg); *\li 'start_routine' is a valid non-NULL thread start_routine */ +void +isc__trampoline_attach(isc__trampoline_t *trampoline); +void +isc__trampoline_detach(isc__trampoline_t *trampoline); +/*%< + * Attach/detach the trampoline to/from the current thread. + * + * Requires: + * \li 'trampoline' is a valid isc__trampoline_t + */ + isc_threadresult_t isc__trampoline_run(isc_threadarg_t arg); /*%<