Commit b41f38a4 authored by simonm's avatar simonm
Browse files

[project @ 1999-02-11 14:22:53 by simonm]

- 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
parent 71d4a947
......@@ -172,7 +172,7 @@ data PrimOp
| MkWeakOp
| DeRefWeakOp
| FinaliseWeakOp
| FinalizeWeakOp
| MakeStableNameOp
| EqStableNameOp
......@@ -501,7 +501,7 @@ tagOf_PrimOp MakeForeignObjOp = ILIT(201)
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)
......@@ -767,7 +767,7 @@ allThePrimOps
WriteForeignObjOp,
MkWeakOp,
DeRefWeakOp,
FinaliseWeakOp,
FinalizeWeakOp,
MakeStableNameOp,
EqStableNameOp,
StableNameToIntOp,
......@@ -1542,7 +1542,7 @@ primOpInfo MkWeakOp
\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 ->
......@@ -1561,15 +1561,26 @@ primOpInfo DeRefWeakOp
(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}
%************************************************************************
......@@ -1805,7 +1816,7 @@ primOpOutOfLine op
FloatDecodeOp -> True
DoubleDecodeOp -> True
MkWeakOp -> True
FinaliseWeakOp -> True
FinalizeWeakOp -> True
MakeStableNameOp -> True
MakeForeignObjOp -> True
NewMutVarOp -> True
......@@ -1887,7 +1898,7 @@ primOpHasSideEffects MakeForeignObjOp = 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
*
......@@ -260,7 +260,7 @@ typedef struct _StgWeak { /* Weak v */
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
*
......@@ -686,7 +686,7 @@ EF_(seqzh_fast);
#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
*
......@@ -300,7 +300,7 @@ FN_(mkWeakzh_fast)
{
/* R1.p = key
R2.p = value
R3.p = finaliser
R3.p = finalizer
*/
StgWeak *w;
FB_
......@@ -316,9 +316,9 @@ FN_(mkWeakzh_fast)
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;
......@@ -330,7 +330,7 @@ FN_(mkWeakzh_fast)
FE_
}
FN_(finaliseWeakzh_fast)
FN_(finalizeWeakzh_fast)
{
/* R1.p = weak ptr
*/
......@@ -339,16 +339,20 @@ FN_(finaliseWeakzh_fast)
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
*
......@@ -240,16 +240,16 @@ INFO_TABLE_CONSTR(DEAD_WEAK_info,DEAD_WEAK_entry,0,1,0,CONSTR,const,EF_,0,0);
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
*
* ---------------------------------------------------------------------------*/
......@@ -16,43 +16,43 @@
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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment