wasCSharpSQLite – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * TclEvent.java -- |
||
3 | * |
||
4 | * Abstract class for describing an event in the Tcl notifier |
||
5 | * API. |
||
6 | * |
||
7 | * Copyright (c) 1997 Cornell University. |
||
8 | * Copyright (c) 1997 Sun Microsystems, Inc. |
||
9 | * |
||
10 | * See the file "license.terms" for information on usage and |
||
11 | * redistribution of this file, and for a DISCLAIMER OF ALL |
||
12 | * WARRANTIES. |
||
13 | * |
||
14 | * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart |
||
15 | * |
||
16 | * RCS @(#) $Id: TclEvent.java,v 1.3 2003/03/11 01:45:53 mdejong Exp $ |
||
17 | * |
||
18 | */ |
||
19 | using System; |
||
20 | namespace tcl.lang |
||
21 | { |
||
22 | |||
23 | /* |
||
24 | * This is an abstract class that describes an event in the Jacl |
||
25 | * implementation of the notifier. It contains package protected |
||
26 | * fields and methods that are accessed by the Jacl notifier. Tcl Blend |
||
27 | * needs a different implementation of the TclEvent base class. |
||
28 | * |
||
29 | * The only public methods in this class are processEvent() and |
||
30 | * sync(). These methods must appear in both the Jacl and Tcl Blend versions |
||
31 | * of this class. |
||
32 | */ |
||
33 | |||
34 | public abstract class TclEvent |
||
35 | { |
||
36 | |||
37 | /* |
||
38 | * The notifier in which this event is queued. |
||
39 | */ |
||
40 | |||
41 | internal Notifier notifier = null; |
||
42 | |||
43 | /* |
||
44 | * This flag is true if sync() has been called on this object. |
||
45 | */ |
||
46 | |||
47 | internal bool needsNotify = false; |
||
48 | |||
49 | /* |
||
50 | * True if this event is current being processing. This flag provents |
||
51 | * an event to be processed twice when the event loop is entered |
||
52 | * recursively. |
||
53 | */ |
||
54 | |||
55 | internal bool isProcessing = false; |
||
56 | |||
57 | /* |
||
58 | * True if this event has been processed. |
||
59 | */ |
||
60 | |||
61 | internal bool isProcessed = false; |
||
62 | |||
63 | /* |
||
64 | * Links to the next event in the event queue. |
||
65 | */ |
||
66 | |||
67 | internal TclEvent next; |
||
68 | |||
69 | public abstract int processEvent( int flags ); // Same as flags passed to Notifier.doOneEvent. |
||
70 | |||
71 | public void sync() |
||
72 | { |
||
73 | if ( notifier == null ) |
||
74 | { |
||
75 | throw new TclRuntimeError( "TclEvent is not queued when sync() is called" ); |
||
76 | } |
||
77 | |||
78 | if ( System.Threading.Thread.CurrentThread == notifier.primaryThread ) |
||
79 | { |
||
80 | while ( !isProcessed ) |
||
81 | { |
||
82 | notifier.serviceEvent( 0 ); |
||
83 | } |
||
84 | } |
||
85 | else |
||
86 | { |
||
87 | lock ( this ) |
||
88 | { |
||
89 | needsNotify = true; |
||
90 | while ( !isProcessed ) |
||
91 | { |
||
92 | try |
||
93 | { |
||
94 | System.Threading.Monitor.Wait( this, TimeSpan.FromMilliseconds( 0 ) ); |
||
95 | } |
||
96 | catch ( System.Threading.ThreadInterruptedException e ) |
||
97 | { |
||
98 | // Another thread has sent us an "interrupt" |
||
99 | // signal. We ignore it and continue waiting until |
||
100 | // the event is processed. |
||
101 | |||
102 | continue; |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | } |
||
108 | } // end TclEvent |
||
109 | } |