/* Atomic compare-and-set primitive. 
The reading of the original value at <target>, the comparison, and the write of the new value (if it occurs) all happen atomically with respect to both interrupts and accesses of other processors to <target>. */
int atomic_cas(atomic_t *target, atomic_val_t old_value, atomic_val_t new_value)
/* Atomic compare-and-set primitive. 
The reading of the original value at <target>, the comparison, and the write of the new value (if it occurs) all happen atomically with respect to both interrupts and accesses of other processors to <target>. */
int atomic_cas(atomic_t *target, atomic_val_t old_value, atomic_val_t new_value)
{
    unsigned int key;
    int ret = 0;
    key = irq_lock();
    if (*target == old_value) {
        *target = new_value;
        ret = 1;
    }
    irq_unlock(key);
    return ret;
}