unix, windows: add uv_loop_configure() function

The only supported option right now is UV_LOOP_BLOCK_SIGNAL, which only
supports the SIGPROF signal and only on UNIX platforms.  So yes, it is
kind of limited right now.  But everything has to start somewhere.

Refs strongloop/strong-agent#3 and strongloop-internal/scrum-cs#37.

PR-URL: https://github.com/libuv/libuv/pull/15
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
Ben Noordhuis 2014-11-27 08:43:48 +01:00
parent 2daf9448b1
commit 9da5fd443e
5 changed files with 52 additions and 0 deletions

View File

@ -226,6 +226,16 @@ typedef struct uv_work_s uv_work_t;
typedef struct uv_cpu_info_s uv_cpu_info_t;
typedef struct uv_interface_address_s uv_interface_address_t;
typedef enum {
/* Block a signal when polling for new events. The second argument to
* uv_loop_configure() is the signal number.
*
* This operation is currently only implemented for SIGPROF signals,
* to suppress unnecessary wakeups when using a sampling profiler.
* Requesting other signals will fail with UV_EINVAL.
*/
UV_LOOP_BLOCK_SIGNAL
} uv_loop_option;
typedef enum {
UV_RUN_DEFAULT = 0,
@ -264,6 +274,15 @@ UV_EXTERN void uv_loop_delete(uv_loop_t*);
*/
UV_EXTERN uv_loop_t* uv_default_loop(void);
/*
* Set additional loop options. You should normally call this before the
* first call to uv_run() unless mentioned otherwise.
*
* Returns 0 on success or a UV_E* error code on failure. Be prepared to
* handle UV_ENOSYS; it means the loop option is not supported by the platform.
*/
UV_EXTERN int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...);
/*
* This function runs the event loop. It will act differently depending on the
* specified mode:

View File

@ -112,3 +112,15 @@ void uv__loop_delete(uv_loop_t* loop) {
loop->watchers = NULL;
loop->nwatchers = 0;
}
int uv__loop_configure(uv_loop_t* loop, uv_loop_option option, va_list ap) {
if (option != UV_LOOP_BLOCK_SIGNAL)
return UV_ENOSYS;
if (va_arg(ap, int) != SIGPROF)
return UV_EINVAL;
loop->flags |= UV_LOOP_BLOCK_SIGPROF;
return 0;
}

View File

@ -24,6 +24,7 @@
#include <stdio.h>
#include <assert.h>
#include <stdarg.h>
#include <stddef.h> /* NULL */
#include <stdlib.h> /* malloc */
#include <string.h> /* memset */
@ -434,3 +435,16 @@ void uv_stop(uv_loop_t* loop) {
uint64_t uv_now(uv_loop_t* loop) {
return loop->time;
}
int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...) {
va_list ap;
int err;
va_start(ap, option);
/* Any platform-agnostic options should be handled here. */
err = uv__loop_configure(loop, option, ap);
va_end(ap);
return err;
}

View File

@ -28,6 +28,7 @@
#define UV_COMMON_H_
#include <assert.h>
#include <stdarg.h>
#include <stddef.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
@ -77,6 +78,7 @@ int uv__set_artificial_error(uv_loop_t* loop, uv_err_code code);
uv_err_t uv__new_sys_error(int sys_error);
uv_err_t uv__new_artificial_error(uv_err_code code);
int uv__loop_configure(uv_loop_t* loop, uv_loop_option option, va_list ap);
int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr);
int uv__tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr);

View File

@ -174,6 +174,11 @@ void uv_loop_delete(uv_loop_t* loop) {
}
int uv__loop_configure(uv_loop_t* loop, uv_loop_option option, va_list ap) {
return UV_ENOSYS;
}
int uv_backend_fd(const uv_loop_t* loop) {
return -1;
}