Changeset 9413c0d in mainline


Ignore:
Timestamp:
2008-01-06T12:50:51Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b3c38750
Parents:
f57f8ea
Message:

Add basic rwlock API for uspace so that VFS can be designed/implemented using
this API. So far, the implementation of this API merely wraps futexes into
rwlocks. Real rwlocks are wanted by ticket #54.

Using the new rwlock API, replace the VFS node content futex with an rwlock.
Lock the contents rwlock as reader on reads and as writer on writes.

Location:
uspace
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs.h

    rf57f8ea r9413c0d  
    3737#include <libadt/list.h>
    3838#include <atomic.h>
     39#include <rwlock.h>
    3940#include <sys/types.h>
    4041#include <bool.h>
     
    136137        link_t nh_link;         /**< Node hash-table link. */
    137138
    138         /** Holding this futex prevents modifications of the node's contents. */
    139         atomic_t contents_futex;
     139        /** Holding this rwlock prevents modifications of the node's contents. */
     140        atomic_t contents_rwlock;
    140141} vfs_node_t;
    141142
  • uspace/srv/vfs/vfs_node.c

    rf57f8ea r9413c0d  
    4141#include <atomic.h>
    4242#include <futex.h>
     43#include <rwlock.h>
    4344#include <libadt/hash_table.h>
    4445
     
    147148                node->index = triplet->index;
    148149                link_initialize(&node->nh_link);
    149                 futex_initialize(&node->contents_futex, 1);
     150                rwlock_initialize(&node->contents_rwlock);
    150151                hash_table_insert(&nodes, key, &node->nh_link);
    151152        } else {
  • uspace/srv/vfs/vfs_rdwr.c

    rf57f8ea r9413c0d  
    4040#include <async.h>
    4141#include <errno.h>
    42 #include <futex.h>
     42#include <rwlock.h>
    4343
    4444static void vfs_rdwr(ipc_callid_t rid, ipc_call_t *request, bool read)
     
    8686         * the same time.
    8787         */
    88         futex_down(&file->node->contents_futex);
     88        if (read)
     89                rwlock_reader_lock(&file->node->contents_rwlock);
     90        else
     91                rwlock_writer_lock(&file->node->contents_rwlock);
    8992
    9093        int fs_phone = vfs_grab_phone(file->node->fs_handle);   
     
    118121         * Unlock the VFS node.
    119122         */
    120         futex_up(&file->node->contents_futex);
     123        if (read)
     124                rwlock_reader_unlock(&file->node->contents_rwlock);
     125        else
     126                rwlock_writer_unlock(&file->node->contents_rwlock);
    121127
    122128        /*
Note: See TracChangeset for help on using the changeset viewer.