[Openmcl-devel] Help with lap functions

Taoufik Dachraoui dachraoui.taoufik at gmail.com
Thu Jan 9 03:27:28 PST 2014


Hi

Sorry for the errors; it was not my main concern it should be like this:

(defmacro with-critical-section (addr &body body)
   "lock on addr"
  `(unwind-protect
  (progn
         (acquire-lock-xchg ,addr) ; this will block
           , at body)
      (free-lock-xchg ,addr)))

(deflapfunction acquire-lock-xchg (addr)
   :again
       mov ($ 1) (% reg)
       xchg (% reg) (@ addr)
       jz @win
       (pause)
        jmp @again
      :win
       ret (% reg)  )

Now, I am not reinventing the wheel, I used to use semaphores but they are
very slow for my needs
and would like to use LOCK XCHG to implement a lightweight locking

PS: to get the address of a cons I use ccl::%address-of, but in my program
I need to get the address of the
lock bit (ex.   (let ((a '(x . 0))) (with-critical-section (cdr a)
do-something))); as you can see I need to get the address of 0
to be able to xchg it with 1 atomically in acquire-lock-xchg.

Kind regards
Taoufik



On Thu, Jan 9, 2014 at 10:48 AM, Taoufik Dachraoui <
dachraoui.taoufik at gmail.com> wrote:

> Hi
>
> Please I need help with creating 2 simple lapfunctions: acquire-lock-xchg
> and free-lock-xchg
>
> assembler pseudocode for both functions follow:
>
> (deflapfunction acquire-lock-xchg (addr)
>        mov 1 reg
>        xchg addr reg
>        ret reg  )
>
> (deflapfunction free-lock-xchg (addr)
>        mov 0 reg
>        xchg addr reg
>        ret
> )
>
> (defmacro with-critical-section (addr &body body)
>    "lock on addr"
>   `((loop when (= 1 (the fixnumm (acquire-lock-xchg ,addr))) return nil) ;
> spin-wait           (unwind-protect
>  (progn
>            , at body)
>       (free-lock-xchg ,addr))))
>
> Usage:
>    (let ((x '(1 nil . 0))) (with-critical-section (cddr x) (push 2 (cadr
> x))))
>
> 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)
>
> Kind regards
> Taoufik
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20140109/6965d1e7/attachment.htm>


More information about the Openmcl-devel mailing list