Mercurial > hg > GearsTemplate
view src/parallel_execution/SpinLock.cbc @ 557:1eb2a22ec1e3
tweak
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 18 Nov 2019 21:22:34 +0900 |
parents | 64869af1f3ef |
children |
line wrap: on
line source
#include "../context.h" #interface "Atomic.h" #interface "Lock.h" Lock* createSpinLock(struct Context* context) { struct Lock* lock = new Lock(); struct SpinLock* spinLock = new SpinLock(); spinLock->lock = NULL; spinLock->atomic = createAtomicReference(context); lock->lock = (union Data*)spinLock; lock->doLock = C_doLockSpinLock; lock->doUnlock = C_doUnlockSpinLock; return lock; } __code doLockSpinLock(struct SpinLock* lock, __code next(...)) { struct Atomic* atomic = lock->atomic; goto atomic->checkAndSet(&lock->lock, NULL, 1, doLockSpinLock1, doLockSpinLock); } __code doLockSpinLock1(struct SpinLock* lock, __code next(...)) { lock->lockContext = context; goto next(...); } __code doUnlockSpinLock(struct SpinLock* lock, __code next(...)) { if (lock->lockContext == context) { struct Atomic* atomic = lock->atomic; goto atomic->checkAndSet(&lock->lock, 1, NULL, next(...), doUnlockSpinLock); } goto next(...); }