Changeset 9bde0d5 in mainline for uspace/lib/c/generic/malloc.c


Ignore:
Timestamp:
2018-07-18T19:56:43Z (7 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.