Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/synch/futex.c

    r82cbf8c6 r38dc82d  
    6161 */
    6262
    63 #include <assert.h>
    6463#include <synch/futex.h>
    6564#include <synch/mutex.h>
     
    7473#include <genarch/mm/page_ht.h>
    7574#include <adt/cht.h>
    76 #include <adt/hash.h>
    7775#include <adt/hash_table.h>
    7876#include <adt/list.h>
     
    8179#include <panic.h>
    8280#include <errno.h>
     81
     82#define FUTEX_HT_SIZE   1024    /* keep it a power of 2 */
    8383
    8484/** Task specific pointer to a global kernel futex object. */
     
    107107static bool find_futex_paddr(uintptr_t uaddr, uintptr_t *phys_addr);
    108108
    109 static size_t futex_ht_hash(const ht_link_t *item);
    110 static size_t futex_ht_key_hash(void *key);
    111 static bool futex_ht_key_equal(void *key, const ht_link_t *item);
    112 static void futex_ht_remove_callback(ht_link_t *item);
     109static size_t futex_ht_hash(sysarg_t *key);
     110static bool futex_ht_compare(sysarg_t *key, size_t keys, link_t *item);
     111static void futex_ht_remove_callback(link_t *item);
    113112
    114113static size_t task_fut_ht_hash(const cht_link_t *link);
     
    131130
    132131/** Global kernel futex hash table operations. */
    133 static hash_table_ops_t futex_ht_ops = {
     132static hash_table_operations_t futex_ht_ops = {
    134133        .hash = futex_ht_hash,
    135         .key_hash = futex_ht_key_hash,
    136         .key_equal = futex_ht_key_equal,
     134        .compare = futex_ht_compare,
    137135        .remove_callback = futex_ht_remove_callback
    138136};
     
    150148void futex_init(void)
    151149{
    152         hash_table_create(&futex_ht, 0, 0, &futex_ht_ops);
     150        hash_table_create(&futex_ht, FUTEX_HT_SIZE, 1, &futex_ht_ops);
    153151}
    154152
     
    235233{
    236234        waitq_initialize(&futex->wq);
     235        link_initialize(&futex->ht_link);
    237236        futex->paddr = paddr;
    238237        futex->refcount = 1;
     
    242241static void futex_add_ref(futex_t *futex)
    243242{
    244         assert(spinlock_locked(&futex_ht_lock));
    245         assert(0 < futex->refcount);
     243        ASSERT(spinlock_locked(&futex_ht_lock));
     244        ASSERT(0 < futex->refcount);
    246245        ++futex->refcount;
    247246}
     
    250249static void futex_release_ref(futex_t *futex)
    251250{
    252         assert(spinlock_locked(&futex_ht_lock));
    253         assert(0 < futex->refcount);
     251        ASSERT(spinlock_locked(&futex_ht_lock));
     252        ASSERT(0 < futex->refcount);
    254253       
    255254        --futex->refcount;
    256255       
    257256        if (0 == futex->refcount) {
    258                 hash_table_remove(&futex_ht, &futex->paddr);
     257                hash_table_remove(&futex_ht, &futex->paddr, 1);
    259258        }
    260259}
     
    347346        spinlock_lock(&futex_ht_lock);
    348347       
    349         ht_link_t *fut_link = hash_table_find(&futex_ht, &phys_addr);
     348        link_t *fut_link = hash_table_find(&futex_ht, &phys_addr);
    350349       
    351350        if (fut_link) {
     
    355354        } else {
    356355                futex_initialize(futex, phys_addr);
    357                 hash_table_insert(&futex_ht, &futex->ht_link);
     356                hash_table_insert(&futex_ht, &phys_addr, &futex->ht_link);
    358357        }
    359358       
     
    437436
    438437
    439 /** Return the hash of the key stored in the item */
    440 size_t futex_ht_hash(const ht_link_t *item)
    441 {
    442         futex_t *futex = hash_table_get_inst(item, futex_t, ht_link);
    443         return hash_mix(futex->paddr);
    444 }
    445 
    446 /** Return the hash of the key */
    447 size_t futex_ht_key_hash(void *key)
    448 {
    449         uintptr_t *paddr = (uintptr_t *) key;
    450         return hash_mix(*paddr);
    451 }
    452 
    453 /** Return true if the key is equal to the item's lookup key. */
    454 bool futex_ht_key_equal(void *key, const ht_link_t *item)
    455 {
    456         uintptr_t *paddr = (uintptr_t *) key;
    457         futex_t *futex = hash_table_get_inst(item, futex_t, ht_link);
    458         return *paddr == futex->paddr;
     438/** Compute hash index into futex hash table.
     439 *
     440 * @param key           Address where the key (i.e. physical address of futex
     441 *                      counter) is stored.
     442 *
     443 * @return              Index into futex hash table.
     444 */
     445size_t futex_ht_hash(sysarg_t *key)
     446{
     447        return (*key & (FUTEX_HT_SIZE - 1));
     448}
     449
     450/** Compare futex hash table item with a key.
     451 *
     452 * @param key           Address where the key (i.e. physical address of futex
     453 *                      counter) is stored.
     454 *
     455 * @return              True if the item matches the key. False otherwise.
     456 */
     457bool futex_ht_compare(sysarg_t *key, size_t keys, link_t *item)
     458{
     459        futex_t *futex;
     460
     461        ASSERT(keys == 1);
     462
     463        futex = hash_table_get_instance(item, futex_t, ht_link);
     464        return *key == futex->paddr;
    459465}
    460466
     
    463469 * @param item          Item removed from the hash table.
    464470 */
    465 void futex_ht_remove_callback(ht_link_t *item)
     471void futex_ht_remove_callback(link_t *item)
    466472{
    467473        futex_t *futex;
    468474
    469         futex = hash_table_get_inst(item, futex_t, ht_link);
     475        futex = hash_table_get_instance(item, futex_t, ht_link);
    470476        free(futex);
    471477}
Note: See TracChangeset for help on using the changeset viewer.