Changeset 831507b in mainline for uspace


Ignore:
Timestamp:
2012-04-14T14:00:02Z (14 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b6d7b7c
Parents:
1fff583 (diff), 1db6dfd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline

Location:
uspace
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tester/Makefile

    r1fff583 r831507b  
    5050        vfs/vfs1.c \
    5151        ipc/ping_pong.c \
     52        ipc/starve.c \
    5253        loop/loop1.c \
    5354        mm/common.c \
  • uspace/app/tester/tester.c

    r1fff583 r831507b  
    6060#include "vfs/vfs1.def"
    6161#include "ipc/ping_pong.def"
     62#include "ipc/starve.def"
    6263#include "loop/loop1.def"
    6364#include "mm/malloc1.def"
  • uspace/app/tester/tester.h

    r1fff583 r831507b  
    9393extern const char *test_vfs1(void);
    9494extern const char *test_ping_pong(void);
     95extern const char *test_starve_ipc(void);
    9596extern const char *test_loop1(void);
    9697extern const char *test_malloc1(void);
  • uspace/lib/c/generic/async.c

    r1fff583 r831507b  
    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;
    191197       
    192198        /** Pointer to where the answer data is stored. */
     
    240246/** Identifier of the incoming connection handled by the current fibril. */
    241247static fibril_local connection_t *fibril_connection;
     248
     249static void to_event_initialize(to_event_t *to)
     250{
     251        struct timeval tv = { 0, 0 };
     252
     253        to->inlist = false;
     254        to->occurred = false;
     255        link_initialize(&to->link);
     256        to->expires = tv;
     257}
     258
     259static void wu_event_initialize(wu_event_t *wu)
     260{
     261        wu->inlist = false;
     262        link_initialize(&wu->link);
     263}
     264
     265void 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
     273static 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
     290static void amsg_destroy(amsg_t *msg)
     291{
     292        assert(!msg->destroyed);
     293        msg->destroyed = true;
     294        free(msg);
     295}
    242296
    243297static void *default_client_data_constructor(void)
     
    9631017               
    9641018                suseconds_t timeout;
     1019                unsigned int flags = SYNCH_FLAGS_NONE;
    9651020                if (!list_empty(&timeout_list)) {
    9661021                        awaiter_t *waiter = list_get_instance(
     
    9731028                                futex_up(&async_futex);
    9741029                                handle_expired_timeouts();
    975                                 continue;
    976                         } else
     1030                                /*
     1031                                 * Notice that even if the event(s) already
     1032                                 * expired (and thus the other fibril was
     1033                                 * supposed to be running already),
     1034                                 * we check for incoming IPC.
     1035                                 *
     1036                                 * Otherwise, a fibril that continuously
     1037                                 * creates (almost) expired events could
     1038                                 * prevent IPC retrieval from the kernel.
     1039                                 */
     1040                                timeout = 0;
     1041                                flags = SYNCH_FLAGS_NON_BLOCKING;
     1042
     1043                        } else {
    9771044                                timeout = tv_sub(&waiter->to_event.expires, &tv);
    978                 } else
     1045                                futex_up(&async_futex);
     1046                        }
     1047                } else {
     1048                        futex_up(&async_futex);
    9791049                        timeout = SYNCH_NO_TIMEOUT;
    980                
    981                 futex_up(&async_futex);
     1050                }
    9821051               
    9831052                atomic_inc(&threads_in_ipc_wait);
    9841053               
    9851054                ipc_call_t call;
    986                 ipc_callid_t callid = ipc_wait_cycle(&call, timeout,
    987                     SYNCH_FLAGS_NONE);
     1055                ipc_callid_t callid = ipc_wait_cycle(&call, timeout, flags);
    9881056               
    9891057                atomic_dec(&threads_in_ipc_wait);
     
    11001168       
    11011169        msg->done = true;
    1102         if (!msg->wdata.active) {
     1170
     1171        if (msg->forget) {
     1172                assert(msg->wdata.active);
     1173                amsg_destroy(msg);
     1174        } else if (!msg->wdata.active) {
    11031175                msg->wdata.active = true;
    11041176                fibril_add_ready(msg->wdata.fid);
    11051177        }
    1106        
     1178
    11071179        futex_up(&async_futex);
    11081180}
     
    11311203                return 0;
    11321204       
    1133         amsg_t *msg = malloc(sizeof(amsg_t));
     1205        amsg_t *msg = amsg_create();
    11341206        if (msg == NULL)
    11351207                return 0;
    11361208       
    1137         msg->done = false;
    11381209        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          */
    11461210        msg->wdata.active = true;
    11471211       
     
    11771241                return 0;
    11781242       
    1179         amsg_t *msg = malloc(sizeof(amsg_t));
    1180        
     1243        amsg_t *msg = amsg_create();
    11811244        if (msg == NULL)
    11821245                return 0;
    11831246       
    1184         msg->done = false;
    11851247        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          */
    11931248        msg->wdata.active = true;
    11941249       
     
    12131268       
    12141269        futex_down(&async_futex);
     1270
     1271        assert(!msg->forget);
     1272        assert(!msg->destroyed);
     1273
    12151274        if (msg->done) {
    12161275                futex_up(&async_futex);
     
    12311290                *retval = msg->retval;
    12321291       
    1233         free(msg);
     1292        amsg_destroy(msg);
    12341293}
    12351294
    12361295/** Wait for a message sent by the async framework, timeout variant.
     1296 *
     1297 * If the wait times out, the caller may choose to either wait again by calling
     1298 * async_wait_for() or async_wait_timeout(), or forget the message via
     1299 * async_forget().
    12371300 *
    12381301 * @param amsgid  Hash of the message to wait for.
     
    12491312       
    12501313        amsg_t *msg = (amsg_t *) amsgid;
    1251        
    1252         /* TODO: Let it go through the event read at least once */
    1253         if (timeout < 0)
    1254                 return ETIMEOUT;
    1255        
     1314
    12561315        futex_down(&async_futex);
     1316
     1317        assert(!msg->forget);
     1318        assert(!msg->destroyed);
     1319
    12571320        if (msg->done) {
    12581321                futex_up(&async_futex);
     
    12601323        }
    12611324       
     1325        /*
     1326         * Negative timeout is converted to zero timeout to avoid
     1327         * using tv_add with negative augmenter.
     1328         */
     1329        if (timeout < 0)
     1330                timeout = 0;
     1331
    12621332        gettimeofday(&msg->wdata.to_event.expires, NULL);
    12631333        tv_add(&msg->wdata.to_event.expires, timeout);
    12641334       
     1335        /*
     1336         * Current fibril is inserted as waiting regardless of the
     1337         * "size" of the timeout.
     1338         *
     1339         * Checking for msg->done and immediately bailing out when
     1340         * timeout == 0 would mean that the manager fibril would never
     1341         * run (consider single threaded program).
     1342         * Thus the IPC answer would be never retrieved from the kernel.
     1343         *
     1344         * Notice that the actual delay would be very small because we
     1345         * - switch to manager fibril
     1346         * - the manager sees expired timeout
     1347         * - and thus adds us back to ready queue
     1348         * - manager switches back to some ready fibril
     1349         *   (prior it, it checks for incoming IPC).
     1350         *
     1351         */
    12651352        msg->wdata.fid = fibril_get_id();
    12661353        msg->wdata.active = false;
     
    12791366                *retval = msg->retval;
    12801367       
    1281         free(msg);
     1368        amsg_destroy(msg);
    12821369       
    12831370        return 0;
    12841371}
     1372 
     1373/** Discard the message / reply on arrival.
     1374 *
     1375 * The message will be marked to be discarded once the reply arrives in
     1376 * reply_received(). It is not allowed to call async_wait_for() or
     1377 * async_wait_timeout() on this message after a call to this function.
     1378 *
     1379 * @param amsgid  Hash of the message to forget.
     1380 */
     1381void async_forget(aid_t amsgid)
     1382{
     1383        amsg_t *msg = (amsg_t *) amsgid;
     1384
     1385        assert(msg);
     1386        assert(!msg->forget);
     1387        assert(!msg->destroyed);
     1388
     1389        futex_down(&async_futex);
     1390        if (msg->done)
     1391                amsg_destroy(msg);
     1392        else
     1393                msg->forget = true;
     1394        futex_up(&async_futex);
     1395}
    12851396
    12861397/** Wait for specified time.
     
    12931404void async_usleep(suseconds_t timeout)
    12941405{
    1295         amsg_t *msg = malloc(sizeof(amsg_t));
    1296        
     1406        amsg_t *msg = amsg_create();
    12971407        if (!msg)
    12981408                return;
    12991409       
    13001410        msg->wdata.fid = fibril_get_id();
    1301         msg->wdata.active = false;
    13021411       
    13031412        gettimeofday(&msg->wdata.to_event.expires, NULL);
     
    13131422        /* Futex is up automatically after fibril_switch() */
    13141423       
    1315         free(msg);
     1424        amsg_destroy(msg);
    13161425}
    13171426
     
    15841693        ipc_call_t result;
    15851694       
    1586         amsg_t *msg = malloc(sizeof(amsg_t));
    1587         if (msg == NULL) {
     1695        amsg_t *msg = amsg_create();
     1696        if (!msg) {
    15881697                free(sess);
    15891698                errno = ENOMEM;
     
    15911700        }
    15921701       
    1593         msg->done = false;
    15941702        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          */
    16021703        msg->wdata.active = true;
    16031704       
     
    16431744        ipc_call_t result;
    16441745       
    1645         amsg_t *msg = malloc(sizeof(amsg_t));
    1646         if (msg == NULL)
     1746        amsg_t *msg = amsg_create();
     1747        if (!msg)
    16471748                return ENOENT;
    16481749       
    1649         msg->done = false;
    16501750        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          */
    16581751        msg->wdata.active = true;
    16591752       
     
    22512344            IPC_FF_ROUTE_FROM_ME);
    22522345        if (retval != EOK) {
    2253                 async_wait_for(msg, NULL);
     2346                async_forget(msg);
    22542347                ipc_answer_0(callid, retval);
    22552348                return retval;
     
    24452538            IPC_FF_ROUTE_FROM_ME);
    24462539        if (retval != EOK) {
    2447                 async_wait_for(msg, NULL);
     2540                async_forget(msg);
    24482541                ipc_answer_0(callid, retval);
    24492542                return retval;
  • uspace/lib/c/generic/fibril_synch.c

    r1fff583 r831507b  
    112112                awaiter_t wdata;
    113113
     114                awaiter_initialize(&wdata);
    114115                wdata.fid = fibril_get_id();
    115                 wdata.active = false;
    116116                wdata.wu_event.inlist = true;
    117                 link_initialize(&wdata.wu_event.link);
    118117                list_append(&wdata.wu_event.link, &fm->waiters);
    119118                check_for_deadlock(&fm->oi);
     
    205204                awaiter_t wdata;
    206205
     206                awaiter_initialize(&wdata);
    207207                wdata.fid = (fid_t) f;
    208                 wdata.active = false;
    209208                wdata.wu_event.inlist = true;
    210                 link_initialize(&wdata.wu_event.link);
    211209                f->flags &= ~FIBRIL_WRITER;
    212210                list_append(&wdata.wu_event.link, &frw->waiters);
     
    233231                awaiter_t wdata;
    234232
     233                awaiter_initialize(&wdata);
    235234                wdata.fid = (fid_t) f;
    236                 wdata.active = false;
    237235                wdata.wu_event.inlist = true;
    238                 link_initialize(&wdata.wu_event.link);
    239236                f->flags |= FIBRIL_WRITER;
    240237                list_append(&wdata.wu_event.link, &frw->waiters);
     
    375372                return ETIMEOUT;
    376373
     374        awaiter_initialize(&wdata);
    377375        wdata.fid = fibril_get_id();
    378         wdata.active = false;
    379        
    380376        wdata.to_event.inlist = timeout > 0;
    381         wdata.to_event.occurred = false;
    382         link_initialize(&wdata.to_event.link);
    383 
    384377        wdata.wu_event.inlist = true;
    385         link_initialize(&wdata.wu_event.link);
    386378
    387379        futex_down(&async_futex);
  • uspace/lib/c/generic/private/async.h

    r1fff583 r831507b  
    8181} awaiter_t;
    8282
     83extern void awaiter_initialize(awaiter_t *);
     84
    8385extern void __async_init(void);
    8486extern void async_insert_timeout(awaiter_t *);
  • uspace/lib/c/include/async.h

    r1fff583 r831507b  
    139139extern void async_wait_for(aid_t, sysarg_t *);
    140140extern int async_wait_timeout(aid_t, sysarg_t *, suseconds_t);
     141extern void async_forget(aid_t);
    141142
    142143extern fid_t async_new_connection(task_id_t, sysarg_t, ipc_callid_t,
  • uspace/srv/fs/fat/fat_dentry.c

    r1fff583 r831507b  
    334334        while (i < count) {
    335335                if ((ch = str_decode(src, &off, STR_NO_LIMIT)) != 0) {
    336                         if (ascii_check(ch) & IS_D_CHAR(ch))
     336                        if (ascii_check(ch) && IS_D_CHAR(ch))
    337337                                *dst = toupper(ch);
    338338                        else
  • uspace/srv/fs/fat/fat_directory.c

    r1fff583 r831507b  
    162162        int rc;
    163163
     164        void *data;
     165        fat_instance_t *instance;
     166
     167        rc = fs_instance_get(di->nodep->idx->service_id, &data);
     168        assert(rc == EOK);
     169        instance = (fat_instance_t *) data;
     170       
    164171        do {
    165172                rc = fat_directory_get(di, &d);
     
    177184                                long_entry_count--;
    178185                                if ((FAT_LFN_ORDER(d) == long_entry_count) &&
    179                                         (checksum == FAT_LFN_CHKSUM(d))) {
     186                                    (checksum == FAT_LFN_CHKSUM(d))) {
    180187                                        /* Right order! */
    181188                                        fat_lfn_get_entry(d, wname,
     
    189196                                        long_entry = false;
    190197                                }
    191                         } else if (FAT_IS_LFN(d)) {
     198                        } else if (FAT_IS_LFN(d) && instance->lfn_enabled) {
    192199                                /* We found Last long entry! */
    193200                                if (FAT_LFN_COUNT(d) <= FAT_LFN_MAX_COUNT) {
     
    308315                checksum = fat_dentry_chksum(de->name);
    309316
    310                 rc = fat_directory_seek(di, start_pos+long_entry_count);
     317                rc = fat_directory_seek(di, start_pos + long_entry_count);
    311318                if (rc != EOK)
    312319                        return rc;
Note: See TracChangeset for help on using the changeset viewer.