org.objectfabric.ThreadAssert Maven / Gradle / Ivy
/**
* This file is part of ObjectFabric (http://objectfabric.org).
*
* ObjectFabric is licensed under the Apache License, Version 2.0, the terms
* of which may be found at http://www.apache.org/licenses/LICENSE-2.0.html.
*
* Copyright ObjectFabric Inc.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
package org.objectfabric;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicReference;
/**
* Debug purposes. Allows objects to be associated to threads, and asserts that only this
* thread access them. When a context switches thread, a common object needs to be given
* to ensure that the switch is expected on both sides.
*/
final class ThreadAssert {
/**
* Notifies AspectJ checks that this object should be used in an single threaded way.
*/
@interface SingleThreaded {
}
/**
* Notifies AspectJ checks that this object should be used in an single threaded way,
* and can be shared at some point between threads. Only reads are allowed on fields
* once instance has been shared.
*/
@interface SingleThreadedThenShared {
}
@interface AllowSharedRead {
}
@interface AllowSharedWrite {
}
private static final PlatformThreadLocal _current;
private static final PlatformConcurrentMap _map;
private static final PlatformConcurrentMap _shared;
private static final PlatformMap> _exchangedObjects;
private static final PlatformConcurrentMap _suspendedContexts;
private static final PlatformThreadLocal