1 2 3 4 5 | public final void acquire(int arg) { if (!tryAcquire(arg) && acquireQueued(addWaiter(Node.EXCLUSIVE), arg)) selfInterrupt(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | private Node addWaiter(Node mode) { Node node = new Node(Thread.currentThread(), mode); // Try the fast path of enq; backup to full enq on failure Node prev = tail; if (prev != null) { node.prev = prev; if (compareAndSetTail(prev, node)) { prev.next = node; return node; } } enq(node); return node; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | private Node enq(final Node node) { for (;;) { Node t = tail; if (t == null) { // Must initialize if (compareAndSetHead(new Node())) tail = head; } else { node.prev = t; if (compareAndSetTail(t, node)) { t.next = node; return t; } } } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |