Changeset 156b6406 in mainline for uspace/lib/c


Ignore:
Timestamp:
2012-12-04T16:42:06Z (13 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b188002
Parents:
b7acf38
Message:

Differentiated futexes when used with mutex semantics from those with semaphore semantics.

Location:
uspace/lib/c
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/futex.c

    rb7acf38 r156b6406  
    5656void futex_upgrade_all_and_wait(void)
    5757{
    58         _futex_down(&upg_and_wait_futex);
     58        futex_down(&upg_and_wait_futex);
    5959       
    6060        if (!_upgrade_futexes) {
     
    6363        }
    6464       
    65         _futex_up(&upg_and_wait_futex);
     65        futex_up(&upg_and_wait_futex);
    6666}
    6767
  • uspace/lib/c/generic/malloc.c

    rb7acf38 r156b6406  
    200200        do { \
    201201                if (!(expr)) {\
    202                         _futex_up(&malloc_futex); \
     202                        futex_up(&malloc_futex); \
    203203                        assert_abort(#expr, __FILE__, __LINE__); \
    204204                } \
     
    785785void *malloc(const size_t size)
    786786{
    787         _futex_down(&malloc_futex);
     787        futex_down(&malloc_futex);
    788788        void *block = malloc_internal(size, BASE_ALIGN);
    789         _futex_up(&malloc_futex);
     789        futex_up(&malloc_futex);
    790790
    791791        return block;
     
    808808            1 << (fnzb(max(sizeof(void *), align) - 1) + 1);
    809809
    810         _futex_down(&malloc_futex);
     810        futex_down(&malloc_futex);
    811811        void *block = malloc_internal(size, palign);
    812         _futex_up(&malloc_futex);
     812        futex_up(&malloc_futex);
    813813
    814814        return block;
     
    828828                return malloc(size);
    829829       
    830         _futex_down(&malloc_futex);
     830        futex_down(&malloc_futex);
    831831       
    832832        /* Calculate the position of the header. */
     
    885885        }
    886886       
    887         _futex_up(&malloc_futex);
     887        futex_up(&malloc_futex);
    888888       
    889889        if (reloc) {
     
    908908                return;
    909909       
    910         _futex_down(&malloc_futex);
     910        futex_down(&malloc_futex);
    911911       
    912912        /* Calculate the position of the header. */
     
    953953        heap_shrink(area);
    954954       
    955         _futex_up(&malloc_futex);
     955        futex_up(&malloc_futex);
    956956}
    957957
    958958void *heap_check(void)
    959959{
    960         _futex_down(&malloc_futex);
     960        futex_down(&malloc_futex);
    961961       
    962962        if (first_heap_area == NULL) {
    963                 _futex_up(&malloc_futex);
     963                futex_up(&malloc_futex);
    964964                return (void *) -1;
    965965        }
     
    975975                    (((uintptr_t) area->start % PAGE_SIZE) != 0) ||
    976976                    (((uintptr_t) area->end % PAGE_SIZE) != 0)) {
    977                         _futex_up(&malloc_futex);
     977                        futex_up(&malloc_futex);
    978978                        return (void *) area;
    979979                }
     
    986986                        /* Check heap block consistency */
    987987                        if (head->magic != HEAP_BLOCK_HEAD_MAGIC) {
    988                                 _futex_up(&malloc_futex);
     988                                futex_up(&malloc_futex);
    989989                                return (void *) head;
    990990                        }
     
    994994                        if ((foot->magic != HEAP_BLOCK_FOOT_MAGIC) ||
    995995                            (head->size != foot->size)) {
    996                                 _futex_up(&malloc_futex);
     996                                futex_up(&malloc_futex);
    997997                                return (void *) foot;
    998998                        }
     
    10001000        }
    10011001       
    1002         _futex_up(&malloc_futex);
     1002        futex_up(&malloc_futex);
    10031003       
    10041004        return NULL;
  • uspace/lib/c/include/futex.h

    rb7acf38 r156b6406  
    5555#define FUTEX_INITIALIZE(val) {{ (val) }, 0}
    5656
    57 #define futex_down(fut) \
     57#define futex_lock(fut) \
    5858({ \
    5959        rcu_read_lock(); \
    6060        (fut)->upgraded = rcu_access(_upgrade_futexes); \
    6161        if ((fut)->upgraded) \
    62                 (void) _futex_down((fut)); \
     62                (void) futex_down((fut)); \
    6363})
    6464
    65 #define futex_trydown(fut) \
     65#define futex_trylock(fut) \
    6666({ \
    6767        rcu_read_lock(); \
    6868        int _upgraded = rcu_access(_upgrade_futexes); \
    6969        if (_upgraded) { \
    70                 int _acquired = _futex_trydown((fut)); \
     70                int _acquired = futex_trydown((fut)); \
    7171                if (!_acquired) { \
    7272                        rcu_read_unlock(); \
     
    8181})
    8282               
    83 #define futex_up(fut) \
     83#define futex_unlock(fut) \
    8484({ \
    8585        if ((fut)->upgraded) \
    86                 (void) _futex_up((fut)); \
     86                (void) futex_up((fut)); \
    8787        rcu_read_unlock(); \
    8888})
     
    9696#define FUTEX_INITIALIZE(val) {{ (val) }}
    9797
    98 #define futex_down(fut)     (void)_futex_down((fut))
    99 #define futex_trydown(fut)  _futex_trydown((fut))
    100 #define futex_up(fut)       (void)_futex_up((fut))
     98#define futex_lock(fut)     (void) futex_down((fut))
     99#define futex_trylock(fut)  futex_trydown((fut))
     100#define futex_unlock(fut)   (void) futex_up((fut))
    101101               
    102102#endif
     
    112112 *
    113113 */
    114 static inline int _futex_trydown(futex_t *futex)
     114static inline int futex_trydown(futex_t *futex)
    115115{
    116116        return cas(&futex->val, 1, 0);
     
    126126 *
    127127 */
    128 static inline int _futex_down(futex_t *futex)
     128static inline int futex_down(futex_t *futex)
    129129{
    130130        if ((atomic_signed_t) atomic_predec(&futex->val) < 0)
     
    142142 *
    143143 */
    144 static inline int _futex_up(futex_t *futex)
     144static inline int futex_up(futex_t *futex)
    145145{
    146146        if ((atomic_signed_t) atomic_postinc(&futex->val) < 0)
Note: See TracChangeset for help on using the changeset viewer.