Real Lock Implementation
Real Lock Implementation
Programming
Real Lock Implementations
Locking Example
ARM Locks
TEXT
_tas(SB), 1, $-4
MOVW
R0,R1
MOVW
$1,R0
SWPW
R0,(R1)
RET
ARM Locks
void
lock(Lock *lk)
{
int i;
/* once fast */
if(!_tas(&lk->val))
return;
/* a thousand times pretty fast */
for(i=0; i<1000; i++){
if(!_tas(&lk->val))
return;
sleep(0);
}
3
ARM Locks
Multi-Core Effects
Ticket Locks
p1:
p2:
p3:
p4:
p5:
fetch-and-add
Load Exclusive
LDREX
(R0), R1
10
Store Exclusive
STREX
R1, (R0), R2
11
/* _tas(ulong *) */
12
Queue Locks
13