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

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

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « fusl/src/thread/powerpc/syscall_cp.s ('k') | fusl/src/thread/pthread_attr_destroy.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <pthread.h>
2 #include "libc.h"
3
4 static struct atfork_funcs {
5 void (*prepare)(void);
6 void (*parent)(void);
7 void (*child)(void);
8 struct atfork_funcs *prev, *next;
9 } *funcs;
10
11 static volatile int lock[2];
12
13 void __fork_handler(int who)
14 {
15 struct atfork_funcs *p;
16 if (!funcs) return;
17 if (who < 0) {
18 LOCK(lock);
19 for (p=funcs; p; p = p->next) {
20 if (p->prepare) p->prepare();
21 funcs = p;
22 }
23 } else {
24 for (p=funcs; p; p = p->prev) {
25 if (!who && p->parent) p->parent();
26 else if (who && p->child) p->child();
27 funcs = p;
28 }
29 UNLOCK(lock);
30 }
31 }
32
33 int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(vo id))
34 {
35 struct atfork_funcs *new = malloc(sizeof *new);
36 if (!new) return -1;
37
38 LOCK(lock);
39 new->next = funcs;
40 new->prev = 0;
41 new->prepare = prepare;
42 new->parent = parent;
43 new->child = child;
44 if (funcs) funcs->prev = new;
45 funcs = new;
46 UNLOCK(lock);
47 return 0;
48 }
OLDNEW
« no previous file with comments | « fusl/src/thread/powerpc/syscall_cp.s ('k') | fusl/src/thread/pthread_attr_destroy.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698