Changeset 9bde0d5 in mainline


Ignore:
Timestamp:
2018-07-18T19:56:43Z (6 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
42f5860
Parents:
40abf56
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-18 19:47:28)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-18 19:56:43)
Message:

Replace a bunch of direct uses of futex_t.

Location:
uspace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/rcubench/rcubench.c

    r40abf56 r9bde0d5  
    5959        size_t iters;
    6060        size_t nthreads;
    61         futex_t done_threads;
    62 
    63         futex_t bench_fut;
     61        fibril_semaphore_t done_threads;
    6462} bench_t;
    6563
     
    111109
    112110        /* Signal another thread completed. */
    113         futex_up(&bench->done_threads);
     111        fibril_semaphore_up(&bench->done_threads);
    114112        return EOK;
    115113}
     
    147145        /* Wait for threads to complete. */
    148146        for (size_t k = 0; k < bench->nthreads; ++k) {
    149                 futex_down(&bench->done_threads);
     147                fibril_semaphore_down(&bench->done_threads);
    150148        }
    151149}
     
    202200        }
    203201
    204         futex_initialize(&bench->bench_fut, 1);
    205 
    206202        if (0 == str_cmp(argv[1], "sys-futex")) {
    207203                bench->func = kernel_futex_bench;
     
    247243        bench_t bench;
    248244
    249         futex_initialize(&bench.done_threads, 0);
     245        fibril_semaphore_initialize(&bench.done_threads, 0);
    250246
    251247        if (!parse_cmd_line(argc, argv, &bench, &err)) {
  • uspace/lib/c/generic/async/ports.c

    r40abf56 r9bde0d5  
    9999
    100100/** Futex guarding the interface hash table. */
    101 static futex_t interface_futex = FUTEX_INITIALIZER;
     101static FIBRIL_RMUTEX_INITIALIZE(interface_mutex);
    102102static hash_table_t interface_hash_table;
    103103
     
    205205        interface_t *interface;
    206206
    207         futex_lock(&interface_futex);
     207        fibril_rmutex_lock(&interface_mutex);
    208208
    209209        ht_link_t *link = hash_table_find(&interface_hash_table, &iface);
     
    214214
    215215        if (!interface) {
    216                 futex_unlock(&interface_futex);
     216                fibril_rmutex_unlock(&interface_mutex);
    217217                return ENOMEM;
    218218        }
     
    220220        port_t *port = async_new_port(interface, handler, data);
    221221        if (!port) {
    222                 futex_unlock(&interface_futex);
     222                fibril_rmutex_unlock(&interface_mutex);
    223223                return ENOMEM;
    224224        }
     
    226226        *port_id = port->id;
    227227
    228         futex_unlock(&interface_futex);
     228        fibril_rmutex_unlock(&interface_mutex);
    229229
    230230        return EOK;
     
    252252        port_t *port = NULL;
    253253
    254         futex_lock(&interface_futex);
     254        fibril_rmutex_lock(&interface_mutex);
    255255
    256256        ht_link_t *link = hash_table_find(&interface_hash_table, &iface);
     
    264264        }
    265265
    266         futex_unlock(&interface_futex);
     266        fibril_rmutex_unlock(&interface_mutex);
    267267
    268268        return port;
  • uspace/lib/c/generic/async/server.c

    r40abf56 r9bde0d5  
    234234}
    235235
    236 static futex_t client_futex = FUTEX_INITIALIZER;
     236static FIBRIL_RMUTEX_INITIALIZE(client_mutex);
    237237static hash_table_t client_hash_table;
    238238
    239239// TODO: lockfree notification_queue?
    240 static futex_t notification_futex = FUTEX_INITIALIZER;
     240static FIBRIL_RMUTEX_INITIALIZE(notification_mutex);
    241241static hash_table_t notification_hash_table;
    242242static LIST_INITIALIZE(notification_queue);
     
    339339        client_t *client = NULL;
    340340
    341         futex_lock(&client_futex);
     341        fibril_rmutex_lock(&client_mutex);
    342342        ht_link_t *link = hash_table_find(&client_hash_table, &client_id);
    343343        if (link) {
     
    346346        } else if (create) {
    347347                // TODO: move the malloc out of critical section
     348                /* malloc() is rmutex safe. */
    348349                client = malloc(sizeof(client_t));
    349350                if (client) {
     
    356357        }
    357358
    358         futex_unlock(&client_futex);
     359        fibril_rmutex_unlock(&client_mutex);
    359360        return client;
    360361}
     
    364365        bool destroy;
    365366
    366         futex_lock(&client_futex);
     367        fibril_rmutex_lock(&client_mutex);
    367368
    368369        if (atomic_predec(&client->refcnt) == 0) {
     
    372373                destroy = false;
    373374
    374         futex_unlock(&client_futex);
     375        fibril_rmutex_unlock(&client_mutex);
    375376
    376377        if (destroy) {
     
    693694                fibril_semaphore_down(&notification_semaphore);
    694695
    695                 futex_lock(&notification_futex);
     696                fibril_rmutex_lock(&notification_mutex);
    696697
    697698                /*
     
    727728                        list_remove(&notification->qlink);
    728729
    729                 futex_unlock(&notification_futex);
     730                fibril_rmutex_unlock(&notification_mutex);
    730731
    731732                if (handler)
     
    766767        assert(call);
    767768
    768         futex_lock(&notification_futex);
     769        fibril_rmutex_lock(&notification_mutex);
    769770
    770771        notification_msg_t *m = list_pop(&notification_freelist,
     
    772773
    773774        if (!m) {
    774                 futex_unlock(&notification_futex);
     775                fibril_rmutex_unlock(&notification_mutex);
    775776                m = malloc(sizeof(notification_msg_t));
    776777                if (!m) {
     
    779780                }
    780781
    781                 futex_lock(&notification_futex);
     782                fibril_rmutex_lock(&notification_mutex);
    782783                notification_freelist_total++;
    783784        }
     
    789790                // TODO: Make sure this can't happen and turn it into assert.
    790791                notification_freelist_total--;
    791                 futex_unlock(&notification_futex);
     792                fibril_rmutex_unlock(&notification_mutex);
    792793                free(m);
    793794                return;
     
    804805                list_append(&notification->qlink, &notification_queue);
    805806
    806         futex_unlock(&notification_futex);
     807        fibril_rmutex_unlock(&notification_mutex);
    807808
    808809        fibril_semaphore_up(&notification_semaphore);
     
    829830        fid_t fib = 0;
    830831
    831         futex_lock(&notification_futex);
     832        fibril_rmutex_lock(&notification_mutex);
    832833
    833834        if (notification_avail == 0) {
     
    835836                fib = fibril_create(notification_fibril_func, NULL);
    836837                if (fib == 0) {
    837                         futex_unlock(&notification_futex);
     838                        fibril_rmutex_unlock(&notification_mutex);
    838839                        free(notification);
    839840                        return NULL;
     
    847848        hash_table_insert(&notification_hash_table, &notification->htlink);
    848849
    849         futex_unlock(&notification_futex);
     850        fibril_rmutex_unlock(&notification_mutex);
    850851
    851852        if (imethod == 0) {
  • uspace/lib/c/generic/malloc.c

    r40abf56 r9bde0d5  
    4444#include <bitops.h>
    4545#include <mem.h>
    46 #include <futex.h>
     46#include <fibril_synch.h>
    4747#include <stdlib.h>
    4848#include <adt/gcdlcm.h>
     
    194194
    195195/** Futex for thread-safe heap manipulation */
    196 static futex_t malloc_futex = FUTEX_INITIALIZER;
     196static FIBRIL_RMUTEX_INITIALIZE(malloc_mutex);
    197197
    198198#define malloc_assert(expr) safe_assert(expr)
    199 
    200 #ifdef FUTEX_UPGRADABLE
    201 /** True if the heap may be accessed from multiple threads. */
    202 static bool multithreaded = false;
    203 
    204 /** Makes accesses to the heap thread safe. */
    205 void malloc_enable_multithreaded(void)
    206 {
    207         multithreaded = true;
    208 }
    209199
    210200/** Serializes access to the heap from multiple threads. */
    211201static inline void heap_lock(void)
    212202{
    213         if (multithreaded) {
    214                 futex_down(&malloc_futex);
    215         } else {
    216                 /*
    217                  * Malloc never switches fibrils while the heap is locked.
    218                  * Similarly, it never creates new threads from within the
    219                  * locked region. Therefore, if there are no other threads
    220                  * except this one, the whole operation will complete without
    221                  * any interruptions.
    222                  */
    223         }
     203        fibril_rmutex_lock(&malloc_mutex);
    224204}
    225205
     
    227207static inline void heap_unlock(void)
    228208{
    229         if (multithreaded) {
    230                 futex_up(&malloc_futex);
    231         } else {
    232                 /*
    233                  * Malloc never switches fibrils while the heap is locked.
    234                  * Similarly, it never creates new threads from within the
    235                  * locked region. Therefore, if there are no other threads
    236                  * except this one, the whole operation will complete without
    237                  * any interruptions.
    238                  */
    239         }
    240 }
    241 
    242 #else
    243 
    244 /** Makes accesses to the heap thread safe. */
    245 void malloc_enable_multithreaded(void)
    246 {
    247         /* No-op. Already using thread-safe heap locking operations. */
    248 }
    249 
    250 /** Serializes access to the heap from multiple threads. */
    251 static inline void heap_lock(void)
    252 {
    253         futex_down(&malloc_futex);
    254 }
    255 
    256 /** Serializes access to the heap from multiple threads. */
    257 static inline void heap_unlock(void)
    258 {
    259         futex_up(&malloc_futex);
    260 }
    261 #endif
    262 
     209        fibril_rmutex_unlock(&malloc_mutex);
     210}
    263211
    264212/** Initialize a heap block
  • uspace/lib/c/generic/thread.c

    r40abf56 r9bde0d5  
    116116        }
    117117
    118         /* Make heap thread safe. */
    119         malloc_enable_multithreaded();
    120 
    121118        fibril->arg = arg;
    122119        uarg->uspace_entry = (void *) FADDR(__thread_entry);
  • uspace/lib/c/include/malloc.h

    r40abf56 r9bde0d5  
    4949extern void *heap_check(void);
    5050
    51 extern void malloc_enable_multithreaded(void);
    5251#endif
    5352
Note: See TracChangeset for help on using the changeset viewer.