You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ThreadStackFactoryImpl.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* *******************************************************************
  2. * Copyright (c) 2004 IBM Corporation
  3. *
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v 2.0
  7. * which accompanies this distribution and is available at
  8. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  9. *
  10. * Contributors:
  11. * Andy Clement initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.runtime.internal.cflowstack;
  14. import java.util.Stack;
  15. public class ThreadStackFactoryImpl implements ThreadStackFactory {
  16. private static class ThreadStackImpl extends ThreadLocal<Stack> implements ThreadStack {
  17. public Stack initialValue() {
  18. return new Stack();
  19. }
  20. public Stack getThreadStack() {
  21. return get();
  22. }
  23. public void removeThreadStack() {
  24. this.remove();
  25. }
  26. }
  27. public ThreadStack getNewThreadStack() {
  28. return new ThreadStackImpl();
  29. }
  30. private static class ThreadCounterImpl extends ThreadLocal<ThreadCounterImpl.Counter> implements ThreadCounter {
  31. public Counter initialValue() {
  32. return new Counter();
  33. }
  34. public Counter getThreadCounter() {
  35. return get();
  36. }
  37. public void removeThreadCounter() {
  38. this.remove();
  39. }
  40. public void inc() { getThreadCounter().value++; }
  41. public void dec() { getThreadCounter().value--; }
  42. public boolean isNotZero() { return getThreadCounter().value!= 0; }
  43. static class Counter {
  44. protected int value = 0;
  45. }
  46. }
  47. public ThreadCounter getNewThreadCounter() {
  48. return new ThreadCounterImpl();
  49. }
  50. }