Changeset ee42e43 in mainline for kernel/generic/src/synch/futex.c


Ignore:
Timestamp:
2010-06-22T11:29:40Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a49a1a1
Parents:
fdaad75d
Message:

Retire kernel rwlocks.

File:
1 edited

Legend:

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

    rfdaad75d ree42e43  
    3737
    3838#include <synch/futex.h>
    39 #include <synch/rwlock.h>
     39#include <synch/mutex.h>
    4040#include <synch/spinlock.h>
    4141#include <synch/synch.h>
     
    6565
    6666/**
    67  * Read-write lock protecting global futex hash table.
     67 * Mutex protecting global futex hash table.
    6868 * It is also used to serialize access to all futex_t structures.
    6969 * Must be acquired before the task futex B+tree lock.
    7070 */
    71 static rwlock_t futex_ht_lock;
     71static mutex_t futex_ht_lock;
    7272
    7373/** Futex hash table. */
     
    8484void futex_init(void)
    8585{
    86         rwlock_initialize(&futex_ht_lock);
     86        mutex_initialize(&futex_ht_lock, MUTEX_PASSIVE);
    8787        hash_table_create(&futex_ht, FUTEX_HT_SIZE, 1, &futex_ht_ops);
    8888}
     
    194194         * or allocate new one if it does not exist already.
    195195         */
    196         rwlock_read_lock(&futex_ht_lock);
     196        mutex_lock(&futex_ht_lock);
    197197        item = hash_table_find(&futex_ht, &paddr);
    198198        if (item) {
     
    206206                        /*
    207207                         * The futex is new to the current task.
    208                          * However, we only have read access.
    209                          * Gain write access and try again.
     208                         * Upgrade its reference count and put it to the
     209                         * current task's B+tree of known futexes.
    210210                         */
    211                         mutex_unlock(&TASK->futexes_lock);
    212                         goto gain_write_access;
     211                        futex->refcount++;
     212                        btree_insert(&TASK->futexes, paddr, futex, leaf);
    213213                }
    214214                mutex_unlock(&TASK->futexes_lock);
    215 
    216                 rwlock_read_unlock(&futex_ht_lock);
    217215        } else {
    218 gain_write_access:
     216                futex = (futex_t *) malloc(sizeof(futex_t), 0);
     217                futex_initialize(futex);
     218                futex->paddr = paddr;
     219                hash_table_insert(&futex_ht, &paddr, &futex->ht_link);
     220                       
    219221                /*
    220                  * Upgrade to writer is not currently supported,
    221                  * therefore, it is necessary to release the read lock
    222                  * and reacquire it as a writer.
     222                 * This is the first task referencing the futex.
     223                 * It can be directly inserted into its
     224                 * B+tree of known futexes.
    223225                 */
    224                 rwlock_read_unlock(&futex_ht_lock);
    225 
    226                 rwlock_write_lock(&futex_ht_lock);
    227                 /*
    228                  * Avoid possible race condition by searching
    229                  * the hash table once again with write access.
    230                  */
    231                 item = hash_table_find(&futex_ht, &paddr);
    232                 if (item) {
    233                         futex = hash_table_get_instance(item, futex_t, ht_link);
    234                        
    235                         /*
    236                          * See if this futex is known to the current task.
    237                          */
    238                         mutex_lock(&TASK->futexes_lock);
    239                         if (!btree_search(&TASK->futexes, paddr, &leaf)) {
    240                                 /*
    241                                  * The futex is new to the current task.
    242                                  * Upgrade its reference count and put it to the
    243                                  * current task's B+tree of known futexes.
    244                                  */
    245                                 futex->refcount++;
    246                                 btree_insert(&TASK->futexes, paddr, futex,
    247                                     leaf);
    248                         }
    249                         mutex_unlock(&TASK->futexes_lock);
    250        
    251                         rwlock_write_unlock(&futex_ht_lock);
    252                 } else {
    253                         futex = (futex_t *) malloc(sizeof(futex_t), 0);
    254                         futex_initialize(futex);
    255                         futex->paddr = paddr;
    256                         hash_table_insert(&futex_ht, &paddr, &futex->ht_link);
    257                        
    258                         /*
    259                          * This is the first task referencing the futex.
    260                          * It can be directly inserted into its
    261                          * B+tree of known futexes.
    262                          */
    263                         mutex_lock(&TASK->futexes_lock);
    264                         btree_insert(&TASK->futexes, paddr, futex, NULL);
    265                         mutex_unlock(&TASK->futexes_lock);
    266                        
    267                         rwlock_write_unlock(&futex_ht_lock);
    268                 }
     226                mutex_lock(&TASK->futexes_lock);
     227                btree_insert(&TASK->futexes, paddr, futex, NULL);
     228                mutex_unlock(&TASK->futexes_lock);
     229               
    269230        }
     231        mutex_unlock(&futex_ht_lock);
    270232       
    271233        return futex;
     
    318280        link_t *cur;
    319281       
    320         rwlock_write_lock(&futex_ht_lock);
     282        mutex_lock(&futex_ht_lock);
    321283        mutex_lock(&TASK->futexes_lock);
    322284
     
    338300       
    339301        mutex_unlock(&TASK->futexes_lock);
    340         rwlock_write_unlock(&futex_ht_lock);
     302        mutex_unlock(&futex_ht_lock);
    341303}
    342304
Note: See TracChangeset for help on using the changeset viewer.