Rizin
unix-like reverse engineering framework and cli tools
main.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <uv.h>

Go to the source code of this file.

Functions

uv_loop_tcreate_loop ()
 
void signal_handler (uv_signal_t *handle, int signum)
 
void thread1_worker (void *userp)
 
void thread2_worker (void *userp)
 
int main ()
 

Function Documentation

◆ create_loop()

uv_loop_t* create_loop ( )

Definition at line 6 of file main.c.

7 {
8  uv_loop_t *loop = malloc(sizeof(uv_loop_t));
9  if (loop) {
11  }
12  return loop;
13 }
void * malloc(size_t size)
Definition: malloc.c:123
Definition: uv.h:1780
uv_loop_t * loop
Definition: main.c:7
UV_EXTERN int uv_loop_init(uv_loop_t *loop)
Definition: loop.c:30

References loop, malloc(), and uv_loop_init().

Referenced by thread1_worker(), and thread2_worker().

◆ main()

int main ( void  )

Definition at line 54 of file main.c.

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 }
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
void thread2_worker(void *userp)
Definition: main.c:37
void thread1_worker(void *userp)
Definition: main.c:22
pthread_t uv_thread_t
Definition: unix.h:136
UV_EXTERN int uv_thread_join(uv_thread_t *tid)
Definition: thread.c:272
UV_EXTERN int uv_thread_create(uv_thread_t *tid, uv_thread_cb entry, void *arg)
Definition: thread.c:210

References printf(), thread1_worker(), thread2_worker(), uv_thread_create(), and uv_thread_join().

◆ signal_handler()

void signal_handler ( uv_signal_t handle,
int  signum 
)

Definition at line 15 of file main.c.

16 {
17  printf("Signal received: %d\n", signum);
19 }
static mcore_handle handle
Definition: asm_mcore.c:8
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
UV_EXTERN int uv_signal_stop(uv_signal_t *handle)
Definition: signal.c:513

References handle, printf(), signum, and uv_signal_stop().

◆ thread1_worker()

void thread1_worker ( void *  userp)

Definition at line 22 of file main.c.

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 }
void signal_handler(uv_signal_t *req, int signum)
Definition: main.c:33
uv_loop_t * create_loop()
Definition: main.c:6
@ UV_RUN_DEFAULT
Definition: uv.h:255
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_run(uv_loop_t *, uv_run_mode mode)
Definition: core.c:365
UV_EXTERN int uv_signal_init(uv_loop_t *loop, uv_signal_t *handle)
Definition: signal.c:319

References create_loop(), signal_handler(), uv_run(), UV_RUN_DEFAULT, uv_signal_init(), and uv_signal_start().

Referenced by main().

◆ thread2_worker()

void thread2_worker ( void *  userp)

Definition at line 37 of file main.c.

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 }
@ UV_RUN_NOWAIT
Definition: uv.h:257

References create_loop(), signal_handler(), uv_run(), UV_RUN_NOWAIT, uv_signal_init(), and uv_signal_start().

Referenced by main().