src/atomic/SDL_atomic.c
changeset 6978 e851407e9294
parent 6885 700f1b25f77f
child 7191 75360622e65f
equal deleted inserted replaced
6977:b73d51026c68 6978:e851407e9294
    25 /* Note that we undefine the atomic operations here, in case they are
    25 /* Note that we undefine the atomic operations here, in case they are
    26    defined as compiler intrinsics while building SDL but the library user
    26    defined as compiler intrinsics while building SDL but the library user
    27    doesn't have that compiler.  That way we always have a working set of
    27    doesn't have that compiler.  That way we always have a working set of
    28    atomic operations built into the library.
    28    atomic operations built into the library.
    29 */
    29 */
       
    30 #undef SDL_AtomicCAS
       
    31 #undef SDL_AtomicCASPtr
    30  
    32  
    31 /* 
    33 /* 
    32   If any of the operations are not provided then we must emulate some
    34   If any of the operations are not provided then we must emulate some
    33   of them. That means we need a nice implementation of spin locks
    35   of them. That means we need a nice implementation of spin locks
    34   that avoids the "one big lock" problem. We use a vector of spin
    36   that avoids the "one big lock" problem. We use a vector of spin
    67     uintptr_t index = ((((uintptr_t)a) >> 3) & 0x1f);
    69     uintptr_t index = ((((uintptr_t)a) >> 3) & 0x1f);
    68 
    70 
    69     SDL_AtomicUnlock(&locks[index]);
    71     SDL_AtomicUnlock(&locks[index]);
    70 }
    72 }
    71 
    73 
    72 SDL_bool
    74 DECLSPEC SDL_bool SDLCALL
    73 SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval)
    75 SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
    74 {
    76 {
    75     SDL_bool retval = SDL_FALSE;
    77     SDL_bool retval = SDL_FALSE;
    76 
    78 
    77     enterLock(a);
    79     enterLock(a);
    78     if (a->value == oldval) {
    80     if (a->value == oldval) {
    82     leaveLock(a);
    84     leaveLock(a);
    83 
    85 
    84     return retval;
    86     return retval;
    85 }
    87 }
    86 
    88 
    87 SDL_bool
    89 DECLSPEC SDL_bool SDLCALL
    88 SDL_AtomicCASPtr_(void **a, void *oldval, void *newval)
    90 SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
    89 {
    91 {
    90     SDL_bool retval = SDL_FALSE;
    92     SDL_bool retval = SDL_FALSE;
    91 
    93 
    92     enterLock(a);
    94     enterLock(a);
    93     if (*a == oldval) {
    95     if (*a == oldval) {