unix: port fs and work api to new thread pool
This commit is contained in:
parent
36c91e3ba0
commit
74999f8f99
@ -51,7 +51,7 @@ ifeq (SunOS,$(uname_S))
|
||||
EV_CONFIG=config_sunos.h
|
||||
EIO_CONFIG=config_sunos.h
|
||||
CPPFLAGS += -D__EXTENSIONS__ -D_XOPEN_SOURCE=500
|
||||
LINKFLAGS+=-lsocket -lnsl -lkstat
|
||||
LINKFLAGS+=-lkstat -lnsl -lsendfile -lsocket
|
||||
OBJS += src/unix/sunos.o
|
||||
endif
|
||||
|
||||
@ -137,7 +137,7 @@ endif
|
||||
RUNNER_LIBS=
|
||||
RUNNER_SRC=test/runner-unix.c
|
||||
|
||||
uv.a: $(OBJS) src/fs-poll.o src/inet.o src/uv-common.o src/unix/ev/ev.o src/unix/uv-eio.o src/unix/eio/eio.o
|
||||
uv.a: $(OBJS) src/fs-poll.o src/inet.o src/uv-common.o src/unix/ev/ev.o src/unix/eio/eio.o
|
||||
$(AR) rcs uv.a $^
|
||||
|
||||
src/%.o: src/%.c include/uv.h include/uv-private/uv-unix.h
|
||||
@ -158,10 +158,6 @@ EIO_CPPFLAGS += -D_GNU_SOURCE
|
||||
src/unix/eio/eio.o: src/unix/eio/eio.c
|
||||
$(CC) $(EIO_CPPFLAGS) $(CFLAGS) -c src/unix/eio/eio.c -o src/unix/eio/eio.o
|
||||
|
||||
src/unix/uv-eio.o: src/unix/uv-eio.c
|
||||
$(CC) $(CPPFLAGS) -Isrc/unix/eio/ $(CSTDFLAG) $(CFLAGS) -c src/unix/uv-eio.c -o src/unix/uv-eio.o
|
||||
|
||||
|
||||
clean-platform:
|
||||
-rm -f src/unix/*.o
|
||||
-rm -f src/unix/ev/*.o
|
||||
|
||||
@ -25,7 +25,6 @@
|
||||
#include "ngx-queue.h"
|
||||
|
||||
#include "ev.h"
|
||||
#include "eio.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@ -122,13 +121,7 @@ typedef struct {
|
||||
|
||||
#define UV_LOOP_PRIVATE_FIELDS \
|
||||
unsigned long flags; \
|
||||
/* Poll result queue */ \
|
||||
eio_channel uv_eio_channel; \
|
||||
struct ev_loop* ev; \
|
||||
/* Various thing for libeio. */ \
|
||||
uv_async_t uv_eio_want_poll_notifier; \
|
||||
uv_async_t uv_eio_done_poll_notifier; \
|
||||
uv_idle_t uv_eio_poller; \
|
||||
ngx_queue_t wq; \
|
||||
uv_mutex_t wq_mutex; \
|
||||
uv_async_t wq_async; \
|
||||
@ -256,12 +249,22 @@ typedef struct {
|
||||
int errorno; \
|
||||
|
||||
#define UV_FS_PRIVATE_FIELDS \
|
||||
struct stat statbuf; \
|
||||
const char *new_path; \
|
||||
uv_file file; \
|
||||
eio_req* eio; \
|
||||
int flags; \
|
||||
mode_t mode; \
|
||||
void* buf; \
|
||||
size_t len; \
|
||||
off_t off; \
|
||||
uid_t uid; \
|
||||
gid_t gid; \
|
||||
double atime; \
|
||||
double mtime; \
|
||||
struct uv__work work_req; \
|
||||
struct stat statbuf; \
|
||||
|
||||
#define UV_WORK_PRIVATE_FIELDS \
|
||||
eio_req* eio;
|
||||
struct uv__work work_req;
|
||||
|
||||
#define UV_TTY_PRIVATE_FIELDS \
|
||||
struct termios orig_termios; \
|
||||
|
||||
1251
src/unix/fs.c
1251
src/unix/fs.c
File diff suppressed because it is too large
Load Diff
@ -23,7 +23,6 @@
|
||||
#define UV_UNIX_INTERNAL_H_
|
||||
|
||||
#include "uv-common.h"
|
||||
#include "uv-eio.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h> /* abort */
|
||||
@ -101,11 +100,6 @@ enum {
|
||||
UV_TCP_SINGLE_ACCEPT = 0x400 /* Only accept() when idle. */
|
||||
};
|
||||
|
||||
/* loop flags */
|
||||
enum {
|
||||
UV_LOOP_EIO_INITIALIZED = 1
|
||||
};
|
||||
|
||||
__attribute__((unused))
|
||||
__attribute__((always_inline))
|
||||
static void uv__req_init(uv_loop_t* loop, uv_req_t* req, uv_req_type type) {
|
||||
|
||||
@ -54,7 +54,6 @@ int uv__loop_init(uv_loop_t* loop, int default_loop) {
|
||||
loop->emfile_fd = -1;
|
||||
loop->ev = (default_loop ? ev_default_loop : ev_loop_new)(flags);
|
||||
ev_set_userdata(loop->ev, loop);
|
||||
eio_channel_init(&loop->uv_eio_channel, loop);
|
||||
|
||||
uv_signal_init(loop, &loop->child_watcher);
|
||||
uv__handle_unref(&loop->child_watcher);
|
||||
|
||||
@ -1,107 +0,0 @@
|
||||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* This file integrates the libuv event loop with the libeio thread pool */
|
||||
|
||||
#include "uv.h"
|
||||
#include "eio.h"
|
||||
#include "internal.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
static uv_once_t uv__eio_init_once_guard = UV_ONCE_INIT;
|
||||
|
||||
|
||||
static void uv_eio_do_poll(uv_idle_t* watcher, int status) {
|
||||
uv_loop_t* loop = watcher->loop;
|
||||
assert(watcher == &loop->uv_eio_poller);
|
||||
if (eio_poll(&loop->uv_eio_channel) != -1)
|
||||
uv_idle_stop(watcher);
|
||||
}
|
||||
|
||||
|
||||
/* Called from the main thread. */
|
||||
static void uv_eio_want_poll_notifier_cb(uv_async_t* watcher, int status) {
|
||||
uv_loop_t* loop = watcher->loop;
|
||||
assert(watcher == &loop->uv_eio_want_poll_notifier);
|
||||
if (eio_poll(&loop->uv_eio_channel) == -1)
|
||||
uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll);
|
||||
}
|
||||
|
||||
|
||||
static void uv_eio_done_poll_notifier_cb(uv_async_t* watcher, int revents) {
|
||||
uv_loop_t* loop = watcher->loop;
|
||||
assert(watcher == &loop->uv_eio_done_poll_notifier);
|
||||
if (eio_poll(&loop->uv_eio_channel) != -1)
|
||||
uv_idle_stop(&loop->uv_eio_poller);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* uv_eio_want_poll() is called from the EIO thread pool each time an EIO
|
||||
* request (that is, one of the node.fs.* functions) has completed.
|
||||
*/
|
||||
static void uv_eio_want_poll(eio_channel *channel) {
|
||||
/* Signal the main thread that eio_poll need to be processed. */
|
||||
uv_loop_t* loop = channel->data;
|
||||
uv_async_send(&loop->uv_eio_want_poll_notifier);
|
||||
}
|
||||
|
||||
|
||||
static void uv_eio_done_poll(eio_channel *channel) {
|
||||
/*
|
||||
* Signal the main thread that we should stop calling eio_poll().
|
||||
* from the idle watcher.
|
||||
*/
|
||||
uv_loop_t* loop = channel->data;
|
||||
uv_async_send(&loop->uv_eio_done_poll_notifier);
|
||||
}
|
||||
|
||||
|
||||
static void uv__eio_init(void) {
|
||||
eio_init(uv_eio_want_poll, uv_eio_done_poll);
|
||||
}
|
||||
|
||||
|
||||
void uv_eio_init(uv_loop_t* loop) {
|
||||
if (loop->flags & UV_LOOP_EIO_INITIALIZED) return;
|
||||
loop->flags |= UV_LOOP_EIO_INITIALIZED;
|
||||
|
||||
uv_idle_init(loop, &loop->uv_eio_poller);
|
||||
uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll);
|
||||
loop->uv_eio_poller.flags |= UV__HANDLE_INTERNAL;
|
||||
|
||||
loop->uv_eio_want_poll_notifier.data = loop;
|
||||
uv_async_init(loop,
|
||||
&loop->uv_eio_want_poll_notifier,
|
||||
uv_eio_want_poll_notifier_cb);
|
||||
loop->uv_eio_want_poll_notifier.flags |= UV__HANDLE_INTERNAL;
|
||||
uv__handle_unref(&loop->uv_eio_want_poll_notifier);
|
||||
|
||||
uv_async_init(loop,
|
||||
&loop->uv_eio_done_poll_notifier,
|
||||
uv_eio_done_poll_notifier_cb);
|
||||
loop->uv_eio_done_poll_notifier.flags |= UV__HANDLE_INTERNAL;
|
||||
uv__handle_unref(&loop->uv_eio_done_poll_notifier);
|
||||
|
||||
uv_once(&uv__eio_init_once_guard, uv__eio_init);
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
/* This header is private to libuv */
|
||||
#ifndef UV_EIO_H_
|
||||
#define UV_EIO_H_
|
||||
|
||||
#include "eio.h"
|
||||
|
||||
/*
|
||||
* Call this function to integrate libeio into the libuv event loop. It is
|
||||
* safe to call more than once.
|
||||
* TODO: uv_eio_deinit
|
||||
*/
|
||||
void uv_eio_init(uv_loop_t*);
|
||||
#endif
|
||||
5
uv.gyp
5
uv.gyp
@ -142,8 +142,6 @@
|
||||
'src/unix/timer.c',
|
||||
'src/unix/tty.c',
|
||||
'src/unix/udp.c',
|
||||
'src/unix/uv-eio.c',
|
||||
'src/unix/uv-eio.h',
|
||||
],
|
||||
'include_dirs': [ 'src/unix/ev', ],
|
||||
'libraries': [ '-lm' ]
|
||||
@ -187,8 +185,9 @@
|
||||
'direct_dependent_settings': {
|
||||
'libraries': [
|
||||
'-lkstat',
|
||||
'-lsocket',
|
||||
'-lnsl',
|
||||
'-lsendfile',
|
||||
'-lsocket',
|
||||
],
|
||||
},
|
||||
}],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user