Changeset 4e1b57d in mainline


Ignore:
Timestamp:
2009-06-17T22:08:05Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ca093b3
Parents:
6ebe721
Message:

Use fibril synchronization in libblock.

Location:
uspace/lib/libblock
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libblock/libblock.c

    r6ebe721 r4e1b57d  
    4747#include <as.h>
    4848#include <assert.h>
    49 #include <futex.h>
     49#include <fibril_sync.h>
    5050#include <adt/list.h>
    5151#include <adt/hash_table.h>
     
    5353
    5454/** Lock protecting the device connection list */
    55 static futex_t dcl_lock = FUTEX_INITIALIZER;
     55static FIBRIL_MUTEX_INITIALIZE(dcl_lock);
    5656/** Device connection list head. */
    5757static LIST_INITIALIZE(dcl_head);
     
    6161
    6262typedef struct {
    63         futex_t lock;
     63        fibril_mutex_t lock;
    6464        size_t block_size;              /**< Block size. */
    6565        unsigned block_count;           /**< Total number of blocks. */
     
    8484        link_t *cur;
    8585
    86         futex_down(&dcl_lock);
     86        fibril_mutex_lock(&dcl_lock);
    8787        for (cur = dcl_head.next; cur != &dcl_head; cur = cur->next) {
    8888                devcon_t *devcon = list_get_instance(cur, devcon_t, link);
    8989                if (devcon->dev_handle == dev_handle) {
    90                         futex_up(&dcl_lock);
     90                        fibril_mutex_unlock(&dcl_lock);
    9191                        return devcon;
    9292                }
    9393        }
    94         futex_up(&dcl_lock);
     94        fibril_mutex_unlock(&dcl_lock);
    9595        return NULL;
    9696}
     
    116116        devcon->cache = NULL;
    117117
    118         futex_down(&dcl_lock);
     118        fibril_mutex_lock(&dcl_lock);
    119119        for (cur = dcl_head.next; cur != &dcl_head; cur = cur->next) {
    120120                devcon_t *d = list_get_instance(cur, devcon_t, link);
    121121                if (d->dev_handle == dev_handle) {
    122                         futex_up(&dcl_lock);
     122                        fibril_mutex_unlock(&dcl_lock);
    123123                        free(devcon);
    124124                        return EEXIST;
     
    126126        }
    127127        list_append(&devcon->link, &dcl_head);
    128         futex_up(&dcl_lock);
     128        fibril_mutex_unlock(&dcl_lock);
    129129        return EOK;
    130130}
     
    132132static void devcon_remove(devcon_t *devcon)
    133133{
    134         futex_down(&dcl_lock);
     134        fibril_mutex_lock(&dcl_lock);
    135135        list_remove(&devcon->link);
    136         futex_up(&dcl_lock);
     136        fibril_mutex_unlock(&dcl_lock);
    137137}
    138138
     
    263263                return ENOMEM;
    264264       
    265         futex_initialize(&cache->lock, 1);
     265        fibril_mutex_initialize(&cache->lock);
    266266        list_initialize(&cache->free_head);
    267267        cache->block_size = size;
     
    285285static void block_initialize(block_t *b)
    286286{
    287         futex_initialize(&b->lock, 1);
     287        fibril_mutex_initialize(&b->lock);
    288288        b->refcnt = 1;
    289289        b->dirty = false;
    290         rwlock_initialize(&b->contents_lock);
     290        fibril_rwlock_initialize(&b->contents_lock);
    291291        link_initialize(&b->free_link);
    292292        link_initialize(&b->hash_link);
     
    317317       
    318318        cache = devcon->cache;
    319         futex_down(&cache->lock);
     319        fibril_mutex_lock(&cache->lock);
    320320        l = hash_table_find(&cache->block_hash, &key);
    321321        if (l) {
     
    324324                 */
    325325                b = hash_table_get_instance(l, block_t, hash_link);
    326                 futex_down(&b->lock);
     326                fibril_mutex_lock(&b->lock);
    327327                if (b->refcnt++ == 0)
    328328                        list_remove(&b->free_link);
    329                 futex_up(&b->lock);
    330                 futex_up(&cache->lock);
     329                fibril_mutex_unlock(&b->lock);
     330                fibril_mutex_unlock(&cache->lock);
    331331        } else {
    332332                /*
     
    379379                 * block.
    380380                 */
    381                 futex_down(&b->lock);
    382                 futex_up(&cache->lock);
     381                fibril_mutex_lock(&b->lock);
     382                fibril_mutex_unlock(&cache->lock);
    383383
    384384                if (sync) {
     
    394394                         * the new contents from the device.
    395395                         */
    396                         async_serialize_start();
    397396                        rc = block_read(dev_handle, &bufpos, &buflen, &pos,
    398397                            b->data, cache->block_size, cache->block_size);
    399                         async_serialize_end();
    400398                        assert(rc == EOK);
    401399                }
    402400
    403                 futex_up(&b->lock);
     401                fibril_mutex_unlock(&b->lock);
    404402        }
    405403        return b;
     
    421419
    422420        cache = devcon->cache;
    423         futex_down(&cache->lock);
    424         futex_down(&block->lock);
     421        fibril_mutex_lock(&cache->lock);
     422        fibril_mutex_lock(&block->lock);
    425423        if (!--block->refcnt) {
    426424                /*
     
    430428                list_append(&block->free_link, &cache->free_head);
    431429        }
    432         futex_up(&block->lock);
    433         futex_up(&cache->lock);
     430        fibril_mutex_unlock(&block->lock);
     431        fibril_mutex_unlock(&cache->lock);
    434432}
    435433
  • uspace/lib/libblock/libblock.h

    r6ebe721 r4e1b57d  
    4040#include <stdint.h>
    4141#include "../../srv/vfs/vfs.h"
    42 #include <futex.h>
    43 #include <rwlock.h>
     42#include <fibril_sync.h>
    4443#include <adt/hash_table.h>
    4544#include <adt/list.h>
     
    6463
    6564typedef struct block {
    66         /** Futex protecting the reference count. */
    67         futex_t lock;
     65        /** Mutex protecting the reference count. */
     66        fibril_mutex_t lock;
    6867        /** Number of references to the block_t structure. */
    6968        unsigned refcnt;
     
    7170        bool dirty;
    7271        /** Readers / Writer lock protecting the contents of the block. */
    73         rwlock_t contents_lock;
     72        fibril_rwlock_t contents_lock;
    7473        /** Handle of the device where the block resides. */
    7574        dev_handle_t dev_handle;
Note: See TracChangeset for help on using the changeset viewer.