[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Locatives and Class slots

    Date: Tue, 22 May 90 08:41 PDT
    From: snicoud@atc.boeing.com (Stephen L. Nicoud)

    I'm converting an application using New Flavors to use PCL on a
    Symbolics 3650 (7.2).  I have several cases where the code uses a flavor
    instance variable as an argument to SCL:LOCF.  The resulting locative is

    I can't seem to get the same functionality with class slots.

    Would anyone care to make suggestions about how to proceed?  Is there a
    way to get a locative to a PCL class slot?

Nope.  In 7.4 and 8.0, there is a way to make a lock instance, using
PROCESS:MAKE-LOCK, which can then be locked inside a dynamic extent with
PROCESS:WITH-LOCK; you would just put that lock instance into a slot.
Of course, in 8.0 you can use Genera CLOS, which will allow locatives to
instance slots, I think.

In 7.2, one way to do this is to make the slot be a cons, and use its
CAR as the lock cell.

Here is how I might go about having locks on objects in general
(untested, but probably right in form):

(defclass locking-mixin ()
  (lock :initform (list nil)))

(defmethod with-locked-thing-internal ((locked-thing locking-mixin) continuation
				       &optional (whostate "Lock")) 
  (declare (sys:downward-funarg continuation))
  (with-slots (lock) locked-thing
    (si:with-lock-held ((car lock) :whostate whostate)  ; Genera macro
      (funcall continuation))))

(defmacro with-locked-thing ((thing &optional (whostate '"Lock")) &body body)
  `(flet ((continuation () ,@body))
     (with-locked-thing-internal ,thing #'continuation whostate)))