您可以使用:metaclassdefclass 形式的 class 选项指定元类。
CL-USER> (defclass hierarchical-lock (lock)
((parent :initarg :parent :reader parent))
(:metaclass built-in-class))
#<BUILT-IN-CLASS HIERARCHICAL-LOCK>
但是,即使您可以这样做并获得课程,我也不确定您将如何实例化它。尝试使用make-instance失败:
CL-USER> (make-instance 'hierarchical-lock)
; There is no applicable method for the generic function:
; #<STANDARD-GENERIC-FUNCTION MAKE-INSTANCE #x30200002676F>
; when called with arguments:
; (#<BUILT-IN-CLASS HIERARCHICAL-LOCK>)
; [Condition of type SIMPLE-ERROR]
make-lock在l0-aprims.lisp中实现为
(defun make-lock (&optional name)
"Create and return a lock object, which can be used for synchronization
between threads."
(%make-lock (%make-recursive-lock-ptr) name))
You can keep following the implementation of %make-lock until you get to the low level implementation details, but it's clear that locks are not obtained the same way that typical CLOS instances are.
In addition to Rainer Joswig's suggestion in a comment on this answer that you let the CCL developers know that you would appreciate locks being CLOS objects, you can always use some aggregation and define your own hierarchical-lock that has slot for its primitive lock and a slot for parent. By the magic of generic functions, you can implement methods on the generic functions that work with locks so that your hierarchical-lock behaves like a built in lock. (This presumes that the lock API is defined in terms of generic functions.)