Rizin
unix-like reverse engineering framework and cli tools
loop.c File Reference
#include "uv.h"
#include "uv/tree.h"
#include "internal.h"
#include "heap-inl.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

Go to the source code of this file.

Functions

int uv_loop_init (uv_loop_t *loop)
 
int uv_loop_fork (uv_loop_t *loop)
 
void uv__loop_close (uv_loop_t *loop)
 
int uv__loop_configure (uv_loop_t *loop, uv_loop_option option, va_list ap)
 

Function Documentation

◆ uv__loop_close()

void uv__loop_close ( uv_loop_t loop)

Definition at line 165 of file loop.c.

165  {
167 
171 
172  if (loop->emfile_fd != -1) {
173  uv__close(loop->emfile_fd);
174  loop->emfile_fd = -1;
175  }
176 
177  if (loop->backend_fd != -1) {
178  uv__close(loop->backend_fd);
179  loop->backend_fd = -1;
180  }
181 
182  uv_mutex_lock(&loop->wq_mutex);
183  assert(QUEUE_EMPTY(&loop->wq) && "thread pool work queue not empty!");
185  uv_mutex_unlock(&loop->wq_mutex);
186  uv_mutex_destroy(&loop->wq_mutex);
187 
188  /*
189  * Note that all thread pool stuff is finished at this point and
190  * it is safe to just destroy rw lock
191  */
192  uv_rwlock_destroy(&loop->cloexec_lock);
193 
194 #if 0
195  assert(QUEUE_EMPTY(&loop->pending_queue));
196  assert(QUEUE_EMPTY(&loop->watcher_queue));
197  assert(loop->nfds == 0);
198 #endif
199 
200  uv__free(loop->watchers);
201  loop->watchers = NULL;
202  loop->nwatchers = 0;
203 
204  lfields = uv__get_internal_fields(loop);
206  uv__free(lfields);
208 }
void uv__platform_loop_delete(uv_loop_t *loop)
Definition: aix.c:95
#define NULL
Definition: cris-opc.c:27
assert(limit<=UINT32_MAX/2)
#define QUEUE_EMPTY(q)
Definition: queue.h:39
uv__loop_metrics_t loop_metrics
Definition: uv-common.h:365
uv_mutex_t lock
Definition: uv-common.h:357
void * internal_fields
Definition: uv.h:1791
uv_loop_t * loop
Definition: main.c:7
int uv__close(int fd)
Definition: core.c:569
void uv__signal_loop_cleanup(uv_loop_t *loop)
Definition: signal.c:291
void uv__async_stop(uv_loop_t *loop)
Definition: async.c:240
void uv__free(void *ptr)
Definition: uv-common.c:81
#define uv__has_active_reqs(loop)
Definition: uv-common.h:221
#define uv__get_internal_fields(loop)
Definition: uv-common.h:336
UV_EXTERN void uv_mutex_lock(uv_mutex_t *handle)
Definition: thread.c:330
UV_EXTERN void uv_mutex_destroy(uv_mutex_t *handle)
Definition: thread.c:324
UV_EXTERN void uv_mutex_unlock(uv_mutex_t *handle)
Definition: thread.c:350
UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t *rwlock)
Definition: thread.c:361

References assert(), uv_loop_s::internal_fields, uv__loop_metrics_s::lock, loop, uv__loop_internal_fields_s::loop_metrics, NULL, QUEUE_EMPTY, uv__async_stop(), uv__close(), uv__free(), uv__get_internal_fields, uv__has_active_reqs, uv__platform_loop_delete(), uv__signal_loop_cleanup(), uv_mutex_destroy(), uv_mutex_lock(), uv_mutex_unlock(), and uv_rwlock_destroy().

Referenced by uv_loop_close().

◆ uv__loop_configure()

int uv__loop_configure ( uv_loop_t loop,
uv_loop_option  option,
va_list  ap 
)

Definition at line 211 of file loop.c.

211  {
213 
214  lfields = uv__get_internal_fields(loop);
215  if (option == UV_METRICS_IDLE_TIME) {
216  lfields->flags |= UV_METRICS_IDLE_TIME;
217  return 0;
218  }
219 
221  return UV_ENOSYS;
222 
223  if (va_arg(ap, int) != SIGPROF)
224  return UV_EINVAL;
225 
226  loop->flags |= UV_LOOP_BLOCK_SIGPROF;
227  return 0;
228 }
Definition: getopt.h:84
@ UV_LOOP_BLOCK_SIGPROF
Definition: internal.h:137
@ UV_LOOP_BLOCK_SIGNAL
Definition: uv.h:250
@ UV_METRICS_IDLE_TIME
Definition: uv.h:251

References uv__loop_internal_fields_s::flags, loop, uv__get_internal_fields, UV_LOOP_BLOCK_SIGNAL, UV_LOOP_BLOCK_SIGPROF, and UV_METRICS_IDLE_TIME.

Referenced by uv_loop_configure().

◆ uv_loop_fork()

int uv_loop_fork ( uv_loop_t loop)

Definition at line 132 of file loop.c.

132  {
133  int err;
134  unsigned int i;
135  uv__io_t* w;
136 
137  err = uv__io_fork(loop);
138  if (err)
139  return err;
140 
142  if (err)
143  return err;
144 
146  if (err)
147  return err;
148 
149  /* Rearm all the watchers that aren't re-queued by the above. */
150  for (i = 0; i < loop->nwatchers; i++) {
151  w = loop->watchers[i];
152  if (w == NULL)
153  continue;
154 
155  if (w->pevents != 0 && QUEUE_EMPTY(&w->watcher_queue)) {
156  w->events = 0; /* Force re-registration in uv__io_poll. */
157  QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
158  }
159  }
160 
161  return 0;
162 }
int uv__io_fork(uv_loop_t *loop)
Definition: aix.c:108
lzma_index ** i
Definition: index.h:629
static bool err
Definition: armass.c:435
#define w
Definition: crypto_rc6.c:13
#define QUEUE_INSERT_TAIL(h, q)
Definition: queue.h:92
Definition: unix.h:96
int uv__signal_loop_fork(uv_loop_t *loop)
Definition: signal.c:281
int uv__async_fork(uv_loop_t *loop)
Definition: async.c:230

◆ uv_loop_init()

int uv_loop_init ( uv_loop_t loop)

Definition at line 30 of file loop.c.

30  {
32  void* saved_data;
33  int err;
34 
35 
36  saved_data = loop->data;
37  memset(loop, 0, sizeof(*loop));
38  loop->data = saved_data;
39 
40  lfields = (uv__loop_internal_fields_t*) uv__calloc(1, sizeof(*lfields));
41  if (lfields == NULL)
42  return UV_ENOMEM;
43  loop->internal_fields = lfields;
44 
45  err = uv_mutex_init(&lfields->loop_metrics.lock);
46  if (err)
47  goto fail_metrics_mutex_init;
48 
49  heap_init((struct heap*) &loop->timer_heap);
50  QUEUE_INIT(&loop->wq);
51  QUEUE_INIT(&loop->idle_handles);
52  QUEUE_INIT(&loop->async_handles);
53  QUEUE_INIT(&loop->check_handles);
54  QUEUE_INIT(&loop->prepare_handles);
56 
57  loop->active_handles = 0;
58  loop->active_reqs.count = 0;
59  loop->nfds = 0;
60  loop->watchers = NULL;
61  loop->nwatchers = 0;
62  QUEUE_INIT(&loop->pending_queue);
63  QUEUE_INIT(&loop->watcher_queue);
64 
65  loop->closing_handles = NULL;
66  uv__update_time(loop);
67  loop->async_io_watcher.fd = -1;
68  loop->async_wfd = -1;
69  loop->signal_pipefd[0] = -1;
70  loop->signal_pipefd[1] = -1;
71  loop->backend_fd = -1;
72  loop->emfile_fd = -1;
73 
74  loop->timer_counter = 0;
75  loop->stop_flag = 0;
76 
78  if (err)
79  goto fail_platform_init;
80 
82  err = uv_signal_init(loop, &loop->child_watcher);
83  if (err)
84  goto fail_signal_init;
85 
86  uv__handle_unref(&loop->child_watcher);
87  loop->child_watcher.flags |= UV_HANDLE_INTERNAL;
88  QUEUE_INIT(&loop->process_handles);
89 
90  err = uv_rwlock_init(&loop->cloexec_lock);
91  if (err)
92  goto fail_rwlock_init;
93 
94  err = uv_mutex_init(&loop->wq_mutex);
95  if (err)
96  goto fail_mutex_init;
97 
98  err = uv_async_init(loop, &loop->wq_async, uv__work_done);
99  if (err)
100  goto fail_async_init;
101 
102  uv__handle_unref(&loop->wq_async);
103  loop->wq_async.flags |= UV_HANDLE_INTERNAL;
104 
105  return 0;
106 
107 fail_async_init:
108  uv_mutex_destroy(&loop->wq_mutex);
109 
110 fail_mutex_init:
111  uv_rwlock_destroy(&loop->cloexec_lock);
112 
113 fail_rwlock_init:
115 
116 fail_signal_init:
118 
119 fail_platform_init:
121 
122 fail_metrics_mutex_init:
123  uv__free(lfields);
125 
126  uv__free(loop->watchers);
127  loop->nwatchers = 0;
128  return err;
129 }
int uv__platform_loop_init(uv_loop_t *loop)
Definition: aix.c:81
return memset(p, 0, total)
#define QUEUE_INIT(q)
Definition: queue.h:45
Definition: heap-inl.h:40
unsigned int stop_flag
Definition: uv.h:1793
union uv_loop_s::@400 active_reqs
void * data
Definition: uv.h:1782
void * handle_queue[2]
Definition: uv.h:1785
unsigned int count
Definition: uv.h:1788
unsigned int active_handles
Definition: uv.h:1784
void uv__signal_global_once_init(void)
Definition: signal.c:111
void uv__work_done(uv_async_t *handle)
Definition: threadpool.c:295
void * uv__calloc(size_t count, size_t size)
Definition: uv-common.c:92
@ UV_HANDLE_INTERNAL
Definition: uv-common.h:78
#define uv__handle_unref(h)
Definition: uv-common.h:283
UV_EXTERN int uv_rwlock_init(uv_rwlock_t *rwlock)
Definition: thread.c:356
UV_EXTERN int uv_async_init(uv_loop_t *, uv_async_t *async, uv_async_cb async_cb)
Definition: async.c:45
UV_EXTERN int uv_signal_init(uv_loop_t *loop, uv_signal_t *handle)
Definition: signal.c:319
UV_EXTERN int uv_mutex_init(uv_mutex_t *handle)
Definition: thread.c:282