Changeset d9e9caf in mainline


Ignore:
Timestamp:
2008-04-15T02:45:48Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
80e8482
Parents:
e13d1feb
Message:

Add a locking scheme for FAT in-core cache and nodes.

Location:
uspace/srv/fs/fat
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat.h

    re13d1feb rd9e9caf  
    148148/** FAT in-core node. */
    149149typedef struct {
     150        /** Protects an instance of this type. */
     151        futex_t                 lock;
    150152        fat_node_type_t         type;
    151153        /** VFS index is the node's first allocated cluster. */
  • uspace/srv/fs/fat/fat_ops.c

    re13d1feb rd9e9caf  
    4747#include <libadt/list.h>
    4848#include <assert.h>
     49#include <futex.h>
    4950
    5051#define BS_BLOCK                0
     
    5253#define FIN_KEY_DEV_HANDLE      0
    5354#define FIN_KEY_INDEX           1
     55
     56/** Futex protecting both fin_hash and ffn_head. */
     57futex_t fin_futex = FUTEX_INITIALIZER;
    5458
    5559/** Hash table of FAT in-core nodes. */
     
    119123static void fat_node_initialize(fat_node_t *node)
    120124{
     125        futex_initialize(&node->lock, 1);
    121126        node->type = 0;
    122127        node->index = 0;
     
    201206        };
    202207
     208        futex_down(&fin_futex);
    203209        lnk = hash_table_find(&fin_hash, key);
    204210        if (lnk) {
     
    209215                if (!node->refcnt++)
    210216                        list_remove(&node->ffn_link);
     217                futex_up(&fin_futex);
     218               
     219                /* Make sure that the node is fully instantiated. */
     220                futex_down(&node->lock);
     221                futex_up(&node->lock);
     222               
    211223                return (void *) node;   
    212224        }
     
    242254        node->index = index;
    243255        node->pindex = pindex;
     256        key[FIN_KEY_DEV_HANDLE] = node->dev_handle;
     257        key[FIN_KEY_INDEX] = node->index;
     258        hash_table_insert(&fin_hash, key, &node->fin_link);
     259
     260        /*
     261         * We have already put the node back to fin_hash.
     262         * The node is not yet fully instantiated so we lock it prior to
     263         * unlocking fin_hash.
     264         */
     265        futex_down(&node->lock);
     266        futex_up(&fin_futex);
    244267
    245268        /*
     
    269292        node->size = uint32_t_le2host(d->size);
    270293        block_put(b);
    271        
    272         key[FIN_KEY_DEV_HANDLE] = node->dev_handle;
    273         key[FIN_KEY_INDEX] = node->index;
    274         hash_table_insert(&fin_hash, key, &node->fin_link);
    275 
     294
     295        futex_up(&node->lock);
    276296        return node;
    277297}
     
    281301        fat_node_t *nodep = (fat_node_t *)node;
    282302
    283         if (nodep->refcnt-- == 1)
     303        futex_down(&fin_futex);
     304        if (!--nodep->refcnt)
    284305                list_append(&nodep->ffn_link, &ffn_head);
     306        futex_up(&fin_futex);
    285307}
    286308
Note: See TracChangeset for help on using the changeset viewer.