Index: kernel/generic/include/synch/spinlock.h
===================================================================
--- kernel/generic/include/synch/spinlock.h	(revision 05882233d8ca97c6879ac5c42456c344c8569d89)
+++ kernel/generic/include/synch/spinlock.h	(revision 70259a55669e39fcfc7d76d43bbf35c26ab91657)
@@ -36,9 +36,8 @@
 #define KERN_SPINLOCK_H_
 
+#include <assert.h>
+#include <stdatomic.h>
 #include <stdbool.h>
-#include <barrier.h>
-#include <assert.h>
 #include <preemption.h>
-#include <atomic.h>
 #include <arch/asm.h>
 
@@ -46,5 +45,5 @@
 
 typedef struct spinlock {
-	atomic_t val;
+	atomic_flag flag;
 
 #ifdef CONFIG_DEBUG_SPINLOCK
@@ -70,5 +69,5 @@
 	spinlock_t lock_name = { \
 		.name = desc_name, \
-		.val = { 0 } \
+		.flag = ATOMIC_FLAG_INIT \
 	}
 
@@ -76,5 +75,5 @@
 	static spinlock_t lock_name = { \
 		.name = desc_name, \
-		.val = { 0 } \
+		.flag = ATOMIC_FLAG_INIT \
 	}
 
@@ -89,10 +88,10 @@
 #define SPINLOCK_INITIALIZE_NAME(lock_name, desc_name) \
 	spinlock_t lock_name = { \
-		.val = { 0 } \
+		.flag = ATOMIC_FLAG_INIT \
 	}
 
 #define SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, desc_name) \
 	static spinlock_t lock_name = { \
-		.val = { 0 } \
+		.flag = ATOMIC_FLAG_INIT \
 	}
 
@@ -126,10 +125,5 @@
 NO_TRACE static inline void spinlock_unlock_nondebug(spinlock_t *lock)
 {
-	/*
-	 * Prevent critical section code from bleeding out this way down.
-	 */
-	CS_LEAVE_BARRIER();
-
-	atomic_set(&lock->val, 0);
+	atomic_flag_clear_explicit(&lock->flag, memory_order_release);
 	preemption_enable();
 }
@@ -215,5 +209,5 @@
 		.lock = { \
 			.name = desc_name, \
-			.val = { 0 } \
+			.flag = ATOMIC_FLAG_INIT \
 		}, \
 		.guard = false, \
@@ -225,5 +219,5 @@
 		.lock = { \
 			.name = desc_name, \
-			.val = { 0 } \
+			.flag = ATOMIC_FLAG_INIT \
 		}, \
 		.guard = false, \
@@ -236,5 +230,5 @@
 	irq_spinlock_t lock_name = { \
 		.lock = { \
-			.val = { 0 } \
+			.flag = ATOMIC_FLAG_INIT \
 		}, \
 		.guard = false, \
@@ -245,5 +239,5 @@
 	static irq_spinlock_t lock_name = { \
 		.lock = { \
-			.val = { 0 } \
+			.flag = ATOMIC_FLAG_INIT \
 		}, \
 		.guard = false, \
