Ticket #285: patch

File patch, 15.1 KB (added by Jakub Jermář, 13 years ago)
  • kernel/generic/include/ipc/ipc.h

    === modified file 'kernel/generic/include/ipc/ipc.h'
     
    4343#define IPC_CALL_LEN  6
    4444
    4545/** Maximum active async calls per phone */
    46 #define IPC_MAX_ASYNC_CALLS  4
     46#define IPC_MAX_ASYNC_CALLS     10
    4747
    4848/* Flags for calls */
    4949
  • kernel/generic/src/ipc/ipc.c

    === modified file 'kernel/generic/src/ipc/ipc.c'
     
    705705                                printf("connecting ");
    706706                                break;
    707707                        case IPC_PHONE_CONNECTED:
    708                                 printf("connected to: %p ",
    709                                     task->phones[i].callee);
     708                                printf("connected to: %p (%" PRIu64 ") ",
     709                                    task->phones[i].callee,
     710                                    task->phones[i].callee->task->taskid);
    710711                                break;
    711712                        case IPC_PHONE_SLAMMED:
    712713                                printf("slammed by: %p ",
  • uspace/lib/c/generic/io/vprintf.c

    === modified file 'uspace/lib/c/generic/io/vprintf.c'
     
    3636#include <stdio.h>
    3737#include <unistd.h>
    3838#include <io/printf_core.h>
    39 #include <futex.h>
     39#include <fibril_synch.h>
    4040#include <async.h>
    4141#include <str.h>
    4242
    43 static atomic_t printf_futex = FUTEX_INITIALIZER;
     43static FIBRIL_MUTEX_INITIALIZE(printf_mutex);
    4444
    4545static int vprintf_str_write(const char *str, size_t size, void *stream)
    4646{
     
    8484        /*
    8585         * Prevent other threads to execute printf_core()
    8686         */
    87         futex_down(&printf_futex);
    88        
    89         /*
    90          * Prevent other fibrils of the same thread
    91          * to execute printf_core()
    92          */
    93         async_serialize_start();
     87        fibril_mutex_lock(&printf_mutex);
    9488       
    9589        int ret = printf_core(fmt, &ps, ap);
    9690       
    97         async_serialize_end();
    98         futex_up(&printf_futex);
     91        fibril_mutex_unlock(&printf_mutex);
    9992       
    10093        return ret;
    10194}
  • uspace/lib/c/generic/loader.c

    === modified file 'uspace/lib/c/generic/loader.c'
     
    6262
    6363loader_t *loader_connect(void)
    6464{
    65         int phone_id = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_LOAD, 0, 0);
     65        int phone_id = async_connect_me_to_blocking(PHONE_NS, SERVICE_LOAD, 0, 0);
    6666        if (phone_id < 0)
    6767                return NULL;
    6868       
  • uspace/lib/c/generic/vfs/vfs.c

    === modified file 'uspace/lib/c/generic/vfs/vfs.c'
     
    4545#include <ipc/ipc.h>
    4646#include <ipc/services.h>
    4747#include <async.h>
    48 #include <atomic.h>
    49 #include <futex.h>
     48#include <fibril_synch.h>
    5049#include <errno.h>
    5150#include <str.h>
    5251#include <devmap.h>
    5352#include <ipc/vfs.h>
    5453#include <ipc/devmap.h>
     54#include <assert.h>
    5555
    5656static int vfs_phone = -1;
    57 static futex_t vfs_phone_futex = FUTEX_INITIALIZER;
    58 static futex_t cwd_futex = FUTEX_INITIALIZER;
     57static FIBRIL_MUTEX_INITIALIZE(vfs_phone_mutex);
     58static FIBRIL_MUTEX_INITIALIZE(cwd_mutex);
    5959
    6060static int cwd_fd = -1;
    6161static char *cwd_path = NULL;
    6262static size_t cwd_size = 0;
    6363
     64static void vfs_serialize_start(void)
     65{
     66        fibril_mutex_lock(&vfs_phone_mutex);
     67}
     68
     69static void vfs_serialize_end(void)
     70{
     71        assert(fibril_mutex_is_locked(&vfs_phone_mutex));
     72        fibril_mutex_unlock(&vfs_phone_mutex);
     73}
     74
    6475char *absolutize(const char *path, size_t *retlen)
    6576{
    6677        char *ncwd_path;
    6778        char *ncwd_path_nc;
    6879
    69         futex_down(&cwd_futex);
     80        fibril_mutex_lock(&cwd_mutex);
    7081        size_t size = str_size(path);
    7182        if (*path != '/') {
    7283                if (!cwd_path) {
    73                         futex_up(&cwd_futex);
     84                        fibril_mutex_unlock(&cwd_mutex);
    7485                        return NULL;
    7586                }
    7687                ncwd_path_nc = malloc(cwd_size + 1 + size + 1);
    7788                if (!ncwd_path_nc) {
    78                         futex_up(&cwd_futex);
     89                        fibril_mutex_unlock(&cwd_mutex);
    7990                        return NULL;
    8091                }
    8192                str_cpy(ncwd_path_nc, cwd_size + 1 + size + 1, cwd_path);
     
    8495        } else {
    8596                ncwd_path_nc = malloc(size + 1);
    8697                if (!ncwd_path_nc) {
    87                         futex_up(&cwd_futex);
     98                        fibril_mutex_unlock(&cwd_mutex);
    8899                        return NULL;
    89100                }
    90101                ncwd_path_nc[0] = '\0';
     
    92103        str_append(ncwd_path_nc, cwd_size + 1 + size + 1, path);
    93104        ncwd_path = canonify(ncwd_path_nc, retlen);
    94105        if (!ncwd_path) {
    95                 futex_up(&cwd_futex);
     106                fibril_mutex_unlock(&cwd_mutex);
    96107                free(ncwd_path_nc);
    97108                return NULL;
    98109        }
     
    104115        ncwd_path = str_dup(ncwd_path);
    105116        free(ncwd_path_nc);
    106117        if (!ncwd_path) {
    107                 futex_up(&cwd_futex);
     118                fibril_mutex_unlock(&cwd_mutex);
    108119                return NULL;
    109120        }
    110         futex_up(&cwd_futex);
     121        fibril_mutex_unlock(&cwd_mutex);
    111122        return ncwd_path;
    112123}
    113124
    114125static void vfs_connect(void)
    115126{
     127        assert(fibril_mutex_is_locked(&vfs_phone_mutex));
    116128        while (vfs_phone < 0)
    117129                vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0);
    118130}
     
    153165                return ENOMEM;
    154166        }
    155167       
    156         futex_down(&vfs_phone_futex);
    157         async_serialize_start();
     168        vfs_serialize_start();
    158169        vfs_connect();
    159170       
    160171        sysarg_t rc_orig;
     
    162173        sysarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
    163174        if (rc != EOK) {
    164175                async_wait_for(req, &rc_orig);
    165                 async_serialize_end();
    166                 futex_up(&vfs_phone_futex);
     176                vfs_serialize_end();
    167177                free(mpa);
    168178               
    169179                if (null_id != -1)
     
    178188        rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts));
    179189        if (rc != EOK) {
    180190                async_wait_for(req, &rc_orig);
    181                 async_serialize_end();
    182                 futex_up(&vfs_phone_futex);
     191                vfs_serialize_end();
    183192                free(mpa);
    184193               
    185194                if (null_id != -1)
     
    194203        rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name));
    195204        if (rc != EOK) {
    196205                async_wait_for(req, &rc_orig);
    197                 async_serialize_end();
    198                 futex_up(&vfs_phone_futex);
     206                vfs_serialize_end();
    199207                free(mpa);
    200208               
    201209                if (null_id != -1)
     
    211219        rc = async_req_0_0(vfs_phone, IPC_M_PING);
    212220        if (rc != EOK) {
    213221                async_wait_for(req, &rc_orig);
    214                 async_serialize_end();
    215                 futex_up(&vfs_phone_futex);
     222                vfs_serialize_end();
    216223                free(mpa);
    217224               
    218225                if (null_id != -1)
     
    225232        }
    226233       
    227234        async_wait_for(req, &rc);
    228         async_serialize_end();
    229         futex_up(&vfs_phone_futex);
     235        vfs_serialize_end();
    230236        free(mpa);
    231237       
    232238        if ((rc != EOK) && (null_id != -1))
     
    247253        if (!mpa)
    248254                return ENOMEM;
    249255       
    250         futex_down(&vfs_phone_futex);
    251         async_serialize_start();
     256        vfs_serialize_start();
    252257        vfs_connect();
    253258       
    254259        req = async_send_0(vfs_phone, VFS_IN_UNMOUNT, NULL);
    255260        rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
    256261        if (rc != EOK) {
    257262                async_wait_for(req, &rc_orig);
    258                 async_serialize_end();
    259                 futex_up(&vfs_phone_futex);
     263                vfs_serialize_end();
    260264                free(mpa);
    261265                if (rc_orig == EOK)
    262266                        return (int) rc;
     
    266270       
    267271
    268272        async_wait_for(req, &rc);
    269         async_serialize_end();
    270         futex_up(&vfs_phone_futex);
     273        vfs_serialize_end();
    271274        free(mpa);
    272275       
    273276        return (int) rc;
     
    275278
    276279static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag)
    277280{
    278         futex_down(&vfs_phone_futex);
    279         async_serialize_start();
     281        vfs_serialize_start();
    280282        vfs_connect();
    281283       
    282284        ipc_call_t answer;
     
    287289                sysarg_t rc_orig;
    288290                async_wait_for(req, &rc_orig);
    289291               
    290                 async_serialize_end();
    291                 futex_up(&vfs_phone_futex);
     292                vfs_serialize_end();
    292293               
    293294                if (rc_orig == EOK)
    294295                        return (int) rc;
     
    297298        }
    298299       
    299300        async_wait_for(req, &rc);
    300         async_serialize_end();
    301         futex_up(&vfs_phone_futex);
     301        vfs_serialize_end();
    302302       
    303303        if (rc != EOK)
    304304            return (int) rc;
     
    321321
    322322int open_node(fdi_node_t *node, int oflag)
    323323{
    324         futex_down(&vfs_phone_futex);
    325         async_serialize_start();
     324        vfs_serialize_start();
    326325        vfs_connect();
    327326       
    328327        ipc_call_t answer;
     
    331330       
    332331        sysarg_t rc;
    333332        async_wait_for(req, &rc);
    334         async_serialize_end();
    335         futex_up(&vfs_phone_futex);
     333        vfs_serialize_end();
    336334       
    337335        if (rc != EOK)
    338336                return (int) rc;
     
    344342{
    345343        sysarg_t rc;
    346344       
    347         futex_down(&vfs_phone_futex);
    348         async_serialize_start();
     345        vfs_serialize_start();
    349346        vfs_connect();
    350347       
    351348        rc = async_req_1_0(vfs_phone, VFS_IN_CLOSE, fildes);
    352349       
    353         async_serialize_end();
    354         futex_up(&vfs_phone_futex);
     350        vfs_serialize_end();
    355351       
    356352        return (int)rc;
    357353}
     
    362358        ipc_call_t answer;
    363359        aid_t req;
    364360
    365         futex_down(&vfs_phone_futex);
    366         async_serialize_start();
     361        vfs_serialize_start();
    367362        vfs_connect();
    368363       
    369364        req = async_send_1(vfs_phone, VFS_IN_READ, fildes, &answer);
     
    372367                sysarg_t rc_orig;
    373368       
    374369                async_wait_for(req, &rc_orig);
    375                 async_serialize_end();
    376                 futex_up(&vfs_phone_futex);
     370                vfs_serialize_end();
    377371                if (rc_orig == EOK)
    378372                        return (ssize_t) rc;
    379373                else
    380374                        return (ssize_t) rc_orig;
    381375        }
    382376        async_wait_for(req, &rc);
    383         async_serialize_end();
    384         futex_up(&vfs_phone_futex);
     377        vfs_serialize_end();
    385378        if (rc == EOK)
    386379                return (ssize_t) IPC_GET_ARG1(answer);
    387380        else
     
    394387        ipc_call_t answer;
    395388        aid_t req;
    396389
    397         futex_down(&vfs_phone_futex);
    398         async_serialize_start();
     390        vfs_serialize_start();
    399391        vfs_connect();
    400392       
    401393        req = async_send_1(vfs_phone, VFS_IN_WRITE, fildes, &answer);
     
    404396                sysarg_t rc_orig;
    405397       
    406398                async_wait_for(req, &rc_orig);
    407                 async_serialize_end();
    408                 futex_up(&vfs_phone_futex);
     399                vfs_serialize_end();
    409400                if (rc_orig == EOK)
    410401                        return (ssize_t) rc;
    411402                else
    412403                        return (ssize_t) rc_orig;
    413404        }
    414405        async_wait_for(req, &rc);
    415         async_serialize_end();
    416         futex_up(&vfs_phone_futex);
     406        vfs_serialize_end();
    417407        if (rc == EOK)
    418408                return (ssize_t) IPC_GET_ARG1(answer);
    419409        else
     
    422412
    423413int fsync(int fildes)
    424414{
    425         futex_down(&vfs_phone_futex);
    426         async_serialize_start();
     415        vfs_serialize_start();
    427416        vfs_connect();
    428417       
    429418        sysarg_t rc = async_req_1_0(vfs_phone, VFS_IN_SYNC, fildes);
    430419       
    431         async_serialize_end();
    432         futex_up(&vfs_phone_futex);
     420        vfs_serialize_end();
    433421       
    434422        return (int) rc;
    435423}
    436424
    437425off64_t lseek(int fildes, off64_t offset, int whence)
    438426{
    439         futex_down(&vfs_phone_futex);
    440         async_serialize_start();
     427        vfs_serialize_start();
    441428        vfs_connect();
    442429       
    443430        sysarg_t newoff_lo;
     
    446433            LOWER32(offset), UPPER32(offset), whence,
    447434            &newoff_lo, &newoff_hi);
    448435       
    449         async_serialize_end();
    450         futex_up(&vfs_phone_futex);
     436        vfs_serialize_end();
    451437       
    452438        if (rc != EOK)
    453439                return (off64_t) -1;
     
    459445{
    460446        sysarg_t rc;
    461447       
    462         futex_down(&vfs_phone_futex);
    463         async_serialize_start();
     448        vfs_serialize_start();
    464449        vfs_connect();
    465450       
    466451        rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes,
    467452            LOWER32(length), UPPER32(length));
    468         async_serialize_end();
    469         futex_up(&vfs_phone_futex);
     453        vfs_serialize_end();
    470454       
    471455        return (int) rc;
    472456}
     
    476460        sysarg_t rc;
    477461        aid_t req;
    478462
    479         futex_down(&vfs_phone_futex);
    480         async_serialize_start();
     463        vfs_serialize_start();
    481464        vfs_connect();
    482465       
    483466        req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL);
     
    486469                sysarg_t rc_orig;
    487470               
    488471                async_wait_for(req, &rc_orig);
    489                 async_serialize_end();
    490                 futex_up(&vfs_phone_futex);
     472                vfs_serialize_end();
    491473                if (rc_orig == EOK)
    492474                        return (ssize_t) rc;
    493475                else
    494476                        return (ssize_t) rc_orig;
    495477        }
    496478        async_wait_for(req, &rc);
    497         async_serialize_end();
    498         futex_up(&vfs_phone_futex);
     479        vfs_serialize_end();
    499480
    500481        return rc;
    501482}
     
    511492        if (!pa)
    512493                return ENOMEM;
    513494       
    514         futex_down(&vfs_phone_futex);
    515         async_serialize_start();
     495        vfs_serialize_start();
    516496        vfs_connect();
    517497       
    518498        req = async_send_0(vfs_phone, VFS_IN_STAT, NULL);
    519499        rc = async_data_write_start(vfs_phone, pa, pa_size);
    520500        if (rc != EOK) {
    521501                async_wait_for(req, &rc_orig);
    522                 async_serialize_end();
    523                 futex_up(&vfs_phone_futex);
     502                vfs_serialize_end();
    524503                free(pa);
    525504                if (rc_orig == EOK)
    526505                        return (int) rc;
     
    530509        rc = async_data_read_start(vfs_phone, stat, sizeof(struct stat));
    531510        if (rc != EOK) {
    532511                async_wait_for(req, &rc_orig);
    533                 async_serialize_end();
    534                 futex_up(&vfs_phone_futex);
     512                vfs_serialize_end();
    535513                free(pa);
    536514                if (rc_orig == EOK)
    537515                        return (int) rc;
     
    539517                        return (int) rc_orig;
    540518        }
    541519        async_wait_for(req, &rc);
    542         async_serialize_end();
    543         futex_up(&vfs_phone_futex);
     520        vfs_serialize_end();
    544521        free(pa);
    545522        return rc;
    546523}
     
    600577        if (!pa)
    601578                return ENOMEM;
    602579       
    603         futex_down(&vfs_phone_futex);
    604         async_serialize_start();
     580        vfs_serialize_start();
    605581        vfs_connect();
    606582       
    607583        req = async_send_1(vfs_phone, VFS_IN_MKDIR, mode, NULL);
     
    610586                sysarg_t rc_orig;
    611587       
    612588                async_wait_for(req, &rc_orig);
    613                 async_serialize_end();
    614                 futex_up(&vfs_phone_futex);
     589                vfs_serialize_end();
    615590                free(pa);
    616591                if (rc_orig == EOK)
    617592                        return (int) rc;
     
    619594                        return (int) rc_orig;
    620595        }
    621596        async_wait_for(req, &rc);
    622         async_serialize_end();
    623         futex_up(&vfs_phone_futex);
     597        vfs_serialize_end();
    624598        free(pa);
    625599        return rc;
    626600}
     
    635609        if (!pa)
    636610                return ENOMEM;
    637611
    638         futex_down(&vfs_phone_futex);
    639         async_serialize_start();
     612        vfs_serialize_start();
    640613        vfs_connect();
    641614       
    642615        req = async_send_0(vfs_phone, VFS_IN_UNLINK, NULL);
     
    645618                sysarg_t rc_orig;
    646619
    647620                async_wait_for(req, &rc_orig);
    648                 async_serialize_end();
    649                 futex_up(&vfs_phone_futex);
     621                vfs_serialize_end();
    650622                free(pa);
    651623                if (rc_orig == EOK)
    652624                        return (int) rc;
     
    654626                        return (int) rc_orig;
    655627        }
    656628        async_wait_for(req, &rc);
    657         async_serialize_end();
    658         futex_up(&vfs_phone_futex);
     629        vfs_serialize_end();
    659630        free(pa);
    660631        return rc;
    661632}
     
    688659                return ENOMEM;
    689660        }
    690661
    691         futex_down(&vfs_phone_futex);
    692         async_serialize_start();
     662        vfs_serialize_start();
    693663        vfs_connect();
    694664       
    695665        req = async_send_0(vfs_phone, VFS_IN_RENAME, NULL);
    696666        rc = async_data_write_start(vfs_phone, olda, olda_size);
    697667        if (rc != EOK) {
    698668                async_wait_for(req, &rc_orig);
    699                 async_serialize_end();
    700                 futex_up(&vfs_phone_futex);
     669                vfs_serialize_end();
    701670                free(olda);
    702671                free(newa);
    703672                if (rc_orig == EOK)
     
    708677        rc = async_data_write_start(vfs_phone, newa, newa_size);
    709678        if (rc != EOK) {
    710679                async_wait_for(req, &rc_orig);
    711                 async_serialize_end();
    712                 futex_up(&vfs_phone_futex);
     680                vfs_serialize_end();
    713681                free(olda);
    714682                free(newa);
    715683                if (rc_orig == EOK)
     
    718686                        return (int) rc_orig;
    719687        }
    720688        async_wait_for(req, &rc);
    721         async_serialize_end();
    722         futex_up(&vfs_phone_futex);
     689        vfs_serialize_end();
    723690        free(olda);
    724691        free(newa);
    725692        return rc;
     
    739706                return ENOENT;
    740707        }
    741708       
    742         futex_down(&cwd_futex);
     709        fibril_mutex_lock(&cwd_mutex);
    743710       
    744711        if (cwd_fd >= 0)
    745712                close(cwd_fd);
     
    752719        cwd_path = abs;
    753720        cwd_size = abs_size;
    754721       
    755         futex_up(&cwd_futex);
     722        fibril_mutex_unlock(&cwd_mutex);
    756723        return EOK;
    757724}
    758725
     
    761728        if (size == 0)
    762729                return NULL;
    763730       
    764         futex_down(&cwd_futex);
     731        fibril_mutex_lock(&cwd_mutex);
    765732       
    766733        if ((cwd_size == 0) || (size < cwd_size + 1)) {
    767                 futex_up(&cwd_futex);
     734                fibril_mutex_unlock(&cwd_mutex);
    768735                return NULL;
    769736        }
    770737       
    771738        str_cpy(buf, size, cwd_path);
    772         futex_up(&cwd_futex);
     739        fibril_mutex_unlock(&cwd_mutex);
    773740       
    774741        return buf;
    775742}
     
    805772
    806773int dup2(int oldfd, int newfd)
    807774{
    808         futex_down(&vfs_phone_futex);
    809         async_serialize_start();
     775        vfs_serialize_start();
    810776        vfs_connect();
    811777       
    812778        sysarg_t ret;
    813779        sysarg_t rc = async_req_2_1(vfs_phone, VFS_IN_DUP, oldfd, newfd, &ret);
    814780       
    815         async_serialize_end();
    816         futex_up(&vfs_phone_futex);
     781        vfs_serialize_end();
    817782       
    818783        if (rc == EOK)
    819784                return (int) ret;
  • uspace/srv/devman/devman.c

    === modified file 'uspace/srv/devman/devman.c'
     
    784784        if (is_running) {
    785785                /* Notify the driver about the new device. */
    786786                int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
    787                 if (phone > 0) {
     787                if (phone >= 0) {
    788788                        add_device(phone, drv, node, tree);
    789789                        ipc_hangup(phone);
    790790                }