- s/finalise/finalize/g
- make finalize run the finalizer immediately, and wait for its completion
- make mkWeak take a (Maybe (IO ())) for the finalizer argument
- remove mkWeakNoFinalizer
| MakeStableNameOp
| EqStableNameOp
| MakeStableNameOp
| EqStableNameOp
tagOf_PrimOp WriteForeignObjOp = ILIT(202)
tagOf_PrimOp MkWeakOp = ILIT(203)
tagOf_PrimOp DeRefWeakOp = ILIT(204)
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)
tagOf_PrimOp MakeStableNameOp = ILIT(206)
tagOf_PrimOp EqStableNameOp = ILIT(207)
tagOf_PrimOp StableNameToIntOp = ILIT(208)
WriteForeignObjOp,
MkWeakOp,
DeRefWeakOp,
WriteForeignObjOp,
MkWeakOp,
DeRefWeakOp,
MakeStableNameOp,
EqStableNameOp,
StableNameToIntOp,
MakeStableNameOp,
EqStableNameOp,
StableNameToIntOp,
\end{code}
The following operation dereferences a weak pointer. The weak pointer
\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 ->
must be inspected before looking at the dereferenced value.
deRefWeak# :: Weak# v -> State# RealWorld ->
(unboxedTriple [realWorldStatePrimTy, intPrimTy, alphaTy])
\end{code}
(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.
-primOpInfo FinaliseWeakOp
- = mkGenPrimOp SLIT("finaliseWeak#") [alphaTyVar]
+primOpInfo FinalizeWeakOp
+ = mkGenPrimOp SLIT("finalizeWeak#") [alphaTyVar]
[mkWeakPrimTy alphaTy, realWorldStatePrimTy]
[mkWeakPrimTy alphaTy, realWorldStatePrimTy]
+ (unboxedTriple [realWorldStatePrimTy, intPrimTy,
+ mkFunTy realWorldStatePrimTy
+ (unboxedPair [realWorldStatePrimTy,unitTy])])
\end{code}
%************************************************************************
\end{code}
%************************************************************************
FloatDecodeOp -> True
DoubleDecodeOp -> True
MkWeakOp -> True
FloatDecodeOp -> True
DoubleDecodeOp -> True
MkWeakOp -> True
MakeStableNameOp -> True
MakeForeignObjOp -> True
NewMutVarOp -> True
MakeStableNameOp -> True
MakeForeignObjOp -> True
NewMutVarOp -> True
primOpHasSideEffects WriteForeignObjOp = True
primOpHasSideEffects MkWeakOp = True
primOpHasSideEffects DeRefWeakOp = 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
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
*
*
* (c) The GHC Team, 1998-1999
*
StgHeader header;
StgClosure *key;
StgClosure *value; /* v */
StgHeader header;
StgClosure *key;
StgClosure *value; /* v */
struct _StgWeak *link;
} StgWeak;
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
*
*
* (c) The GHC Team, 1998-1999
*
#ifndef PAR
EF_(mkWeakzh_fast);
#ifndef PAR
EF_(mkWeakzh_fast);
-EF_(finaliseWeakzh_fast);
+EF_(finalizeWeakzh_fast);
#define deRefWeakzh(code,val,w) \
if (((StgWeak *)w)->header.info == &WEAK_info) { \
#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
*
*
* (c) The GHC Team, 1998-1999
*
{
/* R1.p = key
R2.p = value
{
/* R1.p = key
R2.p = value
w->key = R1.cl;
w->value = R2.cl;
if (R3.cl) {
w->key = R1.cl;
w->value = R2.cl;
if (R3.cl) {
- w->finaliser = &NO_FINALISER_closure;
+ w->finalizer = &NO_FINALIZER_closure;
}
w->link = weak_ptr_list;
}
w->link = weak_ptr_list;
-FN_(finaliseWeakzh_fast)
+FN_(finalizeWeakzh_fast)
TICK_RET_UNBOXED_TUP(0);
w = (StgWeak *)R1.p;
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);
w->header.info = &DEAD_WEAK_info;
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);
+ }
/* -----------------------------------------------------------------------------
/* -----------------------------------------------------------------------------
- * $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
*
*
* (c) The GHC Team, 1998-1999
*
NON_ENTERABLE_ENTRY_CODE(DEAD_WEAK);
/* -----------------------------------------------------------------------------
NON_ENTERABLE_ENTRY_CODE(DEAD_WEAK);
/* -----------------------------------------------------------------------------
This is a static nullary constructor (like []) that we use to mark an empty
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
*
*
* (c) The GHC Team, 1998-1999
*
- * Weak pointers / finalisers
+ * Weak pointers / finalizers
*
* ---------------------------------------------------------------------------*/
*
* ---------------------------------------------------------------------------*/
StgWeak *weak_ptr_list;
/*
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
-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;
{
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
* 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.
-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));
{
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) {
- createGenThread(RtsFlags.GcFlags.initialStkSize, w->finaliser);
+ createGenThread(RtsFlags.GcFlags.initialStkSize, w->finalizer);
- createIOThread(RtsFlags.GcFlags.initialStkSize, w->finaliser);
+ createIOThread(RtsFlags.GcFlags.initialStkSize, w->finalizer);
#endif
}
w->header.info = &DEAD_WEAK_info;
#endif
}
w->header.info = &DEAD_WEAK_info;