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.

Macros

#define FIB_UNTIL   25
 

Functions

long fib_ (long t)
 
void fib (uv_work_t *req)
 
void after_fib (uv_work_t *req, int status)
 
void signal_handler (uv_signal_t *req, int signum)
 
int main ()
 

Variables

uv_loop_tloop
 
uv_work_t fib_reqs [FIB_UNTIL]
 

Macro Definition Documentation

◆ FIB_UNTIL

#define FIB_UNTIL   25

Definition at line 7 of file main.c.

Function Documentation

◆ after_fib()

void after_fib ( uv_work_t req,
int  status 
)

Definition at line 28 of file main.c.

28  {
29  if (status == UV_ECANCELED)
30  fprintf(stderr, "Calculation of %d cancelled.\n", *(int *) req->data);
31 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
Definition: sflib.h:128
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145

References req, and status.

Referenced by main().

◆ fib()

void fib ( uv_work_t req)

Definition at line 18 of file main.c.

18  {
19  int n = *(int *) req->data;
20  if (random() % 2)
21  sleep(1);
22  else
23  sleep(3);
24  long fib = fib_(n);
25  fprintf(stderr, "%dth fibonacci is %lu\n", n, fib);
26 }
int n
Definition: mipsasm.c:19
long fib_(long t)
Definition: main.c:11
void fib(uv_work_t *req)
Definition: main.c:18
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References fib_(), if(), n, and req.

Referenced by fib(), and main().

◆ fib_()

long fib_ ( long  t)

Definition at line 11 of file main.c.

11  {
12  if (t == 0 || t == 1)
13  return 1;
14  else
15  return fib_(t-1) + fib_(t-2);
16 }

Referenced by fib(), and fib_().

◆ main()

int main ( void  )

Definition at line 43 of file main.c.

43  {
45 
46  int data[FIB_UNTIL];
47  int i;
48  for (i = 0; i < FIB_UNTIL; i++) {
49  data[i] = i;
50  fib_reqs[i].data = (void *) &data[i];
52  }
53 
54  uv_signal_t sig;
55  uv_signal_init(loop, &sig);
56  uv_signal_start(&sig, signal_handler, SIGINT);
57 
58  return uv_run(loop, UV_RUN_DEFAULT);
59 }
lzma_index ** i
Definition: index.h:629
uv_loop_t * loop
Definition: main.c:7
void signal_handler(uv_signal_t *req, int signum)
Definition: main.c:33
#define FIB_UNTIL
Definition: main.c:7
uv_work_t fib_reqs[FIB_UNTIL]
Definition: main.c:9
void after_fib(uv_work_t *req, int status)
Definition: main.c:28
@ 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_queue_work(uv_loop_t *loop, uv_work_t *req, uv_work_cb work_cb, uv_after_work_cb after_work_cb)
Definition: threadpool.c:338
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:763
UV_EXTERN int uv_signal_init(uv_loop_t *loop, uv_signal_t *handle)
Definition: signal.c:319

References after_fib(), fib(), fib_reqs, FIB_UNTIL, i, loop, signal_handler(), uv_default_loop(), uv_queue_work(), uv_run(), UV_RUN_DEFAULT, uv_signal_init(), and uv_signal_start().

◆ signal_handler()

void signal_handler ( uv_signal_t req,
int  signum 
)

Definition at line 33 of file main.c.

34 {
35  printf("Signal received!\n");
36  int i;
37  for (i = 0; i < FIB_UNTIL; i++) {
39  }
41 }
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
Definition: uv.h:407
UV_EXTERN int uv_signal_stop(uv_signal_t *handle)
Definition: signal.c:513
UV_EXTERN int uv_cancel(uv_req_t *req)
Definition: threadpool.c:358

References fib_reqs, FIB_UNTIL, i, printf(), req, uv_cancel(), and uv_signal_stop().

Referenced by main(), rz_sys_crash_handler(), thread1_worker(), and thread2_worker().

Variable Documentation

◆ fib_reqs

uv_work_t fib_reqs[FIB_UNTIL]

Definition at line 9 of file main.c.

Referenced by main(), and signal_handler().

◆ loop

uv_loop_t* loop

Definition at line 8 of file main.c.