From c1f06ac28fef5498952994e0399312b1fc567f22 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 10 May 2019 20:08:01 +0200 Subject: Implement asynchronous scope identifiers. Without entering an asynchronous scope, logs are the same before. When entering an asynchronous scope (either thread-based of scheduler/task-based), all log lines within an asynchronous scope contain its ID. Currently this is only used in GNU Taler, for debugging requests across multiple services. This allows us to get all log lines pertaining to a particular request for a user or another service. --- src/include/gnunet_common.h | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'src/include/gnunet_common.h') diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 2c40aef79..1f5600381 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -319,8 +319,34 @@ struct GNUNET_OperationResultMessage /* Followed by data. */ }; + +/** + * Identifier for an asynchronous execution context. + */ +struct GNUNET_AsyncScopeId +{ + uint32_t bits[16 / sizeof (uint32_t)]; /* = 16 bytes */ +}; + GNUNET_NETWORK_STRUCT_END + +/** + * Saved async scope identifier or root scope. + */ +struct GNUNET_AsyncScopeSave { + /** + * Saved scope. Unused if 'have_scope==GNUNET_NO'. + */ + struct GNUNET_AsyncScopeId scope_id; + + /** + * GNUNET_YES unless this saved scope is the unnamed root scope. + */ + int have_scope; +}; + + /** * Function called with a filename. * @@ -1331,6 +1357,44 @@ struct GNUNET_MessageHeader * GNUNET_copy_message (const struct GNUNET_MessageHeader *msg); +/** + * Set the async scope for the current thread. + * + * @param aid the async scope identifier + * @param old_scope[out] location to save the old scope + */ +void +GNUNET_async_scope_enter (const struct GNUNET_AsyncScopeId *aid, + struct GNUNET_AsyncScopeSave *old_scope); + + +/** + * Clear the current thread's async scope. + * + * @param old_scope scope to restore + */ +void +GNUNET_async_scope_restore (struct GNUNET_AsyncScopeSave *old_scope); + + +/** + * Get the current async scope. + * + * @param[out] scope_ret pointer to where the result is stored + */ +void +GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret); + + +/** + * Generate a fresh async scope identifier. + * + * @param[out] aid_ret pointer to where the result is stored + */ +void +GNUNET_async_scope_fresh (struct GNUNET_AsyncScopeId *aid_ret); + + #if __STDC_VERSION__ < 199901L #if __GNUC__ >= 2 #define __func__ __FUNCTION__ -- cgit v1.2.3