/* Atomic get-and-set primitive. 
is atomically written at <target> and the previous value at <target> is returned. */
atomic_val_t atomic_set(atomic_t *target, atomic_val_t value)
/* Atomic get-and-set primitive. 
is atomically written at <target> and the previous value at <target> is returned. */
atomic_val_t atomic_set(atomic_t *target, atomic_val_t value)
{
    unsigned int key;
    atomic_val_t ret;
    key = irq_lock();
    ret = *target;
    *target = value;
    irq_unlock(key);
    return ret;
}