Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/async.c

    rab9f443 rf302586  
    189189        /** If reply was received. */
    190190        bool done;
    191 
    192         /** If the message / reply should be discarded on arrival. */
    193         bool forget;
    194 
    195         /** If already destroyed. */
    196         bool destroyed;
    197191       
    198192        /** Pointer to where the answer data is stored. */
     
    246240/** Identifier of the incoming connection handled by the current fibril. */
    247241static 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 }
    296242
    297243static void *default_client_data_constructor(void)
     
    11541100       
    11551101        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) {
    11611103                msg->wdata.active = true;
    11621104                fibril_add_ready(msg->wdata.fid);
    11631105        }
    1164 
     1106       
    11651107        futex_up(&async_futex);
    11661108}
     
    11891131                return 0;
    11901132       
    1191         amsg_t *msg = amsg_create();
     1133        amsg_t *msg = malloc(sizeof(amsg_t));
    11921134        if (msg == NULL)
    11931135                return 0;
    11941136       
     1137        msg->done = false;
    11951138        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         */
    11961146        msg->wdata.active = true;
    11971147       
     
    12271177                return 0;
    12281178       
    1229         amsg_t *msg = amsg_create();
     1179        amsg_t *msg = malloc(sizeof(amsg_t));
     1180       
    12301181        if (msg == NULL)
    12311182                return 0;
    12321183       
     1184        msg->done = false;
    12331185        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         */
    12341193        msg->wdata.active = true;
    12351194       
     
    12541213       
    12551214        futex_down(&async_futex);
    1256 
    1257         assert(!msg->forget);
    1258         assert(!msg->destroyed);
    1259 
    12601215        if (msg->done) {
    12611216                futex_up(&async_futex);
     
    12761231                *retval = msg->retval;
    12771232       
    1278         amsg_destroy(msg);
     1233        free(msg);
    12791234}
    12801235
    12811236/** 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 calling
    1284  * async_wait_for() or async_wait_timeout(), or forget the message via
    1285  * async_forget().
    12861237 *
    12871238 * @param amsgid  Hash of the message to wait for.
     
    13041255       
    13051256        futex_down(&async_futex);
    1306 
    1307         assert(!msg->forget);
    1308         assert(!msg->destroyed);
    1309 
    13101257        if (msg->done) {
    13111258                futex_up(&async_futex);
     
    13321279                *retval = msg->retval;
    13331280       
    1334         amsg_destroy(msg);
     1281        free(msg);
    13351282       
    13361283        return 0;
    13371284}
    1338  
    1339 /** Discard the message / reply on arrival.
    1340  *
    1341  * The message will be marked to be discarded once the reply arrives in
    1342  * reply_received(). It is not allowed to call async_wait_for() or
    1343  * 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         else
    1359                 msg->forget = true;
    1360         futex_up(&async_futex);
    1361 }
    13621285
    13631286/** Wait for specified time.
     
    13701293void async_usleep(suseconds_t timeout)
    13711294{
    1372         amsg_t *msg = amsg_create();
     1295        amsg_t *msg = malloc(sizeof(amsg_t));
     1296       
    13731297        if (!msg)
    13741298                return;
    13751299       
    13761300        msg->wdata.fid = fibril_get_id();
     1301        msg->wdata.active = false;
    13771302       
    13781303        gettimeofday(&msg->wdata.to_event.expires, NULL);
     
    13881313        /* Futex is up automatically after fibril_switch() */
    13891314       
    1390         amsg_destroy(msg);
     1315        free(msg);
    13911316}
    13921317
     
    16591584        ipc_call_t result;
    16601585       
    1661         amsg_t *msg = amsg_create();
    1662         if (!msg) {
     1586        amsg_t *msg = malloc(sizeof(amsg_t));
     1587        if (msg == NULL) {
    16631588                free(sess);
    16641589                errno = ENOMEM;
     
    16661591        }
    16671592       
     1593        msg->done = false;
    16681594        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         */
    16691602        msg->wdata.active = true;
    16701603       
     
    17101643        ipc_call_t result;
    17111644       
    1712         amsg_t *msg = amsg_create();
    1713         if (!msg)
     1645        amsg_t *msg = malloc(sizeof(amsg_t));
     1646        if (msg == NULL)
    17141647                return ENOENT;
    17151648       
     1649        msg->done = false;
    17161650        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         */
    17171658        msg->wdata.active = true;
    17181659       
     
    23102251            IPC_FF_ROUTE_FROM_ME);
    23112252        if (retval != EOK) {
    2312                 async_forget(msg);
     2253                async_wait_for(msg, NULL);
    23132254                ipc_answer_0(callid, retval);
    23142255                return retval;
     
    25042445            IPC_FF_ROUTE_FROM_ME);
    25052446        if (retval != EOK) {
    2506                 async_forget(msg);
     2447                async_wait_for(msg, NULL);
    25072448                ipc_answer_0(callid, retval);
    25082449                return retval;
Note: See TracChangeset for help on using the changeset viewer.