/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#import "com_apple_concurrent_LibDispatchNative.h"
#import <dispatch/dispatch.h>
/*
* Class: com_apple_concurrent_LibDispatchNative
* Method: nativeIsDispatchSupported
* Signature: ()Z
*/
{
return JNI_TRUE;
}
/*
* Class: com_apple_concurrent_LibDispatchNative
* Method: nativeGetMainQueue
* Signature: ()J
*/
{
return ptr_to_jlong(queue);
}
/*
* Class: com_apple_concurrent_LibDispatchNative
* Method: nativeCreateConcurrentQueue
* Signature: (I)J
*/
{
return ptr_to_jlong(queue);
}
/*
* Class: com_apple_concurrent_LibDispatchNative
* Method: nativeCreateSerialQueue
*/
{
return ptr_to_jlong(queue);
}
/*
* Class: com_apple_concurrent_LibDispatchNative
* Method: nativeReleaseQueue
* Signature: (J)V
*/
{
if (nativeQueue == 0L) return;
}
static void perform_dispatch(JNIEnv *env, jlong nativeQueue, jobject runnable, void (*dispatch_fxn)(dispatch_queue_t, dispatch_block_t))
{
// create a global-ref around the Runnable, so it can be safely passed to the dispatch thread
JNFJObjectWrapper *wrappedRunnable = [[JNFJObjectWrapper alloc] initWithJObject:runnable withEnv:env];
dispatch_fxn(queue, ^{
// attach the dispatch thread to the JVM if necessary, and get an env
JNFThreadContext ctx = JNFThreadDetachOnThreadDeath | JNFThreadSetSystemClassLoaderOnAttach | JNFThreadAttachAsDaemon;
// call the user's runnable
// explicitly clear object while we have an env (it's cheaper that way)
// let the env go, but leave the thread attached as a daemon
});
// release this thread's interest in the Runnable, the block
// will have retained the it's own interest above
}
/*
* Class: com_apple_concurrent_LibDispatchNative
* Method: nativeExecuteAsync
*/
{
// enqueues and returns
}
/*
* Class: com_apple_concurrent_LibDispatchNative
* Method: nativeExecuteSync
*/
{
// blocks until the Runnable completes
}