-fix pthread leftover
This commit is contained in:
parent
bbce483ba0
commit
380db76552
@ -1418,13 +1418,6 @@ run (void *cls,
|
|||||||
GNUNET_SCHEDULER_shutdown ();
|
GNUNET_SCHEDULER_shutdown ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (GNUNET_OK !=
|
|
||||||
TEH_WIRE_init ())
|
|
||||||
{
|
|
||||||
global_ret = EXIT_FAILURE;
|
|
||||||
GNUNET_SCHEDULER_shutdown ();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TEH_keys_init ())
|
TEH_keys_init ())
|
||||||
{
|
{
|
||||||
|
@ -28,20 +28,16 @@
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread-local. Contains a pointer to `struct WireStateHandle` or NULL.
|
* Stores the latest generation of our wire response.
|
||||||
* Stores the per-thread latest generation of our wire response.
|
|
||||||
*/
|
*/
|
||||||
static pthread_key_t wire_state;
|
static struct WireStateHandle *wire_state;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counter incremented whenever we have a reason to re-build the #wire_state
|
* Counter incremented whenever we have a reason to re-build the #wire_state
|
||||||
* because something external changed (in another thread). The counter is
|
* because something external changed.
|
||||||
* manipulated using an atomic update, and thus to ensure that threads notice
|
|
||||||
* when it changes, the variable MUST be volatile. See #get_wire_state()
|
|
||||||
* and #TEH_wire_update_state() for uses of this variable.
|
|
||||||
*/
|
*/
|
||||||
static volatile uint64_t wire_generation;
|
static uint64_t wire_generation;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,36 +77,14 @@ destroy_wire_state (struct WireStateHandle *wsh)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Free memory associated with wire state. Signature
|
|
||||||
* suitable for pthread_key_create().
|
|
||||||
*
|
|
||||||
* @param[in] cls the `struct WireStateHandle` to destroy
|
|
||||||
*/static void
|
|
||||||
destroy_wire_state_cb (void *cls)
|
|
||||||
{
|
|
||||||
struct WireStateHandle *wsh = cls;
|
|
||||||
|
|
||||||
destroy_wire_state (wsh);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
enum GNUNET_GenericReturnValue
|
|
||||||
TEH_WIRE_init ()
|
|
||||||
{
|
|
||||||
if (0 !=
|
|
||||||
pthread_key_create (&wire_state,
|
|
||||||
&destroy_wire_state_cb))
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
return GNUNET_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TEH_WIRE_done ()
|
TEH_WIRE_done ()
|
||||||
{
|
{
|
||||||
GNUNET_assert (0 ==
|
if (NULL != wire_state)
|
||||||
pthread_key_delete (wire_state));
|
{
|
||||||
|
destroy_wire_state (wire_state);
|
||||||
|
wire_state = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -328,8 +302,7 @@ build_wire_state (void)
|
|||||||
void
|
void
|
||||||
TEH_wire_update_state (void)
|
TEH_wire_update_state (void)
|
||||||
{
|
{
|
||||||
__sync_fetch_and_add (&wire_generation,
|
wire_generation++;
|
||||||
1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -345,21 +318,14 @@ get_wire_state (void)
|
|||||||
{
|
{
|
||||||
struct WireStateHandle *old_wsh;
|
struct WireStateHandle *old_wsh;
|
||||||
|
|
||||||
old_wsh = pthread_getspecific (wire_state);
|
old_wsh = wire_state;
|
||||||
if ( (NULL == old_wsh) ||
|
if ( (NULL == old_wsh) ||
|
||||||
(old_wsh->wire_generation < wire_generation) )
|
(old_wsh->wire_generation < wire_generation) )
|
||||||
{
|
{
|
||||||
struct WireStateHandle *wsh;
|
struct WireStateHandle *wsh;
|
||||||
|
|
||||||
wsh = build_wire_state ();
|
wsh = build_wire_state ();
|
||||||
if (0 != pthread_setspecific (wire_state,
|
wire_state = wsh;
|
||||||
wsh))
|
|
||||||
{
|
|
||||||
GNUNET_break (0);
|
|
||||||
if (NULL != wsh)
|
|
||||||
destroy_wire_state (wsh);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (NULL != old_wsh)
|
if (NULL != old_wsh)
|
||||||
destroy_wire_state (old_wsh);
|
destroy_wire_state (old_wsh);
|
||||||
return wsh;
|
return wsh;
|
||||||
|
Loading…
Reference in New Issue
Block a user