blob: 313bafd8b05988581e58e856c3b2a325eac432fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
//
// System.Windows.Forms.XEventQueue
//
// Author(s):
// Jackson Harper (jackson@ximian.com)
//
// Copyright (C) Novell, Inc (http://www.novell.com)
//
using System;
using System.Threading;
using System.Collections;
namespace System.Windows.Forms {
internal class XEventQueue {
private XQueue xqueue;
private XQueue lqueue; // Events inserted from threads other then the main X thread
private static readonly int InitialXEventSize = 100;
private static readonly int InitialLXEventSize = 10;
public XEventQueue ()
{
xqueue = new XQueue (InitialXEventSize);
lqueue = new XQueue (InitialLXEventSize);
}
public int Count {
get {
lock (lqueue) {
return xqueue.Count + lqueue.Count;
}
}
}
public void Enqueue (XEvent xevent)
{
xqueue.Enqueue (xevent);
}
public void EnqueueLocked (XEvent xevent)
{
lock (lqueue) {
lqueue.Enqueue (xevent);
}
}
public XEvent Dequeue ()
{
if (xqueue.Count == 0) {
lock (lqueue) {
return lqueue.Dequeue ();
}
}
return xqueue.Dequeue ();
}
private class XQueue {
private XEvent [] xevents;
private int head;
private int tail;
private int size;
public XQueue (int size)
{
xevents = new XEvent [size];
}
public int Count {
get { return size; }
}
public void Enqueue (XEvent xevent)
{
if (size == xevents.Length)
Grow ();
xevents [tail] = xevent;
tail = (tail + 1) % xevents.Length;
size++;
}
public XEvent Dequeue ()
{
if (size < 1)
throw new Exception ("Attempt to dequeue empty queue.");
XEvent res = xevents [head];
head = (head + 1) % xevents.Length;
size--;
return res;
}
private void Grow ()
{
int newcap = (xevents.Length * 2);
XEvent [] na = new XEvent [newcap];
xevents.CopyTo (na, 0);
xevents = na;
head = 0;
tail = head + size;
}
}
}
}
|