Changeset 4e1b57d in mainline
- Timestamp:
- 2009-06-17T22:08:05Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ca093b3
- Parents:
- 6ebe721
- Location:
- uspace/lib/libblock
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libblock/libblock.c
r6ebe721 r4e1b57d 47 47 #include <as.h> 48 48 #include <assert.h> 49 #include <f utex.h>49 #include <fibril_sync.h> 50 50 #include <adt/list.h> 51 51 #include <adt/hash_table.h> … … 53 53 54 54 /** Lock protecting the device connection list */ 55 static futex_t dcl_lock = FUTEX_INITIALIZER;55 static FIBRIL_MUTEX_INITIALIZE(dcl_lock); 56 56 /** Device connection list head. */ 57 57 static LIST_INITIALIZE(dcl_head); … … 61 61 62 62 typedef struct { 63 f utex_t lock;63 fibril_mutex_t lock; 64 64 size_t block_size; /**< Block size. */ 65 65 unsigned block_count; /**< Total number of blocks. */ … … 84 84 link_t *cur; 85 85 86 f utex_down(&dcl_lock);86 fibril_mutex_lock(&dcl_lock); 87 87 for (cur = dcl_head.next; cur != &dcl_head; cur = cur->next) { 88 88 devcon_t *devcon = list_get_instance(cur, devcon_t, link); 89 89 if (devcon->dev_handle == dev_handle) { 90 f utex_up(&dcl_lock);90 fibril_mutex_unlock(&dcl_lock); 91 91 return devcon; 92 92 } 93 93 } 94 f utex_up(&dcl_lock);94 fibril_mutex_unlock(&dcl_lock); 95 95 return NULL; 96 96 } … … 116 116 devcon->cache = NULL; 117 117 118 f utex_down(&dcl_lock);118 fibril_mutex_lock(&dcl_lock); 119 119 for (cur = dcl_head.next; cur != &dcl_head; cur = cur->next) { 120 120 devcon_t *d = list_get_instance(cur, devcon_t, link); 121 121 if (d->dev_handle == dev_handle) { 122 f utex_up(&dcl_lock);122 fibril_mutex_unlock(&dcl_lock); 123 123 free(devcon); 124 124 return EEXIST; … … 126 126 } 127 127 list_append(&devcon->link, &dcl_head); 128 f utex_up(&dcl_lock);128 fibril_mutex_unlock(&dcl_lock); 129 129 return EOK; 130 130 } … … 132 132 static void devcon_remove(devcon_t *devcon) 133 133 { 134 f utex_down(&dcl_lock);134 fibril_mutex_lock(&dcl_lock); 135 135 list_remove(&devcon->link); 136 f utex_up(&dcl_lock);136 fibril_mutex_unlock(&dcl_lock); 137 137 } 138 138 … … 263 263 return ENOMEM; 264 264 265 f utex_initialize(&cache->lock, 1);265 fibril_mutex_initialize(&cache->lock); 266 266 list_initialize(&cache->free_head); 267 267 cache->block_size = size; … … 285 285 static void block_initialize(block_t *b) 286 286 { 287 f utex_initialize(&b->lock, 1);287 fibril_mutex_initialize(&b->lock); 288 288 b->refcnt = 1; 289 289 b->dirty = false; 290 rwlock_initialize(&b->contents_lock);290 fibril_rwlock_initialize(&b->contents_lock); 291 291 link_initialize(&b->free_link); 292 292 link_initialize(&b->hash_link); … … 317 317 318 318 cache = devcon->cache; 319 f utex_down(&cache->lock);319 fibril_mutex_lock(&cache->lock); 320 320 l = hash_table_find(&cache->block_hash, &key); 321 321 if (l) { … … 324 324 */ 325 325 b = hash_table_get_instance(l, block_t, hash_link); 326 f utex_down(&b->lock);326 fibril_mutex_lock(&b->lock); 327 327 if (b->refcnt++ == 0) 328 328 list_remove(&b->free_link); 329 f utex_up(&b->lock);330 f utex_up(&cache->lock);329 fibril_mutex_unlock(&b->lock); 330 fibril_mutex_unlock(&cache->lock); 331 331 } else { 332 332 /* … … 379 379 * block. 380 380 */ 381 f utex_down(&b->lock);382 f utex_up(&cache->lock);381 fibril_mutex_lock(&b->lock); 382 fibril_mutex_unlock(&cache->lock); 383 383 384 384 if (sync) { … … 394 394 * the new contents from the device. 395 395 */ 396 async_serialize_start();397 396 rc = block_read(dev_handle, &bufpos, &buflen, &pos, 398 397 b->data, cache->block_size, cache->block_size); 399 async_serialize_end();400 398 assert(rc == EOK); 401 399 } 402 400 403 f utex_up(&b->lock);401 fibril_mutex_unlock(&b->lock); 404 402 } 405 403 return b; … … 421 419 422 420 cache = devcon->cache; 423 f utex_down(&cache->lock);424 f utex_down(&block->lock);421 fibril_mutex_lock(&cache->lock); 422 fibril_mutex_lock(&block->lock); 425 423 if (!--block->refcnt) { 426 424 /* … … 430 428 list_append(&block->free_link, &cache->free_head); 431 429 } 432 f utex_up(&block->lock);433 f utex_up(&cache->lock);430 fibril_mutex_unlock(&block->lock); 431 fibril_mutex_unlock(&cache->lock); 434 432 } 435 433 -
uspace/lib/libblock/libblock.h
r6ebe721 r4e1b57d 40 40 #include <stdint.h> 41 41 #include "../../srv/vfs/vfs.h" 42 #include <futex.h> 43 #include <rwlock.h> 42 #include <fibril_sync.h> 44 43 #include <adt/hash_table.h> 45 44 #include <adt/list.h> … … 64 63 65 64 typedef struct block { 66 /** Futex protecting the reference count. */67 f utex_t lock;65 /** Mutex protecting the reference count. */ 66 fibril_mutex_t lock; 68 67 /** Number of references to the block_t structure. */ 69 68 unsigned refcnt; … … 71 70 bool dirty; 72 71 /** Readers / Writer lock protecting the contents of the block. */ 73 rwlock_t contents_lock;72 fibril_rwlock_t contents_lock; 74 73 /** Handle of the device where the block resides. */ 75 74 dev_handle_t dev_handle;
Note:
See TracChangeset
for help on using the changeset viewer.