|
3 | 3 |
|
4 | 4 | namespace Enyim.Collections |
5 | 5 | { |
6 | | - /// <summary> |
7 | | - /// Implements a non-locking stack. |
8 | | - /// </summary> |
9 | | - /// <typeparam name="TItem"></typeparam> |
10 | | - public class InterlockedStack<TItem> |
11 | | - { |
12 | | - private Node head; |
| 6 | + /// <summary> |
| 7 | + /// Implements a non-locking stack. |
| 8 | + /// </summary> |
| 9 | + /// <typeparam name="TItem"></typeparam> |
| 10 | + [Obsolete] |
| 11 | + public class InterlockedStack<TItem> |
| 12 | + { |
| 13 | + private Node head; |
13 | 14 |
|
14 | | - public InterlockedStack() |
15 | | - { |
16 | | - this.head = new Node(default(TItem)); |
17 | | - } |
| 15 | + public InterlockedStack() |
| 16 | + { |
| 17 | + this.head = new Node(default(TItem)); |
| 18 | + } |
18 | 19 |
|
19 | | - public void Push(TItem item) |
20 | | - { |
21 | | - var node = new Node(item); |
| 20 | + public void Push(TItem item) |
| 21 | + { |
| 22 | + var node = new Node(item); |
22 | 23 |
|
23 | | - do { node.Next = this.head.Next; } |
24 | | - while (Interlocked.CompareExchange(ref this.head.Next, node, node.Next) != node.Next); |
25 | | - } |
| 24 | + do { node.Next = this.head.Next; } |
| 25 | + while (Interlocked.CompareExchange(ref this.head.Next, node, node.Next) != node.Next); |
| 26 | + } |
26 | 27 |
|
27 | | - public bool TryPop(out TItem value) |
28 | | - { |
29 | | - value = default(TItem); |
30 | | - Node node; |
| 28 | + public bool TryPop(out TItem value) |
| 29 | + { |
| 30 | + value = default(TItem); |
| 31 | + Node node; |
31 | 32 |
|
32 | | - do |
33 | | - { |
34 | | - node = head.Next; |
35 | | - if (node == null) return false; |
36 | | - } |
37 | | - while (Interlocked.CompareExchange(ref head.Next, node.Next, node) != node); |
| 33 | + do |
| 34 | + { |
| 35 | + node = head.Next; |
| 36 | + if (node == null) return false; |
| 37 | + } |
| 38 | + while (Interlocked.CompareExchange(ref head.Next, node.Next, node) != node); |
38 | 39 |
|
39 | | - value = node.Value; |
| 40 | + value = node.Value; |
40 | 41 |
|
41 | | - return true; |
42 | | - } |
| 42 | + return true; |
| 43 | + } |
43 | 44 |
|
44 | | - #region [ Node ] |
| 45 | + #region [ Node ] |
45 | 46 |
|
46 | | - private class Node |
47 | | - { |
48 | | - public readonly TItem Value; |
49 | | - public Node Next; |
| 47 | + private class Node |
| 48 | + { |
| 49 | + public readonly TItem Value; |
| 50 | + public Node Next; |
50 | 51 |
|
51 | | - public Node(TItem value) |
52 | | - { |
53 | | - this.Value = value; |
54 | | - } |
55 | | - } |
| 52 | + public Node(TItem value) |
| 53 | + { |
| 54 | + this.Value = value; |
| 55 | + } |
| 56 | + } |
56 | 57 |
|
57 | | - #endregion |
58 | | - } |
| 58 | + #endregion |
| 59 | + } |
59 | 60 | } |
60 | 61 |
|
61 | 62 | #region [ License information ] |
62 | 63 | /* ************************************************************ |
63 | | - * |
| 64 | + * |
64 | 65 | * Copyright (c) 2010 Attila Kiskó, enyim.com |
65 | | - * |
| 66 | + * |
66 | 67 | * Licensed under the Apache License, Version 2.0 (the "License"); |
67 | 68 | * you may not use this file except in compliance with the License. |
68 | 69 | * You may obtain a copy of the License at |
69 | | - * |
| 70 | + * |
70 | 71 | * http://www.apache.org/licenses/LICENSE-2.0 |
71 | | - * |
| 72 | + * |
72 | 73 | * Unless required by applicable law or agreed to in writing, software |
73 | 74 | * distributed under the License is distributed on an "AS IS" BASIS, |
74 | 75 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
75 | 76 | * See the License for the specific language governing permissions and |
76 | 77 | * limitations under the License. |
77 | | - * |
| 78 | + * |
78 | 79 | * ************************************************************/ |
79 | 80 | #endregion |
0 commit comments