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.

Selfex.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* -*- Mode: Java; -*-
  2. Copyright (c) Xerox Corporation 1998-2002. All rights reserved.
  3. Use and copying of this software and preparation of derivative works based
  4. upon this software are permitted. Any distribution of this software or
  5. derivative works must comply with all applicable United States export control
  6. laws.
  7. This software is made available AS IS, and Xerox Corporation makes no warranty
  8. about the software, its performance or its conformity to any specification.
  9. |<--- this code is formatted to fit into 80 columns --->|
  10. |<--- this code is formatted to fit into 80 columns --->|
  11. |<--- this code is formatted to fit into 80 columns --->|
  12. */
  13. package coordination;
  14. import java.lang.String;
  15. class Selfex implements Exclusion {
  16. String methodName;
  17. Thread thread;
  18. int count = 0;
  19. Selfex (String _methodName) {
  20. methodName = _methodName;
  21. }
  22. public boolean testExclusion (String _methodName) {
  23. if (count == 0)
  24. return(true);
  25. return (thread == Thread.currentThread());
  26. }
  27. public void enterExclusion (String _methodName) {
  28. count++;
  29. thread = Thread.currentThread(); // note that if count wasn't 0
  30. // we aren't changing thread
  31. }
  32. public void exitExclusion (String _methodName) {
  33. count--;
  34. if (count == 0) // not stricly necessary, but...
  35. thread = null;
  36. }
  37. public void printNames() {
  38. System.out.println("Selfex name: " + methodName);
  39. }
  40. }