summaryrefslogtreecommitdiffstats
path: root/Utilities/cmlibuv/src/unix/loop.c
diff options
context:
space:
mode:
Diffstat (limited to 'Utilities/cmlibuv/src/unix/loop.c')
-rw-r--r--Utilities/cmlibuv/src/unix/loop.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/Utilities/cmlibuv/src/unix/loop.c b/Utilities/cmlibuv/src/unix/loop.c
index c2a03d7..a88e71c 100644
--- a/Utilities/cmlibuv/src/unix/loop.c
+++ b/Utilities/cmlibuv/src/unix/loop.c
@@ -28,6 +28,7 @@
#include <unistd.h>
int uv_loop_init(uv_loop_t* loop) {
+ uv__loop_internal_fields_t* lfields;
void* saved_data;
int err;
@@ -36,6 +37,15 @@ int uv_loop_init(uv_loop_t* loop) {
memset(loop, 0, sizeof(*loop));
loop->data = saved_data;
+ lfields = (uv__loop_internal_fields_t*) uv__calloc(1, sizeof(*lfields));
+ if (lfields == NULL)
+ return UV_ENOMEM;
+ loop->internal_fields = lfields;
+
+ err = uv_mutex_init(&lfields->loop_metrics.lock);
+ if (err)
+ goto fail_metrics_mutex_init;
+
heap_init((struct heap*) &loop->timer_heap);
QUEUE_INIT(&loop->wq);
QUEUE_INIT(&loop->idle_handles);
@@ -66,7 +76,7 @@ int uv_loop_init(uv_loop_t* loop) {
err = uv__platform_loop_init(loop);
if (err)
- return err;
+ goto fail_platform_init;
uv__signal_global_once_init();
err = uv_signal_init(loop, &loop->child_watcher);
@@ -106,6 +116,15 @@ fail_rwlock_init:
fail_signal_init:
uv__platform_loop_delete(loop);
+fail_platform_init:
+ uv_mutex_destroy(&lfields->loop_metrics.lock);
+
+fail_metrics_mutex_init:
+ uv__free(lfields);
+ loop->internal_fields = NULL;
+
+ uv__free(loop->watchers);
+ loop->nwatchers = 0;
return err;
}
@@ -144,6 +163,8 @@ int uv_loop_fork(uv_loop_t* loop) {
void uv__loop_close(uv_loop_t* loop) {
+ uv__loop_internal_fields_t* lfields;
+
uv__signal_loop_cleanup(loop);
uv__platform_loop_delete(loop);
uv__async_stop(loop);
@@ -179,10 +200,23 @@ void uv__loop_close(uv_loop_t* loop) {
uv__free(loop->watchers);
loop->watchers = NULL;
loop->nwatchers = 0;
+
+ lfields = uv__get_internal_fields(loop);
+ uv_mutex_destroy(&lfields->loop_metrics.lock);
+ uv__free(lfields);
+ loop->internal_fields = NULL;
}
int uv__loop_configure(uv_loop_t* loop, uv_loop_option option, va_list ap) {
+ uv__loop_internal_fields_t* lfields;
+
+ lfields = uv__get_internal_fields(loop);
+ if (option == UV_METRICS_IDLE_TIME) {
+ lfields->flags |= UV_METRICS_IDLE_TIME;
+ return 0;
+ }
+
if (option != UV_LOOP_BLOCK_SIGNAL)
return UV_ENOSYS;