Merged gcj-eclipse branch to trunk.
From-SVN: r120621
This commit is contained in:
parent
c648dedbde
commit
97b8365caf
17478 changed files with 606493 additions and 100744 deletions
|
@ -1,5 +1,5 @@
|
|||
/* ThreadLocal -- a variable with a unique value per thread
|
||||
Copyright (C) 2000, 2002, 2003, 2006 Free Software Foundation, Inc.
|
||||
Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
|
@ -84,16 +84,16 @@ import java.util.Map;
|
|||
* @author Mark Wielaard (mark@klomp.org)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.2
|
||||
* @status updated to 1.4
|
||||
* @status updated to 1.5
|
||||
*/
|
||||
public class ThreadLocal
|
||||
public class ThreadLocal<T>
|
||||
{
|
||||
/**
|
||||
* Placeholder to distinguish between uninitialized and null set by the
|
||||
* user. Do not expose this to the public. Package visible for use by
|
||||
* InheritableThreadLocal
|
||||
*/
|
||||
static final Object NULL = new Object();
|
||||
static final Object sentinel = new Object();
|
||||
|
||||
/**
|
||||
* Creates a ThreadLocal object without associating any value to it yet.
|
||||
|
@ -110,7 +110,7 @@ public class ThreadLocal
|
|||
*
|
||||
* @return the initial value of the variable in this thread
|
||||
*/
|
||||
protected Object initialValue()
|
||||
protected T initialValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -123,18 +123,18 @@ public class ThreadLocal
|
|||
*
|
||||
* @return the value of the variable in this thread
|
||||
*/
|
||||
public Object get()
|
||||
public T get()
|
||||
{
|
||||
Map map = Thread.getThreadLocals();
|
||||
Map<ThreadLocal<T>,T> map = (Map<ThreadLocal<T>,T>) Thread.getThreadLocals();
|
||||
// Note that we don't have to synchronize, as only this thread will
|
||||
// ever modify the map.
|
||||
Object value = map.get(this);
|
||||
T value = map.get(this);
|
||||
if (value == null)
|
||||
{
|
||||
value = initialValue();
|
||||
map.put(this, value == null ? NULL : value);
|
||||
map.put(this, (T) (value == null ? sentinel : value));
|
||||
}
|
||||
return value == NULL ? null : value;
|
||||
return value == (T) sentinel ? null : value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,12 +145,12 @@ public class ThreadLocal
|
|||
*
|
||||
* @param value the value to set this thread's view of the variable to
|
||||
*/
|
||||
public void set(Object value)
|
||||
public void set(T value)
|
||||
{
|
||||
Map map = Thread.getThreadLocals();
|
||||
// Note that we don't have to synchronize, as only this thread will
|
||||
// ever modify the map.
|
||||
map.put(this, value == null ? NULL : value);
|
||||
map.put(this, value == null ? sentinel : value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue