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>
39 #ifndef DYNAMIC_LINK_TEST
42 #define rcu_debug_yield_read()
51 static void cb(struct rcu_head
*head
)
53 struct test_node
*node
;
55 fprintf(stderr
, "rcu callback invoked in pid: %d\n",
57 node
= caa_container_of(head
, struct test_node
, head
);
61 static void test_rcu(void)
63 struct test_node
*node
;
65 rcu_register_thread();
72 node
= malloc(sizeof(*node
));
75 call_rcu(&node
->head
, cb
);
79 rcu_unregister_thread();
82 int main(int argc
, char **argv
)
88 /* pthread_atfork does not work with malloc/free in callbacks */
89 ret
= pthread_atfork(call_rcu_before_fork
,
90 call_rcu_after_fork_parent
,
91 call_rcu_after_fork_child
);
94 perror("pthread_atfork");
103 fprintf(stderr
, "%s parent pid: %d, before fork\n",
104 argv
[0], (int) getpid());
106 call_rcu_before_fork();
111 call_rcu_after_fork_child();
112 fprintf(stderr
, "%s child pid: %d, after fork\n",
113 argv
[0], (int) getpid());
115 fprintf(stderr
, "%s child pid: %d, after rcu test\n",
116 argv
[0], (int) getpid());
117 } else if (pid
> 0) {
121 call_rcu_after_fork_parent();
122 fprintf(stderr
, "%s parent pid: %d, after fork\n",
123 argv
[0], (int) getpid());
125 fprintf(stderr
, "%s parent pid: %d, after rcu test\n",
126 argv
[0], (int) getpid());
129 if (WIFEXITED(status
)) {
130 fprintf(stderr
, "child %u exited normally with status %u\n",
131 pid
, WEXITSTATUS(status
));
133 } else if (WIFSIGNALED(status
)) {
134 fprintf(stderr
, "child %u was terminated by signal %u\n",
135 pid
, WTERMSIG(status
));