From cb0e4c283857f6ed9860bc736ada033b9025ffd7 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Sat, 26 Oct 2002 20:25:11 +0000 Subject: [PATCH] getUniqToken() new method. --- .../cdt/debug/mi/core/command/Command.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/Command.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/Command.java index c068aeb4658..6782f2bd337 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/Command.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/Command.java @@ -15,21 +15,40 @@ import org.eclipse.cdt.debug.mi.core.output.MIOutput; */ public abstract class Command { + private static int globalCounter; + int token = 0; MIOutput output; + /** + * A global counter for all command, the token + * will be use to identify uniquely a command. + * Unless the value wraps around which is unlikely. + */ + private static synchronized int getUniqToken() { + int count = ++globalCounter; + // If we ever wrap around. + if (count <= 0) { + count = globalCounter = 1; + } + return count; + } + /** * Returns the identifier of this request. * * @return the identifier of this request */ public int getToken() { + if (token == 0) { + token = getUniqToken(); + } return token; } - public void setToken(int token) { - this.token = token; - } +// public void setToken(int token) { +// this.token = token; +// } public MIOutput getMIOutput() { return output;