View previous topic :: View next topic |
Author |
Message |
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Mon Oct 31, 2005 11:30 pm Post subject: atomic ops |
|
|
Hi Sean,
Can you identify the equivalent Ares atomic function for these two, please?
Code: | /** Compare expect to *ptr and if equal copy update to *ptr and return true;
* Otherwise return false.
* \param ptr the memory location to update
* \param expect the expected value at *ptr
* \param update the new value for *ptr
* \return true if successful
*/
static bool compareAndSet32(void* vptr, void* expect, void* update)
{
return compareAndSet32(vptr,cast(int)expect,cast(int)update);
}
// alternative declaration for data instead of pointers
static bool compareAndSet32(void* vptr, int expect, int update)
{
asm
{
mov EBX,update;
mov EAX,expect;
mov ECX,vptr;
lock;
cmpxchg [ECX],EBX;
setz AL;
}
} |
|
|
Back to top |
|
|
sean
Joined: 24 Jun 2004 Posts: 609 Location: Bay Area, CA
|
Posted: Tue Nov 01, 2005 6:41 pm Post subject: |
|
|
They both would use the same function call:
Code: | bit atomicStoreIf!(T,msync.acq)( inout T val, T newval, T equalTo );
bit atomicStoreIf!(T,msync.rel)( inout T val, T newval, T equalTo ); |
Pick msync.acq or msync.rel as appropriate, and if you aren't sure, use msync.rel. There's actually no difference in the memory barriers used for acquire/release on storeIf, but I suspect there might be on other platforms.
Also, the Atomic struct is the generalized form of the above and is intended to be used when you have full control over the variable being manipulated. Usage is essentially the same:
Code: | Atomic!(int) atom;
atom.storeIf!(msync.rel)( newval, equalTo ); |
A compiler bug currently limits the use of these functions to either signed or unsigned per byte size(so you can't use atomic int and atomic uint at the same time). |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Tue Nov 01, 2005 8:25 pm Post subject: |
|
|
Thanks! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|