wasCSharpSQLite – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*
2 * IdleHandler.java --
3 *
4 * The API for defining idle event handler.
5 *
6 * Copyright (c) 1997 Sun Microsystems, Inc.
7 *
8 * See the file "license.terms" for information on usage and
9 * redistribution of this file, and for a DISCLAIMER OF ALL
10 * WARRANTIES.
11 *
12 * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart
13 *
14 * RCS @(#) $Id: IdleHandler.java,v 1.1.1.1 1998/10/14 21:09:21 cvsadmin Exp $
15 *
16 */
17 using System;
18 namespace tcl.lang
19 {
20  
21 /*
22 * This abstract class is used to define idle handlers.
23 */
24  
25 public abstract class IdleHandler
26 {
27  
28 /*
29 * Back pointer to the notifier that will fire this idle.
30 */
31  
32 internal Notifier notifier;
33  
34 /*
35 * True if the cancel() method has been called.
36 */
37  
38 internal bool isCancelled;
39  
40 /*
41 * Used to distinguish older idle handlers from recently-created ones.
42 */
43  
44 internal int generation;
45  
46 public IdleHandler( Notifier n )
47 {
48 notifier = (Notifier)n;
49 isCancelled = false;
50  
51 lock ( notifier )
52 {
53 notifier.idleList.Add( this );
54 generation = notifier.idleGeneration;
55 if ( System.Threading.Thread.CurrentThread != notifier.primaryThread )
56 {
57 System.Threading.Monitor.PulseAll( notifier );
58 }
59 }
60 }
61 public void cancel()
62 {
63 lock ( this )
64 {
65 if ( isCancelled )
66 {
67 return;
68 }
69  
70 isCancelled = true;
71  
72 lock ( notifier )
73 {
74 for ( int i = 0; i < notifier.idleList.Count; i++ )
75 {
76 if ( notifier.idleList[i] == this )
77 {
78 notifier.idleList.RemoveAt( i );
79  
80 /*
81 * We can return now because the same idle handler can
82 * be registered only once in the list of idles.
83 */
84  
85 return;
86 }
87 }
88 }
89 }
90 }
91 internal int invoke()
92 {
93 lock ( this )
94 {
95 /*
96 * The idle handler may be cancelled after it was registered in
97 * the notifier. Check the isCancelled field to make sure it's not
98 * cancelled.
99 */
100  
101 if ( !isCancelled )
102 {
103 processIdleEvent();
104 return 1;
105 }
106 else
107 {
108 return 0;
109 }
110 }
111 }
112 abstract public void processIdleEvent();
113 } // end IdleHandler
114 }