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.
14 (defun make-weak-pointer (object)
16 "Allocates and returns a weak pointer which points to OBJECT."
17 (declare (values weak-pointer))
18 (make-weak-pointer object))
20 #!-sb-fluid (declaim (inline weak-pointer-value))
21 (defun weak-pointer-value (weak-pointer)
23 "If WEAK-POINTER is valid, returns the value of WEAK-POINTER and T.
24 If the referent of WEAK-POINTER has been garbage collected, returns
25 the values NIL and NIL."
26 (declare (type weak-pointer weak-pointer)
27 (values t (member t nil)))
28 ;; We don't need to wrap this with a without-gcing, because once we have
29 ;; extracted the value, our reference to it will keep the weak pointer
30 ;; from becoming broken. We just have to make sure the compiler won't
31 ;; reorder these primitives.
32 (let ((value (sb!c::%weak-pointer-value weak-pointer))
33 (broken (sb!c::%weak-pointer-broken weak-pointer)))
34 (values value (not broken))))