Commit add33498 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: add atomic xchg64

It will be handy for network poller.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7429048
parent 2fe840f4
......@@ -442,6 +442,12 @@ TEXT runtime·xchg(SB), 7, $0
XCHGL AX, 0(BX)
RET
TEXT runtime·xchg64(SB), 7, $0
MOVQ 8(SP), BX
MOVQ 16(SP), AX
XCHGQ AX, 0(BX)
RET
TEXT runtime·procyield(SB),7,$0
MOVL 8(SP), AX
again:
......
......@@ -30,3 +30,16 @@ runtime·xadd64(uint64 volatile* addr, int64 v)
}
return old+v;
}
#pragma textflag 7
uint64
runtime·xchg64(uint64 volatile* addr, uint64 v)
{
uint64 old;
old = *addr;
while(!runtime·cas64(addr, &old, v)) {
// nothing
}
return old;
}
......@@ -121,6 +121,19 @@ runtime·xadd64(uint64 volatile *addr, int64 delta)
return res;
}
#pragma textflag 7
uint64
runtime·xchg64(uint64 volatile *addr, uint64 v)
{
uint64 res;
runtime·lock(LOCK(addr));
res = *addr;
*addr = v;
runtime·unlock(LOCK(addr));
return res;
}
#pragma textflag 7
uint64
runtime·atomicload64(uint64 volatile *addr)
......
......@@ -156,6 +156,10 @@ TestAtomic64(void)
runtime·throw("xadd64 failed");
if(runtime·atomicload64(&z64) != (2ull<<40)+2)
runtime·throw("xadd64 failed");
if(runtime·xchg64(&z64, (3ull<<40)+3) != (2ull<<40)+2)
runtime·throw("xchg64 failed");
if(runtime·atomicload64(&z64) != (3ull<<40)+3)
runtime·throw("xchg64 failed");
}
void
......
......@@ -691,6 +691,7 @@ bool runtime·casp(void**, void*, void*);
uint32 runtime·xadd(uint32 volatile*, int32);
uint64 runtime·xadd64(uint64 volatile*, int64);
uint32 runtime·xchg(uint32 volatile*, uint32);
uint64 runtime·xchg64(uint64 volatile*, uint64);
uint32 runtime·atomicload(uint32 volatile*);
void runtime·atomicstore(uint32 volatile*, uint32);
void runtime·atomicstore64(uint64 volatile*, uint64);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment