<div dir="ltr">Hi<div><br></div><div>Please I need help with creating 2 simple lapfunctions: acquire-lock-xchg and free-lock-xchg</div><div><br></div><div>assembler pseudocode for both functions follow:</div><div><br></div>
<div><div>(deflapfunction acquire-lock-xchg (addr) </div><div>       mov 1 reg</div><div>       xchg addr reg</div><div>       ret reg  )</div><div> </div><div>(deflapfunction free-lock-xchg (addr) </div><div>       mov 0 reg</div>
<div>       xchg addr reg</div><div>       ret</div><div>)</div><div><br></div><div>(defmacro with-critical-section (addr &body body)</div><div>   "lock on addr"</div><div>  `((loop when (= 1 (the fixnumm (acquire-lock-xchg ,addr))) return nil) ; spin-wait           (unwind-protect</div>
<div><span class="" style="white-space:pre">    </span> (progn</div><div>           ,@body)</div><div>      (free-lock-xchg ,addr))))</div></div><div><br></div><div>Usage:</div><div>   (let ((x '(1 nil . 0))) (with-critical-section (cddr x) (push 2 (cadr x))))</div>
<div><br></div><div>Do you think that such code is robust and may be used in production? (I am developing a new algorithm for persistent hash tables for multiprocessors systems)</div><div><br></div><div>Kind regards</div>
<div>Taoufik</div><div><br></div></div>