| MkWeakOp
| DeRefWeakOp
- | FinaliseWeakOp
+ | FinalizeWeakOp
| MakeStableNameOp
| EqStableNameOp
tagOf_PrimOp WriteForeignObjOp = ILIT(202)
tagOf_PrimOp MkWeakOp = ILIT(203)
tagOf_PrimOp DeRefWeakOp = ILIT(204)
-tagOf_PrimOp FinaliseWeakOp = ILIT(205)
+tagOf_PrimOp FinalizeWeakOp = ILIT(205)
tagOf_PrimOp MakeStableNameOp = ILIT(206)
tagOf_PrimOp EqStableNameOp = ILIT(207)
tagOf_PrimOp StableNameToIntOp = ILIT(208)
WriteForeignObjOp,
MkWeakOp,
DeRefWeakOp,
- FinaliseWeakOp,
+ FinalizeWeakOp,
MakeStableNameOp,
EqStableNameOp,
StableNameToIntOp,
\end{code}
The following operation dereferences a weak pointer. The weak pointer
-may have been finalised, so the operation returns a result code which
+may have been finalized, so the operation returns a result code which
must be inspected before looking at the dereferenced value.
deRefWeak# :: Weak# v -> State# RealWorld ->
(unboxedTriple [realWorldStatePrimTy, intPrimTy, alphaTy])
\end{code}
-Weak pointers can be finalised early by using the finalise# operation:
+Weak pointers can be finalized early by using the finalize# operation:
- finalise# :: Weak# v -> State# RealWorld -> State# RealWorld
+ finalizeWeak# :: Weak# v -> State# RealWorld ->
+ (# State# RealWorld, Int#, IO () #)
+
+The Int# returned is either
+
+ 0 if the weak pointer has already been finalized, or it has no
+ finalizer (the third component is then invalid).
+
+ 1 if the weak pointer is still alive, with the finalizer returned
+ as the third component.
\begin{code}
-primOpInfo FinaliseWeakOp
- = mkGenPrimOp SLIT("finaliseWeak#") [alphaTyVar]
+primOpInfo FinalizeWeakOp
+ = mkGenPrimOp SLIT("finalizeWeak#") [alphaTyVar]
[mkWeakPrimTy alphaTy, realWorldStatePrimTy]
- realWorldStatePrimTy
+ (unboxedTriple [realWorldStatePrimTy, intPrimTy,
+ mkFunTy realWorldStatePrimTy
+ (unboxedPair [realWorldStatePrimTy,unitTy])])
\end{code}
%************************************************************************
FloatDecodeOp -> True
DoubleDecodeOp -> True
MkWeakOp -> True
- FinaliseWeakOp -> True
+ FinalizeWeakOp -> True
MakeStableNameOp -> True
MakeForeignObjOp -> True
NewMutVarOp -> True
primOpHasSideEffects WriteForeignObjOp = True
primOpHasSideEffects MkWeakOp = True
primOpHasSideEffects DeRefWeakOp = True
-primOpHasSideEffects FinaliseWeakOp = True
+primOpHasSideEffects FinalizeWeakOp = True
primOpHasSideEffects MakeStablePtrOp = True
primOpHasSideEffects MakeStableNameOp = True
primOpHasSideEffects EqStablePtrOp = True -- SOF
/* ----------------------------------------------------------------------------
- * $Id: Closures.h,v 1.7 1999/02/05 16:02:21 simonm Exp $
+ * $Id: Closures.h,v 1.8 1999/02/11 14:22:56 simonm Exp $
*
* (c) The GHC Team, 1998-1999
*
StgHeader header;
StgClosure *key;
StgClosure *value; /* v */
- StgClosure *finaliser;
+ StgClosure *finalizer;
struct _StgWeak *link;
} StgWeak;
/* -----------------------------------------------------------------------------
- * $Id: PrimOps.h,v 1.16 1999/02/05 16:02:25 simonm Exp $
+ * $Id: PrimOps.h,v 1.17 1999/02/11 14:22:57 simonm Exp $
*
* (c) The GHC Team, 1998-1999
*
#ifndef PAR
EF_(mkWeakzh_fast);
-EF_(finaliseWeakzh_fast);
+EF_(finalizeWeakzh_fast);
#define deRefWeakzh(code,val,w) \
if (((StgWeak *)w)->header.info == &WEAK_info) { \
/* -----------------------------------------------------------------------------
- * $Id: PrimOps.hc,v 1.13 1999/02/05 16:02:45 simonm Exp $
+ * $Id: PrimOps.hc,v 1.14 1999/02/11 14:22:53 simonm Exp $
*
* (c) The GHC Team, 1998-1999
*
{
/* R1.p = key
R2.p = value
- R3.p = finaliser
+ R3.p = finalizer
*/
StgWeak *w;
FB_
w->key = R1.cl;
w->value = R2.cl;
if (R3.cl) {
- w->finaliser = R3.cl;
+ w->finalizer = R3.cl;
} else {
- w->finaliser = &NO_FINALISER_closure;
+ w->finalizer = &NO_FINALIZER_closure;
}
w->link = weak_ptr_list;
FE_
}
-FN_(finaliseWeakzh_fast)
+FN_(finalizeWeakzh_fast)
{
/* R1.p = weak ptr
*/
TICK_RET_UNBOXED_TUP(0);
w = (StgWeak *)R1.p;
- if (w->finaliser != &NO_FINALISER_closure) {
-#ifdef INTERPRETER
- STGCALL2(createGenThread, RtsFlags.GcFlags.initialStkSize, w->finaliser);
-#else
- STGCALL2(createIOThread, RtsFlags.GcFlags.initialStkSize, w->finaliser);
-#endif
+ /* already dead? */
+ if (w->header.info == &DEAD_WEAK_info) {
+ RET_NP(0,&NO_FINALIZER_closure);
}
+
+ /* kill it */
w->header.info = &DEAD_WEAK_info;
- JMP_(ENTRY_CODE(Sp[0]));
+ /* return the finalizer */
+ if (w->finalizer == &NO_FINALIZER_closure) {
+ RET_NP(0,&NO_FINALIZER_closure);
+ } else {
+ RET_NP(1,w->finalizer);
+ }
FE_
}
/* -----------------------------------------------------------------------------
- * $Id: StgMiscClosures.hc,v 1.13 1999/02/05 16:02:58 simonm Exp $
+ * $Id: StgMiscClosures.hc,v 1.14 1999/02/11 14:22:54 simonm Exp $
*
* (c) The GHC Team, 1998-1999
*
NON_ENTERABLE_ENTRY_CODE(DEAD_WEAK);
/* -----------------------------------------------------------------------------
- NO_FINALISER
+ NO_FINALIZER
This is a static nullary constructor (like []) that we use to mark an empty
- finaliser in a weak pointer object.
+ finalizer in a weak pointer object.
-------------------------------------------------------------------------- */
-INFO_TABLE_CONSTR(NO_FINALISER_info,NO_FINALISER_entry,0,0,0,CONSTR_NOCAF_STATIC,const,EF_,0,0);
-NON_ENTERABLE_ENTRY_CODE(NO_FINALISER);
+INFO_TABLE_CONSTR(NO_FINALIZER_info,NO_FINALIZER_entry,0,0,0,CONSTR_NOCAF_STATIC,const,EF_,0,0);
+NON_ENTERABLE_ENTRY_CODE(NO_FINALIZER);
-SET_STATIC_HDR(NO_FINALISER_closure,NO_FINALISER_info,0/*CC*/,,EI_)
+SET_STATIC_HDR(NO_FINALIZER_closure,NO_FINALIZER_info,0/*CC*/,,EI_)
};
/* -----------------------------------------------------------------------------
/* -----------------------------------------------------------------------------
- * $Id: Weak.c,v 1.7 1999/02/05 16:03:03 simonm Exp $
+ * $Id: Weak.c,v 1.8 1999/02/11 14:22:55 simonm Exp $
*
* (c) The GHC Team, 1998-1999
*
- * Weak pointers / finalisers
+ * Weak pointers / finalizers
*
* ---------------------------------------------------------------------------*/
StgWeak *weak_ptr_list;
/*
- * finaliseWeakPointersNow() is called just before the system is shut
- * down. It runs the finaliser for each weak pointer still in the
+ * finalizeWeakPointersNow() is called just before the system is shut
+ * down. It runs the finalizer for each weak pointer still in the
* system.
*/
void
-finaliseWeakPointersNow(void)
+finalizeWeakPointersNow(void)
{
StgWeak *w;
for (w = weak_ptr_list; w; w = w->link) {
IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key));
w->header.info = &DEAD_WEAK_info;
- if (w->finaliser != &NO_FINALISER_closure) {
- rts_evalIO(w->finaliser,NULL);
+ if (w->finalizer != &NO_FINALIZER_closure) {
+ rts_evalIO(w->finalizer,NULL);
}
}
}
/*
- * scheduleFinalisers() is called on the list of weak pointers found
+ * scheduleFinalizers() is called on the list of weak pointers found
* to be dead after a garbage collection. It overwrites each object
- * with DEAD_WEAK, and creates a new thread for the finaliser.
+ * with DEAD_WEAK, and creates a new thread for the finalizer.
*/
void
-scheduleFinalisers(StgWeak *list)
+scheduleFinalizers(StgWeak *list)
{
StgWeak *w;
for (w = list; w; w = w->link) {
IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key));
- if (w->finaliser != &NO_FINALISER_closure) {
+ if (w->finalizer != &NO_FINALIZER_closure) {
#ifdef INTERPRETER
- createGenThread(RtsFlags.GcFlags.initialStkSize, w->finaliser);
+ createGenThread(RtsFlags.GcFlags.initialStkSize, w->finalizer);
#else
- createIOThread(RtsFlags.GcFlags.initialStkSize, w->finaliser);
+ createIOThread(RtsFlags.GcFlags.initialStkSize, w->finalizer);
#endif
}
w->header.info = &DEAD_WEAK_info;