equal
deleted
inserted
replaced
42 // Adds the current native thread to this set, returning its index so that |
42 // Adds the current native thread to this set, returning its index so that |
43 // it can efficiently be removed later. |
43 // it can efficiently be removed later. |
44 // |
44 // |
45 int add() { |
45 int add() { |
46 long th = NativeThread.current(); |
46 long th = NativeThread.current(); |
47 if (th == -1) |
47 // 0 and -1 are treated as placeholders, not real thread handles |
48 return -1; |
48 if (th == 0) |
|
49 th = -1; |
49 synchronized (this) { |
50 synchronized (this) { |
50 int start = 0; |
51 int start = 0; |
51 if (used >= elts.length) { |
52 if (used >= elts.length) { |
52 int on = elts.length; |
53 int on = elts.length; |
53 int nn = on * 2; |
54 int nn = on * 2; |
69 } |
70 } |
70 |
71 |
71 // Removes the thread at the given index. |
72 // Removes the thread at the given index. |
72 // |
73 // |
73 void remove(int i) { |
74 void remove(int i) { |
74 if (i < 0) |
|
75 return; |
|
76 synchronized (this) { |
75 synchronized (this) { |
77 elts[i] = 0; |
76 elts[i] = 0; |
78 used--; |
77 used--; |
79 if (used == 0 && waitingToEmpty) |
78 if (used == 0 && waitingToEmpty) |
80 notifyAll(); |
79 notifyAll(); |
89 int n = elts.length; |
88 int n = elts.length; |
90 for (int i = 0; i < n; i++) { |
89 for (int i = 0; i < n; i++) { |
91 long th = elts[i]; |
90 long th = elts[i]; |
92 if (th == 0) |
91 if (th == 0) |
93 continue; |
92 continue; |
94 NativeThread.signal(th); |
93 if (th != -1) |
|
94 NativeThread.signal(th); |
95 if (--u == 0) |
95 if (--u == 0) |
96 break; |
96 break; |
97 } |
97 } |
98 waitingToEmpty = true; |
98 waitingToEmpty = true; |
99 boolean interrupted = false; |
99 boolean interrupted = false; |