win/async.c
Go to the documentation of this file.
1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21 
22 #include <assert.h>
23 
24 #include "uv.h"
25 #include "internal.h"
26 #include "atomicops-inl.h"
27 #include "handle-inl.h"
28 #include "req-inl.h"
29 
30 
32  if (handle->flags & UV_HANDLE_CLOSING &&
33  !handle->async_sent) {
34  assert(!(handle->flags & UV_HANDLE_CLOSED));
36  }
37 }
38 
39 
41  uv_req_t* req;
42 
43  uv__handle_init(loop, (uv_handle_t*) handle, UV_ASYNC);
44  handle->async_sent = 0;
45  handle->async_cb = async_cb;
46 
47  req = &handle->async_req;
48  UV_REQ_INIT(req, UV_WAKEUP);
49  req->data = handle;
50 
52 
53  return 0;
54 }
55 
56 
58  if (!((uv_async_t*)handle)->async_sent) {
60  }
61 
63 }
64 
65 
67  uv_loop_t* loop = handle->loop;
68 
69  if (handle->type != UV_ASYNC) {
70  /* Can't set errno because that's not thread-safe. */
71  return -1;
72  }
73 
74  /* The user should make sure never to call uv_async_send to a closing or
75  * closed handle. */
76  assert(!(handle->flags & UV_HANDLE_CLOSING));
77 
78  if (!uv__atomic_exchange_set(&handle->async_sent)) {
79  POST_COMPLETION_FOR_REQ(loop, &handle->async_req);
80  }
81 
82  return 0;
83 }
84 
85 
87  uv_req_t* req) {
88  assert(handle->type == UV_ASYNC);
89  assert(req->type == UV_WAKEUP);
90 
91  handle->async_sent = 0;
92 
93  if (handle->flags & UV_HANDLE_CLOSING) {
95  } else if (handle->async_cb != NULL) {
96  handle->async_cb(handle);
97  }
98 }
async_greeter_server_with_graceful_shutdown.loop
loop
Definition: async_greeter_server_with_graceful_shutdown.py:59
uv_async_endgame
void uv_async_endgame(uv_loop_t *loop, uv_async_t *handle)
Definition: win/async.c:31
UV_HANDLE_CLOSED
@ UV_HANDLE_CLOSED
Definition: uv-common.h:67
POST_COMPLETION_FOR_REQ
#define POST_COMPLETION_FOR_REQ(loop, req)
Definition: req-inl.h:76
uv__handle_close
#define uv__handle_close(handle)
Definition: handle-inl.h:76
uv_want_endgame
static INLINE void uv_want_endgame(uv_loop_t *loop, uv_handle_t *handle)
Definition: handle-inl.h:88
req-inl.h
uv__handle_closing
#define uv__handle_closing(handle)
Definition: handle-inl.h:63
uv_process_async_wakeup_req
void uv_process_async_wakeup_req(uv_loop_t *loop, uv_async_t *handle, uv_req_t *req)
Definition: win/async.c:86
uv_async_s
Definition: uv.h:834
req
static uv_connect_t req
Definition: test-connection-fail.c:30
uv_async_close
void uv_async_close(uv_loop_t *loop, uv_async_t *handle)
Definition: win/async.c:57
uv__handle_init
#define uv__handle_init(loop_, h, type_)
Definition: uv-common.h:284
uv.h
UV_REQ_INIT
#define UV_REQ_INIT(req, typ)
Definition: uv-common.h:305
UV_HANDLE_CLOSING
@ UV_HANDLE_CLOSING
Definition: uv-common.h:66
async_cb
static void async_cb(uv_async_t *handle)
Definition: benchmark-async-pummel.c:39
uv_async_cb
void(* uv_async_cb)(uv_async_t *handle)
Definition: uv.h:319
atomicops-inl.h
handle
static csh handle
Definition: test_arm_regression.c:16
uv_handle_s
Definition: uv.h:441
uv_async_send
int uv_async_send(uv_async_t *handle)
Definition: win/async.c:66
uv_loop_s
Definition: uv.h:1767
internal.h
uv_async_init
int uv_async_init(uv_loop_t *loop, uv_async_t *handle, uv_async_cb async_cb)
Definition: win/async.c:40
uv__handle_start
#define uv__handle_start(h)
Definition: uv-common.h:241
handle-inl.h
uv_req_s
Definition: uv.h:404
uv__atomic_exchange_set
static char uv__atomic_exchange_set(char volatile *target)
Definition: atomicops-inl.h:45


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:35