diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-08-23 13:10:43 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-08-23 13:10:43 +0200 |
commit | 380db76552577e0c2d6537dece136003bba5ac3f (patch) | |
tree | d4a24ac632fae7a1a4c1d670fa3497418719e171 | |
parent | bbce483ba0fc2b0aa832c47bfa949481eea3bf98 (diff) | |
download | exchange-380db76552577e0c2d6537dece136003bba5ac3f.tar.gz exchange-380db76552577e0c2d6537dece136003bba5ac3f.zip |
-fix pthread leftover
-rw-r--r-- | src/exchange/taler-exchange-httpd.c | 7 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_wire.c | 58 |
2 files changed, 12 insertions, 53 deletions
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c index 792b73dac..a39e1032c 100644 --- a/src/exchange/taler-exchange-httpd.c +++ b/src/exchange/taler-exchange-httpd.c | |||
@@ -1419,13 +1419,6 @@ run (void *cls, | |||
1419 | return; | 1419 | return; |
1420 | } | 1420 | } |
1421 | if (GNUNET_OK != | 1421 | if (GNUNET_OK != |
1422 | TEH_WIRE_init ()) | ||
1423 | { | ||
1424 | global_ret = EXIT_FAILURE; | ||
1425 | GNUNET_SCHEDULER_shutdown (); | ||
1426 | return; | ||
1427 | } | ||
1428 | if (GNUNET_OK != | ||
1429 | TEH_keys_init ()) | 1422 | TEH_keys_init ()) |
1430 | { | 1423 | { |
1431 | global_ret = EXIT_FAILURE; | 1424 | global_ret = EXIT_FAILURE; |
diff --git a/src/exchange/taler-exchange-httpd_wire.c b/src/exchange/taler-exchange-httpd_wire.c index 7246939d5..d256e3c50 100644 --- a/src/exchange/taler-exchange-httpd_wire.c +++ b/src/exchange/taler-exchange-httpd_wire.c | |||
@@ -28,20 +28,16 @@ | |||
28 | 28 | ||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Thread-local. Contains a pointer to `struct WireStateHandle` or NULL. | 31 | * Stores the latest generation of our wire response. |
32 | * Stores the per-thread latest generation of our wire response. | ||
33 | */ | 32 | */ |
34 | static pthread_key_t wire_state; | 33 | static struct WireStateHandle *wire_state; |
35 | 34 | ||
36 | 35 | ||
37 | /** | 36 | /** |
38 | * Counter incremented whenever we have a reason to re-build the #wire_state | 37 | * Counter incremented whenever we have a reason to re-build the #wire_state |
39 | * because something external changed (in another thread). The counter is | 38 | * because something external changed. |
40 | * manipulated using an atomic update, and thus to ensure that threads notice | ||
41 | * when it changes, the variable MUST be volatile. See #get_wire_state() | ||
42 | * and #TEH_wire_update_state() for uses of this variable. | ||
43 | */ | 39 | */ |
44 | static volatile uint64_t wire_generation; | 40 | static uint64_t wire_generation; |
45 | 41 | ||
46 | 42 | ||
47 | /** | 43 | /** |
@@ -81,36 +77,14 @@ destroy_wire_state (struct WireStateHandle *wsh) | |||
81 | } | 77 | } |
82 | 78 | ||
83 | 79 | ||
84 | /** | ||
85 | * Free memory associated with wire state. Signature | ||
86 | * suitable for pthread_key_create(). | ||
87 | * | ||
88 | * @param[in] cls the `struct WireStateHandle` to destroy | ||
89 | */static void | ||
90 | destroy_wire_state_cb (void *cls) | ||
91 | { | ||
92 | struct WireStateHandle *wsh = cls; | ||
93 | |||
94 | destroy_wire_state (wsh); | ||
95 | } | ||
96 | |||
97 | |||
98 | enum GNUNET_GenericReturnValue | ||
99 | TEH_WIRE_init () | ||
100 | { | ||
101 | if (0 != | ||
102 | pthread_key_create (&wire_state, | ||
103 | &destroy_wire_state_cb)) | ||
104 | return GNUNET_SYSERR; | ||
105 | return GNUNET_OK; | ||
106 | } | ||
107 | |||
108 | |||
109 | void | 80 | void |
110 | TEH_WIRE_done () | 81 | TEH_WIRE_done () |
111 | { | 82 | { |
112 | GNUNET_assert (0 == | 83 | if (NULL != wire_state) |
113 | pthread_key_delete (wire_state)); | 84 | { |
85 | destroy_wire_state (wire_state); | ||
86 | wire_state = NULL; | ||
87 | } | ||
114 | } | 88 | } |
115 | 89 | ||
116 | 90 | ||
@@ -328,8 +302,7 @@ build_wire_state (void) | |||
328 | void | 302 | void |
329 | TEH_wire_update_state (void) | 303 | TEH_wire_update_state (void) |
330 | { | 304 | { |
331 | __sync_fetch_and_add (&wire_generation, | 305 | wire_generation++; |
332 | 1); | ||
333 | } | 306 | } |
334 | 307 | ||
335 | 308 | ||
@@ -345,21 +318,14 @@ get_wire_state (void) | |||
345 | { | 318 | { |
346 | struct WireStateHandle *old_wsh; | 319 | struct WireStateHandle *old_wsh; |
347 | 320 | ||
348 | old_wsh = pthread_getspecific (wire_state); | 321 | old_wsh = wire_state; |
349 | if ( (NULL == old_wsh) || | 322 | if ( (NULL == old_wsh) || |
350 | (old_wsh->wire_generation < wire_generation) ) | 323 | (old_wsh->wire_generation < wire_generation) ) |
351 | { | 324 | { |
352 | struct WireStateHandle *wsh; | 325 | struct WireStateHandle *wsh; |
353 | 326 | ||
354 | wsh = build_wire_state (); | 327 | wsh = build_wire_state (); |
355 | if (0 != pthread_setspecific (wire_state, | 328 | wire_state = wsh; |
356 | wsh)) | ||
357 | { | ||
358 | GNUNET_break (0); | ||
359 | if (NULL != wsh) | ||
360 | destroy_wire_state (wsh); | ||
361 | return NULL; | ||
362 | } | ||
363 | if (NULL != old_wsh) | 329 | if (NULL != old_wsh) |
364 | destroy_wire_state (old_wsh); | 330 | destroy_wire_state (old_wsh); |
365 | return wsh; | 331 | return wsh; |