diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-05-10 20:08:01 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-05-10 20:10:02 +0200 |
commit | c1f06ac28fef5498952994e0399312b1fc567f22 (patch) | |
tree | ad71f80bb08bfe20ff33880509263d78f334409b /src/include | |
parent | d1d18e6492708a0ce758ddd8c509f21b0ecbf6a0 (diff) | |
download | gnunet-c1f06ac28fef5498952994e0399312b1fc567f22.tar.gz gnunet-c1f06ac28fef5498952994e0399312b1fc567f22.zip |
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.
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gnunet_common.h | 64 | ||||
-rw-r--r-- | src/include/gnunet_curl_lib.h | 10 | ||||
-rw-r--r-- | src/include/gnunet_scheduler_lib.h | 20 |
3 files changed, 94 insertions, 0 deletions
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 | |||
319 | /* Followed by data. */ | 319 | /* Followed by data. */ |
320 | }; | 320 | }; |
321 | 321 | ||
322 | |||
323 | /** | ||
324 | * Identifier for an asynchronous execution context. | ||
325 | */ | ||
326 | struct GNUNET_AsyncScopeId | ||
327 | { | ||
328 | uint32_t bits[16 / sizeof (uint32_t)]; /* = 16 bytes */ | ||
329 | }; | ||
330 | |||
322 | GNUNET_NETWORK_STRUCT_END | 331 | GNUNET_NETWORK_STRUCT_END |
323 | 332 | ||
333 | |||
334 | /** | ||
335 | * Saved async scope identifier or root scope. | ||
336 | */ | ||
337 | struct GNUNET_AsyncScopeSave { | ||
338 | /** | ||
339 | * Saved scope. Unused if 'have_scope==GNUNET_NO'. | ||
340 | */ | ||
341 | struct GNUNET_AsyncScopeId scope_id; | ||
342 | |||
343 | /** | ||
344 | * GNUNET_YES unless this saved scope is the unnamed root scope. | ||
345 | */ | ||
346 | int have_scope; | ||
347 | }; | ||
348 | |||
349 | |||
324 | /** | 350 | /** |
325 | * Function called with a filename. | 351 | * Function called with a filename. |
326 | * | 352 | * |
@@ -1331,6 +1357,44 @@ struct GNUNET_MessageHeader * | |||
1331 | GNUNET_copy_message (const struct GNUNET_MessageHeader *msg); | 1357 | GNUNET_copy_message (const struct GNUNET_MessageHeader *msg); |
1332 | 1358 | ||
1333 | 1359 | ||
1360 | /** | ||
1361 | * Set the async scope for the current thread. | ||
1362 | * | ||
1363 | * @param aid the async scope identifier | ||
1364 | * @param old_scope[out] location to save the old scope | ||
1365 | */ | ||
1366 | void | ||
1367 | GNUNET_async_scope_enter (const struct GNUNET_AsyncScopeId *aid, | ||
1368 | struct GNUNET_AsyncScopeSave *old_scope); | ||
1369 | |||
1370 | |||
1371 | /** | ||
1372 | * Clear the current thread's async scope. | ||
1373 | * | ||
1374 | * @param old_scope scope to restore | ||
1375 | */ | ||
1376 | void | ||
1377 | GNUNET_async_scope_restore (struct GNUNET_AsyncScopeSave *old_scope); | ||
1378 | |||
1379 | |||
1380 | /** | ||
1381 | * Get the current async scope. | ||
1382 | * | ||
1383 | * @param[out] scope_ret pointer to where the result is stored | ||
1384 | */ | ||
1385 | void | ||
1386 | GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret); | ||
1387 | |||
1388 | |||
1389 | /** | ||
1390 | * Generate a fresh async scope identifier. | ||
1391 | * | ||
1392 | * @param[out] aid_ret pointer to where the result is stored | ||
1393 | */ | ||
1394 | void | ||
1395 | GNUNET_async_scope_fresh (struct GNUNET_AsyncScopeId *aid_ret); | ||
1396 | |||
1397 | |||
1334 | #if __STDC_VERSION__ < 199901L | 1398 | #if __STDC_VERSION__ < 199901L |
1335 | #if __GNUC__ >= 2 | 1399 | #if __GNUC__ >= 2 |
1336 | #define __func__ __FUNCTION__ | 1400 | #define __func__ __FUNCTION__ |
diff --git a/src/include/gnunet_curl_lib.h b/src/include/gnunet_curl_lib.h index 86cb54f6b..84c8d59f8 100644 --- a/src/include/gnunet_curl_lib.h +++ b/src/include/gnunet_curl_lib.h | |||
@@ -294,6 +294,16 @@ void | |||
294 | GNUNET_CURL_gnunet_scheduler_reschedule (void *cls); | 294 | GNUNET_CURL_gnunet_scheduler_reschedule (void *cls); |
295 | 295 | ||
296 | 296 | ||
297 | /** | ||
298 | * Enable sending the async scope ID as a header. | ||
299 | * | ||
300 | * @param ctx the context to enable this for | ||
301 | * @param header_name name of the header to send. | ||
302 | */ | ||
303 | void | ||
304 | GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, const char *header_name); | ||
305 | |||
306 | |||
297 | #endif | 307 | #endif |
298 | /** @} */ /* end of group */ | 308 | /** @} */ /* end of group */ |
299 | 309 | ||
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h index 3f4e3c9a8..3f0350f54 100644 --- a/src/include/gnunet_scheduler_lib.h +++ b/src/include/gnunet_scheduler_lib.h | |||
@@ -214,6 +214,8 @@ struct GNUNET_SCHEDULER_TaskContext | |||
214 | }; | 214 | }; |
215 | 215 | ||
216 | 216 | ||
217 | |||
218 | |||
217 | /** | 219 | /** |
218 | * Function used by event-loop implementations to signal the scheduler | 220 | * Function used by event-loop implementations to signal the scheduler |
219 | * that a particular @a task is ready due to an event specified in the | 221 | * that a particular @a task is ready due to an event specified in the |
@@ -904,6 +906,24 @@ GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select, | |||
904 | void *new_select_cls); | 906 | void *new_select_cls); |
905 | 907 | ||
906 | 908 | ||
909 | |||
910 | /** | ||
911 | * Change the async scope for the currently executing task and (transitively) | ||
912 | * for all tasks scheduled by the current task after calling this function. | ||
913 | * Nested tasks can begin their own nested async scope. | ||
914 | * | ||
915 | * Once the current task is finished, the async scope ID is reset to | ||
916 | * its previous value. | ||
917 | * | ||
918 | * Must only be called from a running task. | ||
919 | * | ||
920 | * @param aid the asynchronous scope id to enter | ||
921 | */ | ||
922 | void | ||
923 | GNUNET_SCHEDULER_begin_async_scope (struct GNUNET_AsyncScopeId *aid); | ||
924 | |||
925 | |||
926 | |||
907 | #if 0 /* keep Emacsens' auto-indent happy */ | 927 | #if 0 /* keep Emacsens' auto-indent happy */ |
908 | { | 928 | { |
909 | #endif | 929 | #endif |