156 |
|
* } |
157 |
|
* } |
158 |
|
* } finally { |
159 |
< |
* sl.unlock(stamp); |
159 |
> |
* sl.unlock(stamp); |
160 |
|
* } |
161 |
|
* } |
162 |
|
* }}</pre> |
226 |
|
* threads. Both await methods use a similar spin strategy: If |
227 |
|
* the associated queue appears to be empty, then the thread |
228 |
|
* spin-waits up to SPINS times (where each iteration decreases |
229 |
< |
* spin count with 50% probability) before enqueing, and then, if |
229 |
> |
* spin count with 50% probability) before enqueuing, and then, if |
230 |
|
* it is the first thread to be enqueued, spins again up to SPINS |
231 |
|
* times before blocking. If, upon wakening it fails to obtain |
232 |
|
* lock, and is still (or becomes) the first waiting thread (which |
252 |
|
* be subject to future improvements. |
253 |
|
*/ |
254 |
|
|
255 |
+ |
private static final long serialVersionUID = -6001602636862214147L; |
256 |
+ |
|
257 |
|
/** Number of processors, for spin control */ |
258 |
|
private static final int NCPU = Runtime.getRuntime().availableProcessors(); |
259 |
|
|
1206 |
|
private static sun.misc.Unsafe getUnsafe() { |
1207 |
|
try { |
1208 |
|
return sun.misc.Unsafe.getUnsafe(); |
1209 |
< |
} catch (SecurityException se) { |
1210 |
< |
try { |
1211 |
< |
return java.security.AccessController.doPrivileged |
1212 |
< |
(new java.security |
1213 |
< |
.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
1214 |
< |
public sun.misc.Unsafe run() throws Exception { |
1215 |
< |
java.lang.reflect.Field f = sun.misc |
1216 |
< |
.Unsafe.class.getDeclaredField("theUnsafe"); |
1217 |
< |
f.setAccessible(true); |
1218 |
< |
return (sun.misc.Unsafe) f.get(null); |
1219 |
< |
}}); |
1220 |
< |
} catch (java.security.PrivilegedActionException e) { |
1221 |
< |
throw new RuntimeException("Could not initialize intrinsics", |
1222 |
< |
e.getCause()); |
1223 |
< |
} |
1209 |
> |
} catch (SecurityException tryReflectionInstead) {} |
1210 |
> |
try { |
1211 |
> |
return java.security.AccessController.doPrivileged |
1212 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
1213 |
> |
public sun.misc.Unsafe run() throws Exception { |
1214 |
> |
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; |
1215 |
> |
for (java.lang.reflect.Field f : k.getDeclaredFields()) { |
1216 |
> |
f.setAccessible(true); |
1217 |
> |
Object x = f.get(null); |
1218 |
> |
if (k.isInstance(x)) |
1219 |
> |
return k.cast(x); |
1220 |
> |
} |
1221 |
> |
throw new NoSuchFieldError("the Unsafe"); |
1222 |
> |
}}); |
1223 |
> |
} catch (java.security.PrivilegedActionException e) { |
1224 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
1225 |
> |
e.getCause()); |
1226 |
|
} |
1227 |
|
} |
1224 |
– |
|
1228 |
|
} |