4 * Userspace RCU library - test program (fork)
6 * Copyright February 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "../config.h"
29 #include <sys/types.h>
37 #include <urcu/arch.h>
38 #include <urcu/tls-compat.h>
40 #ifndef DYNAMIC_LINK_TEST
43 #define rcu_debug_yield_read()
52 static void cb(struct rcu_head
*head
)
54 struct test_node
*node
;
56 fprintf(stderr
, "rcu callback invoked in pid: %d\n",
58 node
= caa_container_of(head
, struct test_node
, head
);
62 static void test_rcu(void)
64 struct test_node
*node
;
66 rcu_register_thread();
73 node
= malloc(sizeof(*node
));
76 call_rcu(&node
->head
, cb
);
80 rcu_unregister_thread();
83 int main(int argc
, char **argv
)
89 /* pthread_atfork does not work with malloc/free in callbacks */
90 ret
= pthread_atfork(call_rcu_before_fork
,
91 call_rcu_after_fork_parent
,
92 call_rcu_after_fork_child
);
95 perror("pthread_atfork");
104 fprintf(stderr
, "%s parent pid: %d, before fork\n",
105 argv
[0], (int) getpid());
107 call_rcu_before_fork();
112 call_rcu_after_fork_child();
113 fprintf(stderr
, "%s child pid: %d, after fork\n",
114 argv
[0], (int) getpid());
116 fprintf(stderr
, "%s child pid: %d, after rcu test\n",
117 argv
[0], (int) getpid());
118 } else if (pid
> 0) {
122 call_rcu_after_fork_parent();
123 fprintf(stderr
, "%s parent pid: %d, after fork\n",
124 argv
[0], (int) getpid());
126 fprintf(stderr
, "%s parent pid: %d, after rcu test\n",
127 argv
[0], (int) getpid());
130 if (WIFEXITED(status
)) {
131 fprintf(stderr
, "child %u exited normally with status %u\n",
132 pid
, WEXITSTATUS(status
));
134 } else if (WIFSIGNALED(status
)) {
135 fprintf(stderr
, "child %u was terminated by signal %u\n",
136 pid
, WTERMSIG(status
));