Indentation fix, cleanup.
[AROS.git] / arch / arm-native / kernel / spinunlock.c
blobcae4d7e3b6e8a782506268edd4d411cfffac719e
1 /*
2 Copyright © 2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/types/spinlock_s.h>
7 #include <aros/kernel.h>
8 #include <aros/libcall.h>
10 #include <kernel_base.h>
12 #include <proto/kernel.h>
14 AROS_LH1(void, KrnSpinUnLock,
15 AROS_LHA(spinlock_t *, lock, A0),
16 struct KernelBase *, KernelBase, 44, Kernel)
18 AROS_LIBFUNC_INIT
20 if (lock->lock == 0)
21 return;
24 * Are we releasing a write lock? Just zero out the value. Also send event so that other cores waiting for lock
25 * wake up.
27 if (lock->lock & 0x80000000)
29 lock->lock = 0;
30 asm volatile("sev");
32 else
34 unsigned long lock_value, write_result;
36 asm volatile(
37 "1: ldrex %0, [%2] \n\t" // Read lock value and gain write exclusive lock
38 " sub %0, %0, #1 \n\t" // Decrease lock value
39 " strex %1, %0, [%2] \n\t" // Try to update the lock value
40 " teq %1, #0 \n\t" // test if write succeeded
41 " bne 1b \n\t" // Try again if write failed
42 :"=&r"(lock_value), "=&r"(write_result)
43 :"r"(&lock->lock)
44 :"cc"
47 /* Send event to other cores if lock is free */
48 if (lock_value == 0)
49 asm volatile("sev");
52 AROS_LIBFUNC_EXIT