1 ;;;; weak pointer support
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
17 (defun make-weak-pointer (object)
19 "Allocates and returns a weak pointer which points to OBJECT."
20 (declare (values weak-pointer))
21 (make-weak-pointer object))
23 #!-sb-fluid (declaim (inline weak-pointer-value))
24 (defun weak-pointer-value (weak-pointer)
26 "If WEAK-POINTER is valid, returns the value of WEAK-POINTER and T.
27 If the referent of WEAK-POINTER has been garbage collected, returns
28 the values NIL and NIL."
29 (declare (type weak-pointer weak-pointer)
30 (values t (member t nil)))
31 ;; We don't need to wrap this with a without-gcing, because once we have
32 ;; extracted the value, our reference to it will keep the weak pointer
33 ;; from becoming broken. We just have to make sure the compiler won't
34 ;; reorder these primitives.
35 (let ((value (sb!c::%weak-pointer-value weak-pointer))
36 (broken (sb!c::%weak-pointer-broken weak-pointer)))
37 (values value (not broken))))