Changeset 508b0df1 in mainline for uspace/lib/c/include/refcount.h


Ignore:
Timestamp:
2018-09-06T20:21:52Z (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:
78de83de, fc10e1b
Parents:
4621d23
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-08-13 03:53:39)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-09-06 20:21:52)
Message:

Remove uspace <atomic.h>, use <stdatomic.h> instead

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/refcount.h

    r4621d23 r508b0df1  
    4040#define LIBC_REFCOUNT_H_
    4141
    42 // TODO: #include <stdatomic.h>
    43 
    4442#include <assert.h>
    45 #include <atomic.h>
     43#include <stdatomic.h>
    4644#include <stdbool.h>
    4745
    4846/* Wrapped in a structure to prevent direct manipulation. */
    4947typedef struct atomic_refcount {
    50         //volatile atomic_int __cnt;
    51         atomic_t __cnt;
     48        volatile atomic_int __cnt;
    5249} atomic_refcount_t;
    5350
    5451static inline void refcount_init(atomic_refcount_t *rc)
    5552{
    56         //atomic_store_explicit(&rc->__cnt, 0, memory_order_relaxed);
    57         atomic_set(&rc->__cnt, 0);
     53        atomic_store_explicit(&rc->__cnt, 0, memory_order_relaxed);
    5854}
    5955
     
    7268        //      still needs to be synchronized independently of the refcount.
    7369
    74         //int old = atomic_fetch_add_explicit(&rc->__cnt, 1,
    75         //    memory_order_relaxed);
    76 
    77         atomic_signed_t old = atomic_postinc(&rc->__cnt);
     70        int old = atomic_fetch_add_explicit(&rc->__cnt, 1,
     71            memory_order_relaxed);
    7872
    7973        /* old < 0 indicates that the function is used incorrectly. */
     
    9488        // XXX: The decrementers don't need to synchronize with each other,
    9589        //      but they do need to synchronize with the one doing deallocation.
    96         //int old = atomic_fetch_sub_explicit(&rc->__cnt, 1,
    97         //    memory_order_release);
    98 
    99         atomic_signed_t old = atomic_postdec(&rc->__cnt);
     90        int old = atomic_fetch_sub_explicit(&rc->__cnt, 1,
     91            memory_order_release);
    10092
    10193        assert(old >= 0);
     
    10496                // XXX: We are holding the last reference, so we must now
    10597                //      synchronize with all the other decrementers.
    106                 //int val = atomic_load_explicit(&rc->__cnt,
    107                 //    memory_order_acquire);
    108                 //assert(val == -1);
    109                 return true;
     98
     99                int val = atomic_load_explicit(&rc->__cnt,
     100                    memory_order_acquire);
     101                assert(val == -1);
     102
     103                /*
     104                 * The compiler probably wouldn't optimize the memory barrier
     105                 * away, but better safe than sorry.
     106                 */
     107                return val < 0;
    110108        }
    111109
Note: See TracChangeset for help on using the changeset viewer.