mailing list of musl libc
 help / color / mirror / code / Atom feed
b6ec8c5455cabb38997d2ca0c6f0621d922d5889 blob 2240 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
 
#include "pthread_impl.h"

volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX;
void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 };

static void (*volatile keys[PTHREAD_KEYS_MAX])(void *);

static pthread_rwlock_t key_lock = PTHREAD_RWLOCK_INITIALIZER;

static pthread_key_t next_key;

static void nodtor(void *dummy)
{
}

static void dirty(void *dummy)
{
}

static void clean_dirty_tsd(void *dummy)
{
	pthread_t self = __pthread_self();
	pthread_key_t i;
	for (i=0; i<PTHREAD_KEYS_MAX; i++) {
		if (keys[i] == dirty && self->tsd[i])
			self->tsd[i] = 0;
	}
}

int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *))
{
	pthread_key_t j = next_key;
	pthread_t self = __pthread_self();
	int found_dirty = 0;

	/* This can only happen in the main thread before
	 * pthread_create has been called. */
	if (!self->tsd) self->tsd = __pthread_tsd_main;

	if (!dtor) dtor = nodtor;

	pthread_rwlock_wrlock(&key_lock);
	do {
		if (!keys[j]) {
			keys[next_key = *k = j] = dtor;
			pthread_rwlock_unlock(&key_lock);
			return 0;
		} else if (keys[j] == dirty) {
			found_dirty = 1;
		}
	} while ((j=(j+1)%PTHREAD_KEYS_MAX) != next_key);

	if (!found_dirty) {
		pthread_rwlock_unlock(&key_lock);
		return EAGAIN;
	}

	__pthread_key_delete_synccall(clean_dirty_tsd, 0);

	for (j=0; j<PTHREAD_KEYS_MAX; j++) {
		if (keys[j] == dirty) {
			if (dtor) {
				keys[next_key = *k = j] = dtor;
				dtor = 0;
			} else {
				keys[j] = 0;
			}
		}
	}

	pthread_rwlock_unlock(&key_lock);
	return 0;
}

int __pthread_key_delete_impl(pthread_key_t k)
{
	pthread_rwlock_wrlock(&key_lock);
	keys[k] = dirty;
	pthread_rwlock_unlock(&key_lock);
	return 0;
}

void __pthread_tsd_run_dtors()
{
	pthread_t self = __pthread_self();
	int i, j;
	pthread_rwlock_rdlock(&key_lock);
	for (j=0; self->tsd_used && j<PTHREAD_DESTRUCTOR_ITERATIONS; j++) {
		self->tsd_used = 0;
		for (i=0; i<PTHREAD_KEYS_MAX; i++) {
			void *val = self->tsd[i];
			void (*dtor)(void *) = keys[i];
			self->tsd[i] = 0;
			if (val && dtor && dtor != nodtor && dtor != dirty) {
				pthread_rwlock_unlock(&key_lock);
				dtor(val);
				pthread_rwlock_rdlock(&key_lock);
			}
		}
	}
	pthread_rwlock_unlock(&key_lock);
}

weak_alias(__pthread_key_create, pthread_key_create);
debug log:

solving b6ec8c5 ...
found b6ec8c5 in https://inbox.vuxu.org/musl/20180918031807.GS17995@brightrain.aerifal.cx/
found a78e507 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 a78e507a6fc9a9708140e96929a6a572a4e27601	src/thread/pthread_key_create.c

applying [1/1] https://inbox.vuxu.org/musl/20180918031807.GS17995@brightrain.aerifal.cx/
diff --git a/src/thread/pthread_key_create.c b/src/thread/pthread_key_create.c
index a78e507..b6ec8c5 100644

Checking patch src/thread/pthread_key_create.c...
Applied patch src/thread/pthread_key_create.c cleanly.

index at:
100644 b6ec8c5455cabb38997d2ca0c6f0621d922d5889	src/thread/pthread_key_create.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).