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.
12 (in-package "SB!IMPL")
14 (defun make-weak-pointer (object)
16 "Allocate and return a weak pointer which points to OBJECT."
17 (make-weak-pointer object
))
19 #!-sb-fluid
(declaim (inline weak-pointer-value
))
20 (defun weak-pointer-value (weak-pointer)
22 "If WEAK-POINTER is valid, return the value of WEAK-POINTER and T.
23 If the referent of WEAK-POINTER has been garbage collected,
24 returns the values NIL and NIL."
25 (declare (type weak-pointer weak-pointer
))
26 ;; We don't need to wrap this with a WITHOUT-GCING, because once we
27 ;; have extracted the value, our reference to it will keep the weak
28 ;; pointer from becoming broken. We just have to make sure the
29 ;; compiler won't reorder these primitives.
31 ;; FIXME: Might it be a good idea to tweak the DEFKNOWNs for
32 ;; %WEAK-POINTER-VALUE and %WEAK-POINTER-BROKEN, so that the
33 ;; compiler will never try to reorder them even in code where we
34 ;; neglect to frame them in a LET?
35 (let ((value (sb!c
::%weak-pointer-value weak-pointer
))
36 (broken (sb!c
::%weak-pointer-broken weak-pointer
)))
37 (values value
(not broken
))))