Rizin
unix-like reverse engineering framework and cli tools
main.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <uv.h>
5 
7 {
8  uv_loop_t *loop = malloc(sizeof(uv_loop_t));
9  if (loop) {
11  }
12  return loop;
13 }
14 
16 {
17  printf("Signal received: %d\n", signum);
19 }
20 
21 // two signal handlers in one loop
22 void thread1_worker(void *userp)
23 {
24  uv_loop_t *loop1 = create_loop();
25 
26  uv_signal_t sig1a, sig1b;
27  uv_signal_init(loop1, &sig1a);
28  uv_signal_start(&sig1a, signal_handler, SIGUSR1);
29 
30  uv_signal_init(loop1, &sig1b);
31  uv_signal_start(&sig1b, signal_handler, SIGUSR1);
32 
33  uv_run(loop1, UV_RUN_DEFAULT);
34 }
35 
36 // two signal handlers, each in its own loop
37 void thread2_worker(void *userp)
38 {
39  uv_loop_t *loop2 = create_loop();
40  uv_loop_t *loop3 = create_loop();
41 
42  uv_signal_t sig2;
43  uv_signal_init(loop2, &sig2);
44  uv_signal_start(&sig2, signal_handler, SIGUSR1);
45 
46  uv_signal_t sig3;
47  uv_signal_init(loop3, &sig3);
48  uv_signal_start(&sig3, signal_handler, SIGUSR1);
49 
50  while (uv_run(loop2, UV_RUN_NOWAIT) || uv_run(loop3, UV_RUN_NOWAIT)) {
51  }
52 }
53 
54 int main()
55 {
56  printf("PID %d\n", getpid());
57 
58  uv_thread_t thread1, thread2;
59 
60  uv_thread_create(&thread1, thread1_worker, 0);
61  uv_thread_create(&thread2, thread2_worker, 0);
62 
63  uv_thread_join(&thread1);
64  uv_thread_join(&thread2);
65  return 0;
66 }
static mcore_handle handle
Definition: asm_mcore.c:8
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
int main(int argc, const char **argv)
Definition: main.c:340
void * malloc(size_t size)
Definition: malloc.c:123
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment signum
Definition: sflib.h:79
Definition: uv.h:1780
uv_loop_t * loop
Definition: main.c:7
void signal_handler(uv_signal_t *req, int signum)
Definition: main.c:33
void thread2_worker(void *userp)
Definition: main.c:37
uv_loop_t * create_loop()
Definition: main.c:6
void thread1_worker(void *userp)
Definition: main.c:22
pthread_t uv_thread_t
Definition: unix.h:136
@ UV_RUN_NOWAIT
Definition: uv.h:257
@ UV_RUN_DEFAULT
Definition: uv.h:255
UV_EXTERN int uv_thread_join(uv_thread_t *tid)
Definition: thread.c:272
UV_EXTERN int uv_signal_start(uv_signal_t *handle, uv_signal_cb signal_cb, int signum)
Definition: signal.c:340
UV_EXTERN int uv_loop_init(uv_loop_t *loop)
Definition: loop.c:30
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: core.c:365
UV_EXTERN int uv_signal_stop(uv_signal_t *handle)
Definition: signal.c:513
UV_EXTERN int uv_thread_create(uv_thread_t *tid, uv_thread_cb entry, void *arg)
Definition: thread.c:210
UV_EXTERN int uv_signal_init(uv_loop_t *loop, uv_signal_t *handle)
Definition: signal.c:319