Changeset 230260ac in mainline for uspace/srv/vfs/vfs_register.c


Ignore:
Timestamp:
2009-06-09T22:27:43Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0e31a2b
Parents:
041186f
Message:

Make VFS use the new synchronization for fibrils. Now there should be no (or
only secondary) fibril serialization. Code reorganized not to hold the phone
lock during async_wait_for() in most cases. Tested on ia32. On amd64, VFS
crashes, but I think it is an unrelated problem.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs_register.c

    r041186f r230260ac  
    4646#include <ctype.h>
    4747#include <bool.h>
    48 #include <futex.h>
     48#include <fibril_sync.h>
    4949#include <adt/list.h>
    5050#include <as.h>
     
    5353#include "vfs.h"
    5454
    55 atomic_t fs_head_futex = FUTEX_INITIALIZER;
     55FIBRIL_MUTEX_INITIALIZE(fs_head_lock);
    5656link_t fs_head;
    5757
     
    160160        }
    161161        link_initialize(&fs_info->fs_link);
    162         futex_initialize(&fs_info->phone_futex, 1);
     162        fibril_mutex_initialize(&fs_info->phone_lock);
    163163               
    164164        rc = ipc_data_write_finalize(callid, &fs_info->vfs_info, size);
     
    181181        }
    182182               
    183         futex_down(&fs_head_futex);
    184         fibril_inc_sercount();
     183        fibril_mutex_lock(&fs_head_lock);
    185184
    186185        /*
     
    192191                 */
    193192                dprintf("FS is already registered.\n");
    194                 fibril_dec_sercount();
    195                 futex_up(&fs_head_futex);
     193                fibril_mutex_unlock(&fs_head_lock);
    196194                free(fs_info);
    197195                ipc_answer_0(callid, EEXISTS);
     
    215213                dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
    216214                list_remove(&fs_info->fs_link);
    217                 fibril_dec_sercount();
    218                 futex_up(&fs_head_futex);
     215                fibril_mutex_unlock(&fs_head_lock);
    219216                free(fs_info);
    220217                ipc_answer_0(callid, EINVAL);
     
    234231                dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
    235232                list_remove(&fs_info->fs_link);
    236                 fibril_dec_sercount();
    237                 futex_up(&fs_head_futex);
     233                fibril_mutex_unlock(&fs_head_lock);
    238234                ipc_hangup(fs_info->phone);
    239235                free(fs_info);
     
    249245                dprintf("Client suggests wrong size of PFB, size = %d\n", size);
    250246                list_remove(&fs_info->fs_link);
    251                 fibril_dec_sercount();
    252                 futex_up(&fs_head_futex);
     247                fibril_mutex_unlock(&fs_head_lock);
    253248                ipc_hangup(fs_info->phone);
    254249                free(fs_info);
     
    274269        ipc_answer_1(rid, EOK, (ipcarg_t) fs_info->fs_handle);
    275270       
    276         fibril_dec_sercount();
    277         futex_up(&fs_head_futex);
     271        fibril_mutex_unlock(&fs_head_lock);
    278272       
    279273        dprintf("\"%.*s\" filesystem successfully registered, handle=%d.\n",
     
    298292         * phone_futex and keep it until vfs_release_phone().
    299293         */
    300         futex_down(&fs_head_futex);
     294        fibril_mutex_lock(&fs_head_lock);
    301295        link_t *cur;
    302296        fs_info_t *fs;
     
    304298                fs = list_get_instance(cur, fs_info_t, fs_link);
    305299                if (fs->fs_handle == handle) {
    306                         futex_up(&fs_head_futex);
    307                         /*
    308                          * For now, take the futex unconditionally.
    309                          * Oh yeah, serialization rocks.
    310                          * It will be up'ed in vfs_release_phone().
    311                          */
    312                         futex_down(&fs->phone_futex);
    313                         /*
    314                          * Avoid deadlock with other fibrils in the same thread
    315                          * by disabling fibril preemption.
    316                          */
    317                         fibril_inc_sercount();
     300                        fibril_mutex_unlock(&fs_head_lock);
     301                        fibril_mutex_lock(&fs->phone_lock);
    318302                        return fs->phone;
    319303                }
    320304        }
    321         futex_up(&fs_head_futex);
     305        fibril_mutex_unlock(&fs_head_lock);
    322306        return 0;
    323307}
     
    331315        bool found = false;
    332316
    333         /*
    334          * Undo the fibril_inc_sercount() done in vfs_grab_phone().
    335          */
    336         fibril_dec_sercount();
    337        
    338         futex_down(&fs_head_futex);
     317        fibril_mutex_lock(&fs_head_lock);
    339318        link_t *cur;
    340319        for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
     
    342321                if (fs->phone == phone) {
    343322                        found = true;
    344                         futex_up(&fs_head_futex);
    345                         futex_up(&fs->phone_futex);
     323                        fibril_mutex_unlock(&fs_head_lock);
     324                        fibril_mutex_unlock(&fs->phone_lock);
    346325                        return;
    347326                }
    348327        }
    349         futex_up(&fs_head_futex);
     328        fibril_mutex_unlock(&fs_head_lock);
    350329
    351330        /*
     
    358337 *
    359338 * @param name          File system name.
    360  * @param lock          If true, the function will down and up the
    361  *                      fs_head_futex.
     339 * @param lock          If true, the function will lock and unlock the
     340 *                      fs_head_lock.
    362341 *
    363342 * @return              File system handle or zero if file system not found.
     
    368347       
    369348        if (lock)
    370                 futex_down(&fs_head_futex);
     349                fibril_mutex_lock(&fs_head_lock);
    371350        link_t *cur;
    372351        for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
     
    378357        }
    379358        if (lock)
    380                 futex_up(&fs_head_futex);
     359                fibril_mutex_unlock(&fs_head_lock);
    381360        return handle;
    382361}
Note: See TracChangeset for help on using the changeset viewer.