/src/hdf5/src/H5ESevent.c
Line | Count | Source |
1 | | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | | * Copyright by The HDF Group. * |
3 | | * All rights reserved. * |
4 | | * * |
5 | | * This file is part of HDF5. The full HDF5 copyright notice, including * |
6 | | * terms governing use, modification, and redistribution, is contained in * |
7 | | * the LICENSE file, which can be found at the root of the source code * |
8 | | * distribution tree, or in https://www.hdfgroup.org/licenses. * |
9 | | * If you do not have access to either file, you may request a copy from * |
10 | | * help@hdfgroup.org. * |
11 | | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
12 | | |
13 | | /*------------------------------------------------------------------------- |
14 | | * |
15 | | * Created: H5ESevent.c |
16 | | * |
17 | | * Purpose: Operations on "events" for managing asynchronous |
18 | | * operations. |
19 | | * |
20 | | * Please see the asynchronous I/O RFC document |
21 | | * for a full description of how they work, etc. |
22 | | * |
23 | | *------------------------------------------------------------------------- |
24 | | */ |
25 | | |
26 | | /****************/ |
27 | | /* Module Setup */ |
28 | | /****************/ |
29 | | |
30 | | #include "H5ESmodule.h" /* This source code file is part of the H5ES module */ |
31 | | |
32 | | /***********/ |
33 | | /* Headers */ |
34 | | /***********/ |
35 | | #include "H5private.h" /* Generic Functions */ |
36 | | #include "H5Eprivate.h" /* Error handling */ |
37 | | #include "H5ESpkg.h" /* Event Sets */ |
38 | | #include "H5FLprivate.h" /* Free Lists */ |
39 | | #include "H5MMprivate.h" /* Memory management */ |
40 | | |
41 | | /****************/ |
42 | | /* Local Macros */ |
43 | | /****************/ |
44 | | |
45 | | /******************/ |
46 | | /* Local Typedefs */ |
47 | | /******************/ |
48 | | |
49 | | /********************/ |
50 | | /* Package Typedefs */ |
51 | | /********************/ |
52 | | |
53 | | /********************/ |
54 | | /* Local Prototypes */ |
55 | | /********************/ |
56 | | |
57 | | /*********************/ |
58 | | /* Package Variables */ |
59 | | /*********************/ |
60 | | |
61 | | /*****************************/ |
62 | | /* Library Private Variables */ |
63 | | /*****************************/ |
64 | | |
65 | | /*******************/ |
66 | | /* Local Variables */ |
67 | | /*******************/ |
68 | | |
69 | | /* Declare a static free list to manage H5ES_event_t structs */ |
70 | | H5FL_DEFINE_STATIC(H5ES_event_t); |
71 | | |
72 | | /*------------------------------------------------------------------------- |
73 | | * Function: H5ES__event_new |
74 | | * |
75 | | * Purpose: Allocate and initialize a new event |
76 | | * |
77 | | * Return: Non-NULL pointer to new event on success, NULL on failure |
78 | | * |
79 | | *------------------------------------------------------------------------- |
80 | | */ |
81 | | H5ES_event_t * |
82 | | H5ES__event_new(H5VL_connector_t *connector, void *token) |
83 | 0 | { |
84 | 0 | H5ES_event_t *ev = NULL; /* New event */ |
85 | 0 | H5VL_object_t *request = NULL; /* Async request token VOL object */ |
86 | 0 | H5ES_event_t *ret_value = NULL; /* Return value */ |
87 | |
|
88 | 0 | FUNC_ENTER_PACKAGE |
89 | | |
90 | | /* Sanity check */ |
91 | 0 | assert(connector); |
92 | 0 | assert(token); |
93 | | |
94 | | /* Create vol object for token */ |
95 | 0 | if (NULL == (request = H5VL_create_object(token, connector))) { |
96 | 0 | if (H5VL_request_free(token) < 0) |
97 | 0 | HDONE_ERROR(H5E_EVENTSET, H5E_CANTFREE, NULL, "can't free request"); |
98 | 0 | HGOTO_ERROR(H5E_EVENTSET, H5E_CANTINIT, NULL, "can't create vol object for request token"); |
99 | 0 | } /* end if */ |
100 | | |
101 | | /* Allocate space for new event */ |
102 | 0 | if (NULL == (ev = H5FL_CALLOC(H5ES_event_t))) |
103 | 0 | HGOTO_ERROR(H5E_EVENTSET, H5E_CANTALLOC, NULL, "can't allocate event object"); |
104 | | |
105 | | /* Set request for event */ |
106 | 0 | ev->request = request; |
107 | | |
108 | | /* Set return value */ |
109 | 0 | ret_value = ev; |
110 | |
|
111 | 0 | done: |
112 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
113 | 0 | } /* end H5ES__event_new() */ |
114 | | |
115 | | /*------------------------------------------------------------------------- |
116 | | * Function: H5ES__event_free |
117 | | * |
118 | | * Purpose: Free an event |
119 | | * |
120 | | * Return: SUCCEED / FAIL |
121 | | * |
122 | | *------------------------------------------------------------------------- |
123 | | */ |
124 | | herr_t |
125 | | H5ES__event_free(H5ES_event_t *ev) |
126 | 0 | { |
127 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
128 | |
|
129 | 0 | FUNC_ENTER_PACKAGE |
130 | | |
131 | | /* Sanity check */ |
132 | 0 | assert(ev); |
133 | | |
134 | | /* The 'app_func_name', 'app_file_name', and 'api_name' strings are statically allocated (by the compiler) |
135 | | * and are not allocated, so there's no need to free them. |
136 | | */ |
137 | 0 | ev->op_info.api_name = NULL; |
138 | 0 | if (ev->op_info.api_args) |
139 | 0 | H5MM_xfree_const(ev->op_info.api_args); |
140 | 0 | ev->op_info.app_file_name = NULL; |
141 | 0 | ev->op_info.app_func_name = NULL; |
142 | 0 | if (ev->request) { |
143 | | /* Free the request */ |
144 | 0 | if (H5VL_request_free(ev->request) < 0) |
145 | 0 | HGOTO_ERROR(H5E_EVENTSET, H5E_CANTFREE, FAIL, "unable to free request"); |
146 | | |
147 | | /* Free the VOL object for the request */ |
148 | 0 | if (H5VL_free_object(ev->request) < 0) |
149 | 0 | HGOTO_ERROR(H5E_EVENTSET, H5E_CANTRELEASE, FAIL, "can't free VOL request object"); |
150 | 0 | } /* end if */ |
151 | | |
152 | 0 | H5FL_FREE(H5ES_event_t, ev); |
153 | |
|
154 | 0 | done: |
155 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
156 | 0 | } /* end H5ES__event_free() */ |
157 | | |
158 | | /*------------------------------------------------------------------------- |
159 | | * Function: H5ES__event_completed |
160 | | * |
161 | | * Purpose: Handle a completed event |
162 | | * |
163 | | * Return: SUCCEED / FAIL |
164 | | * |
165 | | *------------------------------------------------------------------------- |
166 | | */ |
167 | | herr_t |
168 | | H5ES__event_completed(H5ES_event_t *ev, H5ES_event_list_t *el) |
169 | 0 | { |
170 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
171 | |
|
172 | 0 | FUNC_ENTER_PACKAGE |
173 | | |
174 | | /* Sanity check */ |
175 | 0 | assert(ev); |
176 | | |
177 | | /* Remove the event from the event list */ |
178 | 0 | H5ES__list_remove(el, ev); |
179 | | |
180 | | /* Free the event */ |
181 | 0 | if (H5ES__event_free(ev) < 0) |
182 | 0 | HGOTO_ERROR(H5E_EVENTSET, H5E_CANTFREE, FAIL, "unable to free event"); |
183 | | |
184 | 0 | done: |
185 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
186 | 0 | } /* end H5ES__event_completed() */ |