Commit Graph

16 Commits

Author SHA1 Message Date
Ben Noordhuis
1282d64868 unix: remove dependency on libev 2012-11-16 17:33:25 +01:00
Ben Noordhuis
b7f38b1e53 Revert "unix: avoid iterating over all async handles"
This reverts commit 209abbab27.

Fixes the following SIGSEGV:

  (gdb) f 1
  #1  0x00007fc084683aec in uv__async_io (loop=0x7fc0848e0b40,
  handle=0x7fc0848e0c78, events=1) at src/unix/async.c:175
  175             ASYNC_CB(h)
  (gdb) list
  170
  171         /* If we need to sweep all handles anyway - skip this loop */
  172         if (!loop->async_sweep_needed) {
  173           for (i = 0; i < end; i += sizeof(h)) {
  174             h = *((uv_async_t**) (buf + i));
  175             ASYNC_CB(h)
  176           }
  177         }
  178
  179         bytes -= end;
  (gdb) print *h
  $1 = {close_cb = 0x184e1b0, data = 0x18d9520, loop = 0x7fc0848e0b40,
  type = 49, handle_queue = {prev = 0x18dae10, next = 0x7860c0}, flags = 32,
  next_closing = 0x1863b40, pending = 0, async_cb = 0x31,
  queue = {prev = 0x18dae50, next = 0x7860c0}}
  (gdb)

It looks like the async handle gets closed or otherwise becomes invalid before
the sweep is executed.

Fixes #603.
2012-10-24 14:58:49 +02:00
Ben Noordhuis
1bb1ba27dd unix: fix compiler warning in async.c
Include missing <string.h> header. Fixes the following compiler warning:

  src/unix/async.c:182:7: warning: implicit declaration of
  function ‘memmove’ [-Wimplicit-function-declaration]
2012-10-20 23:36:00 +02:00
Fedor Indutny
209abbab27 unix: avoid iterating over all async handles 2012-10-19 17:22:30 +02:00
Ben Noordhuis
fd136da04a unix: remove always_inline attribute
Fixes the following gcc 4.7+ warning:

  ../src/unix/internal.h:105:13: warning: always_inline function might not be
  inlinable [-Wattributes]

gcc wants the always_inline function to be annotated with the 'inline' keyword
which we can't do because we compile in C89 mode.

Using __inline is not an option because that makes clang generate warnings when
-Wlanguage-extension-token is enabled.

Therefore, remove the always_inline attribute altogether and hope that the
compiler is smart enough to inline the functions.
2012-10-15 01:08:47 +02:00
Ben Noordhuis
ff0a93a04f unix: fix clang -Wlanguage-extension-token warnings 2012-09-01 00:27:57 +02:00
Bert Belder
a787a16ac3 unix: fix uv_async_send not working with Sun Studio
uv_async_send would always return 1 when non-gcc compilers were used.
When uv_async_send returns 1 no attempt is made to make port_getn
return, so in this situation uv_async_send didn't wake up the event
loop.
2012-08-22 20:40:14 +02:00
Ben Noordhuis
837edf4c0f unix, windows: remove handle init counters
Remove the handle init counters, no one uses them.
2012-08-10 02:00:11 +02:00
Ben Noordhuis
c5761f72b3 unix: speed up uv_async_send() some more still
__sync_val_compare_and_swap() emits a CMPXCHG instruction on i386 and x86_64.
Use XCHG instead, it's about four times faster.
2012-07-09 02:46:19 +02:00
Ben Noordhuis
3d9c1ebfeb unix: speed up uv_async_send() some more
Use atomic compare-and-swap to detect if we've been preempted by another thread
and therefore can avoid making the expensive write() syscall.

Speeds up the heavily contended case by about 1-2% and has little if any impact
on the non-contended case. I wasn't able to measure the difference at any rate.
2012-07-02 04:30:48 +02:00
Ben Noordhuis
4c87666a93 unix: speed up uv_async_send()
Don't make a syscall when the handle is already pending.

Speeds up the async_pummel benchmark by about 13%.
2012-06-29 03:18:09 +02:00
Ben Noordhuis
78bc0d6134 unix: implement async handles in libuv
Replace libev backed async handles with a pure libuv implementation.
2012-06-11 04:19:31 +02:00
Bert Belder
5c30443555 unix: uv_async handles should not be unref'ed automatically 2012-06-10 02:25:20 +02:00
Ben Noordhuis
9efa8b3571 unix, windows: rework reference counting scheme
This commit changes how the event loop determines if it needs to stay alive.

Previously, an internal counter was increased whenever a handle got created
and decreased again when the handle was closed.

While conceptually simple, it turned out hard to work with: you often want
to keep the event loop alive only if the handle is actually doing something.
Stopped or inactive handles were a frequent source of hanging event loops.

That's why this commit changes the reference counting scheme to a model where
a handle only references the event loop when it's active. 'Active' means
different things for different handle types, e.g.:

 * timers: ticking
 * sockets: reading, writing or listening
 * processes: always active (for now, subject to change)
 * idle, check, prepare: only active when started

This commit also changes how the uv_ref() and uv_unref() functions work: they
now operate on the level of individual handles, not the whole event loop.

The Windows implementation was done by Bert Belder.
2012-05-17 07:07:53 +02:00
Ben Noordhuis
5a8446c309 unix: move handle specific close logic out of core.c 2012-04-04 05:30:15 -07:00
Ben Noordhuis
f7359a335c unix: move async code from core.c to async.c 2012-04-04 05:25:34 +02:00