~yolanda.robla/ubuntu/trusty/nodejs/add_distribution

« back to all changes in this revision

Viewing changes to deps/uv/src/win/async.c

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include "uv.h"
25
25
#include "internal.h"
26
 
 
27
 
 
28
 
/* Atomic set operation on char */
29
 
#ifdef _MSC_VER /* MSVC */
30
 
 
31
 
/* _InterlockedOr8 is supported by MSVC on x32 and x64. It is  slightly less */
32
 
/* efficient than InterlockedExchange, but InterlockedExchange8 does not */
33
 
/* exist, and interlocked operations on larger targets might require the */
34
 
/* target to be aligned. */
35
 
#pragma intrinsic(_InterlockedOr8)
36
 
 
37
 
static char __declspec(inline) uv_atomic_exchange_set(char volatile* target) {
38
 
  return _InterlockedOr8(target, 1);
39
 
}
40
 
 
41
 
#else /* GCC */
42
 
 
43
 
/* Mingw-32 version, hopefully this works for 64-bit gcc as well. */
44
 
static inline char uv_atomic_exchange_set(char volatile* target) {
45
 
  const char one = 1;
46
 
  char old_value;
47
 
  __asm__ __volatile__ ("lock xchgb %0, %1\n\t"
48
 
                        : "=r"(old_value), "=m"(*target)
49
 
                        : "0"(one), "m"(*target)
50
 
                        : "memory");
51
 
  return old_value;
52
 
}
53
 
 
54
 
#endif
 
26
#include "atomicops-inl.h"
 
27
#include "handle-inl.h"
 
28
#include "req-inl.h"
55
29
 
56
30
 
57
31
void uv_async_endgame(uv_loop_t* loop, uv_async_t* handle) {
58
 
  if (handle->flags & UV_HANDLE_CLOSING &&
 
32
  if (handle->flags & UV__HANDLE_CLOSING &&
59
33
      !handle->async_sent) {
60
34
    assert(!(handle->flags & UV_HANDLE_CLOSED));
61
 
    handle->flags |= UV_HANDLE_CLOSED;
62
 
 
63
 
    if (handle->close_cb) {
64
 
      handle->close_cb((uv_handle_t*)handle);
65
 
    }
66
 
 
67
 
    uv_unref(loop);
 
35
    uv__handle_close(handle);
68
36
  }
69
37
}
70
38
 
72
40
int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) {
73
41
  uv_req_t* req;
74
42
 
75
 
  loop->counters.handle_init++;
76
 
  loop->counters.async_init++;
77
 
 
78
 
  handle->type = UV_ASYNC;
79
 
  handle->loop = loop;
80
 
  handle->flags = 0;
 
43
  uv__handle_init(loop, (uv_handle_t*) handle, UV_ASYNC);
81
44
  handle->async_sent = 0;
82
45
  handle->async_cb = async_cb;
83
46
 
86
49
  req->type = UV_WAKEUP;
87
50
  req->data = handle;
88
51
 
89
 
  uv_ref(loop);
 
52
  uv__handle_start(handle);
90
53
 
91
54
  return 0;
92
55
}
93
56
 
94
57
 
 
58
void uv_async_close(uv_loop_t* loop, uv_async_t* handle) {
 
59
  if (!((uv_async_t*)handle)->async_sent) {
 
60
    uv_want_endgame(loop, (uv_handle_t*) handle);
 
61
  }
 
62
 
 
63
  uv__handle_closing(handle);
 
64
}
 
65
 
 
66
 
95
67
int uv_async_send(uv_async_t* handle) {
96
68
  uv_loop_t* loop = handle->loop;
97
69
 
102
74
 
103
75
  /* The user should make sure never to call uv_async_send to a closing */
104
76
  /* or closed handle. */
105
 
  assert(!(handle->flags & UV_HANDLE_CLOSING));
 
77
  assert(!(handle->flags & UV__HANDLE_CLOSING));
106
78
 
107
 
  if (!uv_atomic_exchange_set(&handle->async_sent)) {
 
79
  if (!uv__atomic_exchange_set(&handle->async_sent)) {
108
80
    POST_COMPLETION_FOR_REQ(loop, &handle->async_req);
109
81
  }
110
82
 
118
90
  assert(req->type == UV_WAKEUP);
119
91
 
120
92
  handle->async_sent = 0;
121
 
  if (handle->async_cb) {
 
93
 
 
94
  if (!(handle->flags & UV__HANDLE_CLOSING)) {
122
95
    handle->async_cb((uv_async_t*) handle, 0);
123
 
  }
124
 
  if (handle->flags & UV_HANDLE_CLOSING) {
 
96
  } else {
125
97
    uv_want_endgame(loop, (uv_handle_t*)handle);
126
98
  }
127
99
}