Changes in uspace/lib/c/generic/async.c [ab9f443:f302586] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
rab9f443 rf302586 189 189 /** If reply was received. */ 190 190 bool done; 191 192 /** If the message / reply should be discarded on arrival. */193 bool forget;194 195 /** If already destroyed. */196 bool destroyed;197 191 198 192 /** Pointer to where the answer data is stored. */ … … 246 240 /** Identifier of the incoming connection handled by the current fibril. */ 247 241 static fibril_local connection_t *fibril_connection; 248 249 static void to_event_initialize(to_event_t *to)250 {251 struct timeval tv = { 0 };252 253 to->inlist = false;254 to->occurred = false;255 link_initialize(&to->link);256 to->expires = tv;257 }258 259 static void wu_event_initialize(wu_event_t *wu)260 {261 wu->inlist = false;262 link_initialize(&wu->link);263 }264 265 void awaiter_initialize(awaiter_t *aw)266 {267 aw->fid = 0;268 aw->active = false;269 to_event_initialize(&aw->to_event);270 wu_event_initialize(&aw->wu_event);271 }272 273 static amsg_t *amsg_create(void)274 {275 amsg_t *msg;276 277 msg = malloc(sizeof(amsg_t));278 if (msg) {279 msg->done = false;280 msg->forget = false;281 msg->destroyed = false;282 msg->dataptr = NULL;283 msg->retval = (sysarg_t) EINVAL;284 awaiter_initialize(&msg->wdata);285 }286 287 return msg;288 }289 290 static void amsg_destroy(amsg_t *msg)291 {292 assert(!msg->destroyed);293 msg->destroyed = true;294 free(msg);295 }296 242 297 243 static void *default_client_data_constructor(void) … … 1154 1100 1155 1101 msg->done = true; 1156 1157 if (msg->forget) { 1158 assert(msg->wdata.active); 1159 amsg_destroy(msg); 1160 } else if (!msg->wdata.active) { 1102 if (!msg->wdata.active) { 1161 1103 msg->wdata.active = true; 1162 1104 fibril_add_ready(msg->wdata.fid); 1163 1105 } 1164 1106 1165 1107 futex_up(&async_futex); 1166 1108 } … … 1189 1131 return 0; 1190 1132 1191 amsg_t *msg = amsg_create();1133 amsg_t *msg = malloc(sizeof(amsg_t)); 1192 1134 if (msg == NULL) 1193 1135 return 0; 1194 1136 1137 msg->done = false; 1195 1138 msg->dataptr = dataptr; 1139 1140 msg->wdata.to_event.inlist = false; 1141 1142 /* 1143 * We may sleep in the next method, 1144 * but it will use its own means 1145 */ 1196 1146 msg->wdata.active = true; 1197 1147 … … 1227 1177 return 0; 1228 1178 1229 amsg_t *msg = amsg_create(); 1179 amsg_t *msg = malloc(sizeof(amsg_t)); 1180 1230 1181 if (msg == NULL) 1231 1182 return 0; 1232 1183 1184 msg->done = false; 1233 1185 msg->dataptr = dataptr; 1186 1187 msg->wdata.to_event.inlist = false; 1188 1189 /* 1190 * We may sleep in the next method, 1191 * but it will use its own means 1192 */ 1234 1193 msg->wdata.active = true; 1235 1194 … … 1254 1213 1255 1214 futex_down(&async_futex); 1256 1257 assert(!msg->forget);1258 assert(!msg->destroyed);1259 1260 1215 if (msg->done) { 1261 1216 futex_up(&async_futex); … … 1276 1231 *retval = msg->retval; 1277 1232 1278 amsg_destroy(msg);1233 free(msg); 1279 1234 } 1280 1235 1281 1236 /** Wait for a message sent by the async framework, timeout variant. 1282 *1283 * If the wait times out, the caller may choose to either wait again by calling1284 * async_wait_for() or async_wait_timeout(), or forget the message via1285 * async_forget().1286 1237 * 1287 1238 * @param amsgid Hash of the message to wait for. … … 1304 1255 1305 1256 futex_down(&async_futex); 1306 1307 assert(!msg->forget);1308 assert(!msg->destroyed);1309 1310 1257 if (msg->done) { 1311 1258 futex_up(&async_futex); … … 1332 1279 *retval = msg->retval; 1333 1280 1334 amsg_destroy(msg);1281 free(msg); 1335 1282 1336 1283 return 0; 1337 1284 } 1338 1339 /** Discard the message / reply on arrival.1340 *1341 * The message will be marked to be discarded once the reply arrives in1342 * reply_received(). It is not allowed to call async_wait_for() or1343 * async_wait_timeout() on this message after a call to this function.1344 *1345 * @param amsgid Hash of the message to forget.1346 */1347 void async_forget(aid_t amsgid)1348 {1349 amsg_t *msg = (amsg_t *) amsgid;1350 1351 assert(msg);1352 assert(!msg->forget);1353 assert(!msg->destroyed);1354 1355 futex_down(&async_futex);1356 if (msg->done)1357 amsg_destroy(msg);1358 else1359 msg->forget = true;1360 futex_up(&async_futex);1361 }1362 1285 1363 1286 /** Wait for specified time. … … 1370 1293 void async_usleep(suseconds_t timeout) 1371 1294 { 1372 amsg_t *msg = amsg_create(); 1295 amsg_t *msg = malloc(sizeof(amsg_t)); 1296 1373 1297 if (!msg) 1374 1298 return; 1375 1299 1376 1300 msg->wdata.fid = fibril_get_id(); 1301 msg->wdata.active = false; 1377 1302 1378 1303 gettimeofday(&msg->wdata.to_event.expires, NULL); … … 1388 1313 /* Futex is up automatically after fibril_switch() */ 1389 1314 1390 amsg_destroy(msg);1315 free(msg); 1391 1316 } 1392 1317 … … 1659 1584 ipc_call_t result; 1660 1585 1661 amsg_t *msg = amsg_create();1662 if ( !msg) {1586 amsg_t *msg = malloc(sizeof(amsg_t)); 1587 if (msg == NULL) { 1663 1588 free(sess); 1664 1589 errno = ENOMEM; … … 1666 1591 } 1667 1592 1593 msg->done = false; 1668 1594 msg->dataptr = &result; 1595 1596 msg->wdata.to_event.inlist = false; 1597 1598 /* 1599 * We may sleep in the next method, 1600 * but it will use its own means 1601 */ 1669 1602 msg->wdata.active = true; 1670 1603 … … 1710 1643 ipc_call_t result; 1711 1644 1712 amsg_t *msg = amsg_create();1713 if ( !msg)1645 amsg_t *msg = malloc(sizeof(amsg_t)); 1646 if (msg == NULL) 1714 1647 return ENOENT; 1715 1648 1649 msg->done = false; 1716 1650 msg->dataptr = &result; 1651 1652 msg->wdata.to_event.inlist = false; 1653 1654 /* 1655 * We may sleep in the next method, 1656 * but it will use its own means 1657 */ 1717 1658 msg->wdata.active = true; 1718 1659 … … 2310 2251 IPC_FF_ROUTE_FROM_ME); 2311 2252 if (retval != EOK) { 2312 async_ forget(msg);2253 async_wait_for(msg, NULL); 2313 2254 ipc_answer_0(callid, retval); 2314 2255 return retval; … … 2504 2445 IPC_FF_ROUTE_FROM_ME); 2505 2446 if (retval != EOK) { 2506 async_ forget(msg);2447 async_wait_for(msg, NULL); 2507 2448 ipc_answer_0(callid, retval); 2508 2449 return retval;
Note:
See TracChangeset
for help on using the changeset viewer.