wasCSharpSQLite – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * EventuallyFreed.java -- |
||
3 | * |
||
4 | * This class makes sure that certain objects |
||
5 | * aren't disposed when there are nested procedures that |
||
6 | * depend on their existence. |
||
7 | * |
||
8 | * Copyright (c) 1991-1994 The Regents of the University of California. |
||
9 | * Copyright (c) 1994-1998 Sun Microsystems, Inc. |
||
10 | * Copyright (c) 2000 Christian Krone. |
||
11 | * |
||
12 | * See the file "license.terms" for information on usage and redistribution |
||
13 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
||
14 | * |
||
15 | * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart |
||
16 | * |
||
17 | * RCS @(#) $Id: EventuallyFreed.java,v 1.2 2001/06/03 21:19:46 mdejong Exp $ |
||
18 | */ |
||
19 | using System; |
||
20 | namespace tcl.lang |
||
21 | { |
||
22 | |||
23 | public abstract class EventuallyFreed |
||
24 | { |
||
25 | |||
26 | // Number of preserve() calls in effect for this object. |
||
27 | |||
28 | internal int refCount = 0; |
||
29 | |||
30 | // True means dispose() was called while a preserve() |
||
31 | // call was in effect, so the object must be disposed |
||
32 | // when refCount becomes zero. |
||
33 | |||
34 | internal bool mustFree = false; |
||
35 | |||
36 | // Procedure to call to dispose. |
||
37 | |||
38 | public abstract void eventuallyDispose(); |
||
39 | internal void preserve() |
||
40 | { |
||
41 | // Just increment its reference count. |
||
42 | |||
43 | refCount++; |
||
44 | } |
||
45 | internal void release() |
||
46 | { |
||
47 | refCount--; |
||
48 | if ( refCount == 0 ) |
||
49 | { |
||
50 | |||
51 | if ( mustFree ) |
||
52 | { |
||
53 | dispose(); |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | public void dispose() |
||
58 | { |
||
59 | // See if there is a reference for this pointer. If so, set its |
||
60 | // "mustFree" flag (the flag had better not be set already!). |
||
61 | |||
62 | if ( refCount >= 1 ) |
||
63 | { |
||
64 | if ( mustFree ) |
||
65 | { |
||
66 | throw new TclRuntimeError( "eventuallyDispose() called twice" ); |
||
67 | } |
||
68 | mustFree = true; |
||
69 | return; |
||
70 | } |
||
71 | |||
72 | // No reference for this block. Free it now. |
||
73 | |||
74 | eventuallyDispose(); |
||
75 | } |
||
76 | } // end EventuallyFreed |
||
77 | } |