Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: fusl/src/thread/pthread_key_create.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "pthread_impl.h" 1 #include "pthread_impl.h"
2 2
3 volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX; 3 volatile size_t __pthread_tsd_size = sizeof(void*) * PTHREAD_KEYS_MAX;
4 void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 }; 4 void* __pthread_tsd_main[PTHREAD_KEYS_MAX] = {0};
5 5
6 static void (*volatile keys[PTHREAD_KEYS_MAX])(void *); 6 static void (*volatile keys[PTHREAD_KEYS_MAX])(void*);
7 7
8 static void nodtor(void *dummy) 8 static void nodtor(void* dummy) {}
9 { 9
10 int __pthread_key_create(pthread_key_t* k, void (*dtor)(void*)) {
11 unsigned i = (uintptr_t)&k / 16 % PTHREAD_KEYS_MAX;
12 unsigned j = i;
13 pthread_t self = __pthread_self();
14
15 /* This can only happen in the main thread before
16 * pthread_create has been called. */
17 if (!self->tsd)
18 self->tsd = __pthread_tsd_main;
19
20 if (!dtor)
21 dtor = nodtor;
22 do {
23 if (!a_cas_p(keys + j, 0, (void*)dtor)) {
24 *k = j;
25 return 0;
26 }
27 } while ((j = (j + 1) % PTHREAD_KEYS_MAX) != i);
28 return EAGAIN;
10 } 29 }
11 30
12 int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) 31 int __pthread_key_delete(pthread_key_t k) {
13 { 32 keys[k] = 0;
14 » unsigned i = (uintptr_t)&k / 16 % PTHREAD_KEYS_MAX; 33 return 0;
15 » unsigned j = i;
16 » pthread_t self = __pthread_self();
17
18 » /* This can only happen in the main thread before
19 » * pthread_create has been called. */
20 » if (!self->tsd) self->tsd = __pthread_tsd_main;
21
22 » if (!dtor) dtor = nodtor;
23 » do {
24 » » if (!a_cas_p(keys+j, 0, (void *)dtor)) {
25 » » » *k = j;
26 » » » return 0;
27 » » }
28 » } while ((j=(j+1)%PTHREAD_KEYS_MAX) != i);
29 » return EAGAIN;
30 } 34 }
31 35
32 int __pthread_key_delete(pthread_key_t k) 36 void __pthread_tsd_run_dtors() {
33 { 37 pthread_t self = __pthread_self();
34 » keys[k] = 0; 38 int i, j, not_finished = self->tsd_used;
35 » return 0; 39 for (j = 0; not_finished && j < PTHREAD_DESTRUCTOR_ITERATIONS; j++) {
36 } 40 not_finished = 0;
37 41 for (i = 0; i < PTHREAD_KEYS_MAX; i++) {
38 void __pthread_tsd_run_dtors() 42 if (self->tsd[i] && keys[i]) {
39 { 43 void* tmp = self->tsd[i];
40 » pthread_t self = __pthread_self(); 44 self->tsd[i] = 0;
41 » int i, j, not_finished = self->tsd_used; 45 keys[i](tmp);
42 » for (j=0; not_finished && j<PTHREAD_DESTRUCTOR_ITERATIONS; j++) { 46 not_finished = 1;
43 » » not_finished = 0; 47 }
44 » » for (i=0; i<PTHREAD_KEYS_MAX; i++) { 48 }
45 » » » if (self->tsd[i] && keys[i]) { 49 }
46 » » » » void *tmp = self->tsd[i];
47 » » » » self->tsd[i] = 0;
48 » » » » keys[i](tmp);
49 » » » » not_finished = 1;
50 » » » }
51 » » }
52 » }
53 } 50 }
54 51
55 weak_alias(__pthread_key_delete, pthread_key_delete); 52 weak_alias(__pthread_key_delete, pthread_key_delete);
56 weak_alias(__pthread_key_create, pthread_key_create); 53 weak_alias(__pthread_key_create, pthread_key_create);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698