Index: trunk/modules/archive/src/main/native/archive/unix/makefile
===================================================================
--- trunk/modules/archive/src/main/native/archive/unix/makefile (revision 501409)
+++ trunk/modules/archive/src/main/native/archive/unix/makefile (working copy)
@@ -28,7 +28,7 @@
MDLLIBFILES = \
$(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so $(LIBPATH)libhycommon.a \
- $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
+ $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
DLLNAME=../libhyarchive.so
Index: trunk/modules/archive/src/main/native/archive/windows/makefile
===================================================================
--- trunk/modules/archive/src/main/native/archive/windows/makefile (revision 501409)
+++ trunk/modules/archive/src/main/native/archive/windows/makefile (working copy)
@@ -38,8 +38,8 @@
MDLLIBFILES = \
$(LIBPATH)hycommon.lib $(LIBPATH)hysig.lib $(LIBPATH)hyzip.lib \
- $(LIBPATH)hyzlib.lib $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib \
- $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib
+ $(LIBPATH)hyzlib.lib $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib \
+ $(LIBPATH)vmi.lib
DLLBASE=0x13100000
!include <$(HY_HDK)\build\make\rules.mak>
Index: trunk/modules/archive/src/main/native/zip/shared/zipsup.c
===================================================================
--- trunk/modules/archive/src/main/native/zip/shared/zipsup.c (revision 501409)
+++ trunk/modules/archive/src/main/native/zip/shared/zipsup.c (working copy)
@@ -1115,7 +1115,7 @@
zip_closeZipFile (HyPortLibrary * portLib, struct HyZipFile * zipFile)
{
PORT_ACCESS_FROM_PORT (portLib);
-
+ THREAD_ACCESS_FROM_PORT(portLib);
IDATA fd;
ENTER ();
@@ -1325,6 +1325,7 @@
HyZipEntry * zipEntry, IDATA * nextEntryPointer)
{
PORT_ACCESS_FROM_PORT (portLib);
+ THREAD_ACCESS_FROM_PORT(portLib);
IDATA result;
BOOLEAN retryAllowed = TRUE;
IDATA pointer;
@@ -1447,6 +1448,7 @@
BOOLEAN findDirectory)
{
PORT_ACCESS_FROM_PORT (portLib);
+ THREAD_ACCESS_FROM_PORT(portLib);
IDATA result, position;
BOOLEAN retryAllowed = TRUE;
I_64 seekResult;
@@ -1584,6 +1586,7 @@
HyZipEntry * entry, U_8 * buffer, U_32 bufferSize)
{
PORT_ACCESS_FROM_PORT (portLib);
+ THREAD_ACCESS_FROM_PORT(portLib);
I_32 result;
U_8 *dataBuffer;
@@ -1754,6 +1757,7 @@
HyZipEntry * entry, U_8 * buffer, U_32 bufferSize)
{
PORT_ACCESS_FROM_PORT (portLib);
+ THREAD_ACCESS_FROM_PORT(portLib);
I_32 result;
U_8 *extraFieldBuffer;
@@ -1862,6 +1866,7 @@
HyZipEntry * entry, U_8 * buffer, U_32 bufferSize)
{
PORT_ACCESS_FROM_PORT (portLib);
+ THREAD_ACCESS_FROM_PORT(portLib);
I_32 result;
U_8 *fileCommentBuffer;
@@ -1973,6 +1978,7 @@
HyZipCachePool * cachePool)
{
PORT_ACCESS_FROM_PORT (portLib);
+ THREAD_ACCESS_FROM_PORT(portLib);
IDATA fd = -1;
I_32 result = 0;
@@ -2149,6 +2155,7 @@
HyZipEntry * entry, IDATA offset)
{
PORT_ACCESS_FROM_PORT (portLib);
+ THREAD_ACCESS_FROM_PORT(portLib);
I_32 result;
I_64 seekResult;
Index: trunk/modules/auth/src/main/native/auth/unix/makefile
===================================================================
--- trunk/modules/auth/src/main/native/auth/unix/makefile (revision 501409)
+++ trunk/modules/auth/src/main/native/auth/unix/makefile (working copy)
@@ -23,7 +23,7 @@
BUILDFILES = $(SHAREDSUB)auth_copyright.o authnix.o
MDLLIBFILES = \
$(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so $(LIBPATH)libhycommon.a \
- $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
+ $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
DLLNAME = ../libhyauth.so
Index: trunk/modules/auth/src/main/native/auth/windows/makefile
===================================================================
--- trunk/modules/auth/src/main/native/auth/windows/makefile (revision 501409)
+++ trunk/modules/auth/src/main/native/auth/windows/makefile (working copy)
@@ -30,7 +30,7 @@
MDLLIBFILES = $(LIBPATH)hycommon.lib $(LIBPATH)hysig.lib $(LIBPATH)hyzip.lib \
$(LIBPATH)hyzlib.lib $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib \
- $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib
+ $(LIBPATH)vmi.lib
DLLBASE=0x1300000
COMMENT=/comment:"Auth component native code. (c) Copyright 2005, 2006 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/awt/src/main/native/gl/unix/makefile
===================================================================
--- trunk/modules/awt/src/main/native/gl/unix/makefile (revision 501409)
+++ trunk/modules/awt/src/main/native/gl/unix/makefile (working copy)
@@ -30,7 +30,7 @@
MDLLIBFILES = \
$(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so $(LIBPATH)libhycommon.a \
- $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
+ $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
OSLIBS += -lstdc++
Index: trunk/modules/awt/src/main/native/gl/windows/makefile
===================================================================
--- trunk/modules/awt/src/main/native/gl/windows/makefile (revision 501409)
+++ trunk/modules/awt/src/main/native/gl/windows/makefile (working copy)
@@ -44,8 +44,7 @@
MDLLIBFILES = \
$(LIBPATH)hysig.lib $(LIBPATH)hycommon.lib $(LIBPATH)hypool.lib \
- $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib \
- $(LIBPATH)hyzlib.lib $(PNG_DIR)libpng.lib
+ $(LIBPATH)vmi.lib $(LIBPATH)hyzlib.lib $(PNG_DIR)libpng.lib
DLLBASE=0x13300000
COMMENT=/comment:"GL native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/awt/src/main/native/jpegdecoder/unix/makefile
===================================================================
--- trunk/modules/awt/src/main/native/jpegdecoder/unix/makefile (revision 501409)
+++ trunk/modules/awt/src/main/native/jpegdecoder/unix/makefile (working copy)
@@ -26,7 +26,7 @@
MDLLIBFILES = \
$(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so $(LIBPATH)libhycommon.a \
- $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
+ $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
DLLNAME=../libjpegdecoder.so
Index: trunk/modules/awt/src/main/native/jpegdecoder/windows/makefile
===================================================================
--- trunk/modules/awt/src/main/native/jpegdecoder/windows/makefile (revision 501409)
+++ trunk/modules/awt/src/main/native/jpegdecoder/windows/makefile (working copy)
@@ -31,7 +31,7 @@
MDLLIBFILES = \
$(LIBPATH)hysig.lib $(LIBPATH)hycommon.lib $(LIBPATH)hypool.lib \
- $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib $(JPEG_DIR)libjpeg.lib
+ $(LIBPATH)vmi.lib $(JPEG_DIR)libjpeg.lib
DLLBASE=0x13300000
COMMENT=/comment:"JPEGDECODER native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/awt/src/main/native/lcmm/unix/makefile
===================================================================
--- trunk/modules/awt/src/main/native/lcmm/unix/makefile (revision 501409)
+++ trunk/modules/awt/src/main/native/lcmm/unix/makefile (working copy)
@@ -30,7 +30,7 @@
MDLLIBFILES = \
$(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so $(LIBPATH)libhycommon.a \
- $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
+ $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
DLLNAME=../liblcmm.so
Index: trunk/modules/awt/src/main/native/lcmm/windows/makefile
===================================================================
--- trunk/modules/awt/src/main/native/lcmm/windows/makefile (revision 501409)
+++ trunk/modules/awt/src/main/native/lcmm/windows/makefile (working copy)
@@ -36,7 +36,7 @@
MDLLIBFILES = \
$(LIBPATH)hysig.lib $(LIBPATH)hycommon.lib $(LIBPATH)hypool.lib \
- $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib $(LCMS_DIR)lcms114.lib
+ $(LIBPATH)vmi.lib $(LCMS_DIR)lcms114.lib
DLLBASE=0x13300000
COMMENT=/comment:"LCMM Wrapper native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/awt/src/main/native/linuxfont/unix/makefile
===================================================================
--- trunk/modules/awt/src/main/native/linuxfont/unix/makefile (revision 501409)
+++ trunk/modules/awt/src/main/native/linuxfont/unix/makefile (working copy)
@@ -26,7 +26,7 @@
MDLLIBFILES = \
$(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so $(LIBPATH)libhycommon.a \
- $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
+ $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
OSLIBS += $(XLIBS)
Index: trunk/modules/awt/src/main/native/oglwrapper/unix/makefile
===================================================================
--- trunk/modules/awt/src/main/native/oglwrapper/unix/makefile (revision 501409)
+++ trunk/modules/awt/src/main/native/oglwrapper/unix/makefile (working copy)
@@ -1,32 +1,32 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(HY_HDK)/build/make/defines.mk
-
-CFLAGS += -fpic
-INCLUDES += -I$(SHARED)common -I$(SHAREDSUB)/include
-
-BUILDFILES = \
- $(SHAREDSUB)/org_apache_harmony_awt_gl_opengl_GL.o
-
-MDLLIBFILES = \
- $(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so $(LIBPATH)libhycommon.a \
- $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
-
-OSLIBS += -lstdc++
-
-DLLNAME=../liboglwrapper.so
-
-include $(HY_HDK)/build/make/rules.mk
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+include $(HY_HDK)/build/make/defines.mk
+
+CFLAGS += -fpic
+INCLUDES += -I$(SHARED)common -I$(SHAREDSUB)/include
+
+BUILDFILES = \
+ $(SHAREDSUB)/org_apache_harmony_awt_gl_opengl_GL.o
+
+MDLLIBFILES = \
+ $(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so $(LIBPATH)libhycommon.a \
+ $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
+
+OSLIBS += -lstdc++
+
+DLLNAME=../liboglwrapper.so
+
+include $(HY_HDK)/build/make/rules.mk
Index: trunk/modules/awt/src/main/native/oglwrapper/windows/makefile
===================================================================
--- trunk/modules/awt/src/main/native/oglwrapper/windows/makefile (revision 501409)
+++ trunk/modules/awt/src/main/native/oglwrapper/windows/makefile (working copy)
@@ -29,7 +29,7 @@
MDLLIBFILES = \
$(LIBPATH)hysig.lib $(LIBPATH)hycommon.lib $(LIBPATH)hypool.lib \
- $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib
+ $(LIBPATH)vmi.lib
DLLBASE=0x13300000
COMMENT=/comment:"OpenGL Wrapper native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/awt/src/main/native/win32wrapper/windows/makefile
===================================================================
--- trunk/modules/awt/src/main/native/win32wrapper/windows/makefile (revision 501409)
+++ trunk/modules/awt/src/main/native/win32wrapper/windows/makefile (working copy)
@@ -33,7 +33,7 @@
MDLLIBFILES = \
$(LIBPATH)hysig.lib $(LIBPATH)hycommon.lib $(LIBPATH)hypool.lib \
- $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib
+ $(LIBPATH)vmi.lib
DLLBASE=0x13300000
COMMENT=/comment:"Win32 Wrapper native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/awt/src/main/native/winfont/windows/makefile
===================================================================
--- trunk/modules/awt/src/main/native/winfont/windows/makefile (revision 501409)
+++ trunk/modules/awt/src/main/native/winfont/windows/makefile (working copy)
@@ -32,7 +32,7 @@
MDLLIBFILES = \
$(LIBPATH)hysig.lib $(LIBPATH)hycommon.lib $(LIBPATH)hypool.lib \
- $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib
+ $(LIBPATH)vmi.lib
DLLBASE=0x13300000
COMMENT=/comment:"Win32 Font native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/awt/src/main/native/x11wrapper/unix/makefile
===================================================================
--- trunk/modules/awt/src/main/native/x11wrapper/unix/makefile (revision 501409)
+++ trunk/modules/awt/src/main/native/x11wrapper/unix/makefile (working copy)
@@ -26,7 +26,7 @@
MDLLIBFILES = \
$(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so $(LIBPATH)libhycommon.a \
- $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
+ $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
OSLIBS += -lstdc++ $(XLIBS)
Index: trunk/modules/imageio/src/main/native/jpegencoder/unix/makefile
===================================================================
--- trunk/modules/imageio/src/main/native/jpegencoder/unix/makefile (revision 501409)
+++ trunk/modules/imageio/src/main/native/jpegencoder/unix/makefile (working copy)
@@ -26,7 +26,7 @@
MDLLIBFILES = \
$(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so $(LIBPATH)libhycommon.a \
- $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
+ $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
DLLNAME=../libjpegencoder.so
Index: trunk/modules/imageio/src/main/native/jpegencoder/windows/makefile
===================================================================
--- trunk/modules/imageio/src/main/native/jpegencoder/windows/makefile (revision 501409)
+++ trunk/modules/imageio/src/main/native/jpegencoder/windows/makefile (working copy)
@@ -38,7 +38,7 @@
MDLLIBFILES = \
$(LIBPATH)hysig.lib $(LIBPATH)hycommon.lib $(LIBPATH)hypool.lib \
- $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib $(JPEG_DIR)libjpeg.lib
+ $(LIBPATH)vmi.lib $(JPEG_DIR)libjpeg.lib
DLLBASE=0x13300000
COMMENT=/comment:"JPEGENCODER native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/instrument/src/main/native/instrument/unix/makefile
===================================================================
--- trunk/modules/instrument/src/main/native/instrument/unix/makefile (revision 501409)
+++ trunk/modules/instrument/src/main/native/instrument/unix/makefile (working copy)
@@ -27,7 +27,7 @@
MDLLIBFILES = \
$(LIBPATH)libhycommon.a $(LIBPATH)libhyzip.a \
$(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a \
- $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
+ $(LIBPATH)libvmi.so
DLLNAME = ../libhyinstrument.so
Index: trunk/modules/instrument/src/main/native/instrument/windows/makefile
===================================================================
--- trunk/modules/instrument/src/main/native/instrument/windows/makefile (revision 501409)
+++ trunk/modules/instrument/src/main/native/instrument/windows/makefile (working copy)
@@ -34,7 +34,7 @@
MDLLIBFILES = \
$(LIBPATH)hycommon.lib $(LIBPATH)hysig.lib $(LIBPATH)hyzip.lib $(LIBPATH)hyzlib.lib \
- $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib
+ $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib $(LIBPATH)vmi.lib
DLLBASE=0x13200000
COMMENT=/comment:"instrument component native code. (c) Copyright 2006 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/luni/src/main/native/include/shared/vmi.h
===================================================================
--- trunk/modules/luni/src/main/native/include/shared/vmi.h (revision 501409)
+++ trunk/modules/luni/src/main/native/include/shared/vmi.h (working copy)
@@ -31,6 +31,7 @@
#include "jni.h"
#include "hyport.h"
#include "hyvmls.h"
+#include "hythread.h"
#include "zipsup.h"
/**
@@ -96,6 +97,7 @@
JavaVM *(JNICALL * GetJavaVM) (VMInterface * vmi);
HyPortLibrary *(JNICALL * GetPortLibrary) (VMInterface * vmi);
HyVMLSFunctionTable *(JNICALL * GetVMLSFunctions) (VMInterface * vmi);
+ HyThreadLibrary *(JNICALL * GetThreadLibrary) (VMInterface * vmi);
HyZipCachePool *(JNICALL * GetZipCachePool) (VMInterface * vmi);
JavaVMInitArgs *(JNICALL * GetInitArgs) (VMInterface * vmi);
@@ -188,6 +190,23 @@
HyVMLSFunctionTable *JNICALL GetVMLSFunctions (VMInterface * vmi);
/**
+ * @fn VMInterfaceFunctions_::GetThreadLibrary(VMInterface * vmi)
+ * Return a pointer to an initialized HyThreadLibrary structure.
+ * @code HyThreadLibrary* JNICALL GetThreadLibrary(VMInterface* vmi); @endcode
+ *
+ * The @ref hythread.h "thread library" is a table of functions that implement useful threading
+ * capability. For example, semaphones, thread creation, thread local storage, etc.
+ * It is the responsibility of the VM to create the thread library.
+ *
+ * @param[in] vmi The VM interface pointer
+ *
+ * @return the HyThreadLibrary associated with the VMI
+ *
+ * @see hythread.c
+ */
+ HyThreadLibrary *JNICALL GetThreadLibrary (VMInterface * vmi);
+
+/**
* @fn VMInterfaceFunctions_::GetZipCachePool(VMInterface * vmi)
* Return a pointer to the HyZipCachePool structure used by the VM. It is the
* responsibility of the vm to allocate the pool using zipCachePool_new().
Index: trunk/modules/luni/src/main/native/luni/unix/makefile
===================================================================
--- trunk/modules/luni/src/main/native/luni/unix/makefile (revision 501409)
+++ trunk/modules/luni/src/main/native/luni/unix/makefile (working copy)
@@ -38,7 +38,7 @@
MDLLIBFILES = \
$(LIBPATH)libhycommon.a $(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so \
- $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
+ $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
DLLNAME = ../libhyluni.so
Index: trunk/modules/luni/src/main/native/luni/windows/makefile
===================================================================
--- trunk/modules/luni/src/main/native/luni/windows/makefile (revision 501409)
+++ trunk/modules/luni/src/main/native/luni/windows/makefile (working copy)
@@ -45,7 +45,7 @@
MDLLIBFILES = \
$(LIBPATH)hycommon.lib $(LIBPATH)hysig.lib $(LIBPATH)hyzip.lib $(LIBPATH)hyzlib.lib \
- $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib
+ $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib $(LIBPATH)vmi.lib
DLLBASE=0x13200000
COMMENT=/comment:"LUNI component native code. (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/luni/src/main/native/vmls/shared/vmls.c
===================================================================
--- trunk/modules/luni/src/main/native/vmls/shared/vmls.c (revision 501409)
+++ trunk/modules/luni/src/main/native/vmls/shared/vmls.c (working copy)
@@ -77,6 +77,7 @@
*/
void JNICALL HyVMLSFreeKeys(JNIEnv * env, UDATA * pInitCount, ...)
{
+ THREAD_ACCESS_FROM_ENV(env);
va_list args;
HyVMLSTable* vmls = GLOBAL_DATA(VMLSTable);
@@ -122,6 +123,7 @@
*/
UDATA JNICALL HyVMLSAllocKeys(JNIEnv * env, UDATA * pInitCount, ...)
{
+ THREAD_ACCESS_FROM_ENV(env);
va_list args;
HyVMLSTable *vmls = GLOBAL_DATA(VMLSTable);
@@ -259,6 +261,7 @@
*/
void initializeVMLocalStorage(JavaVM * vm)
{
+ THREAD_ACCESS_FROM_JAVAVM(vm);
HyVMLSTable* vmls = GLOBAL_DATA(VMLSTable);
VMLSContainer* container = NULL;
@@ -318,6 +321,7 @@
VMLSContainer* previous = NULL;
/* Reach for the VM interface */
+ THREAD_ACCESS_FROM_JAVAVM(vm);
PORT_ACCESS_FROM_JAVAVM(vm);
/* Obtain the global lock */
Index: trunk/modules/misc/src/main/native/accessors/unix/makefile
===================================================================
--- trunk/modules/misc/src/main/native/accessors/unix/makefile (revision 501409)
+++ trunk/modules/misc/src/main/native/accessors/unix/makefile (working copy)
@@ -28,7 +28,7 @@
MDLLIBFILES = \
$(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so $(LIBPATH)libhycommon.a \
- $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
+ $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
DLLNAME=../libaccessors.so
Index: trunk/modules/misc/src/main/native/accessors/windows/makefile
===================================================================
--- trunk/modules/misc/src/main/native/accessors/windows/makefile (revision 501409)
+++ trunk/modules/misc/src/main/native/accessors/windows/makefile (working copy)
@@ -31,7 +31,7 @@
MDLLIBFILES = \
$(LIBPATH)hysig.lib $(LIBPATH)hycommon.lib $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib \
- $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib
+ $(LIBPATH)vmi.lib
DLLBASE=0x13300000
COMMENT=/comment:"Accessors native code. (c) Copyright 2006 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/nio/src/main/native/nio/windows/makefile
===================================================================
--- trunk/modules/nio/src/main/native/nio/windows/makefile (revision 501409)
+++ trunk/modules/nio/src/main/native/nio/windows/makefile (working copy)
@@ -33,7 +33,7 @@
MDLLIBFILES = \
$(LIBPATH)hycommon.lib $(LIBPATH)hysig.lib $(LIBPATH)hyzip.lib $(LIBPATH)hyzlib.lib \
- $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib
+ $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib $(LIBPATH)vmi.lib
DLLBASE=0x13200000
COMMENT=/comment:"nio component native code. (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/portlib/build.xml
===================================================================
--- trunk/modules/portlib/build.xml (revision 501409)
+++ trunk/modules/portlib/build.xml (working copy)
@@ -90,12 +90,6 @@
-
-
-
-
-
-
Index: trunk/modules/portlib/src/main/native/include/shared/hyport.h
===================================================================
--- trunk/modules/portlib/src/main/native/include/shared/hyport.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/include/shared/hyport.h (working copy)
@@ -998,6 +998,8 @@
/** see @ref hysysinfo.c::hysysinfo_get_processing_capacity "hysysinfo_get_processing_capacity"*/
UDATA (PVMCALL sysinfo_get_processing_capacity) (struct HyPortLibrary *
portLibrary);
+ /** see @ref hyport.c::hyport_get_thread_library "hyport_get_thread_library"*/
+ HyThreadLibrary * (PVMCALL port_get_thread_library) (struct HyPortLibrary * portLibrary);
char _hypadding039C[4]; /* 4 bytes of automatic padding */
} HyPortLibrary;
#define HYPORT_SL_FOUND 0
@@ -1026,7 +1028,7 @@
#define HYPORT_CTLDATA_TRACE_STOP "TRACE_STOP"
#define HYPORT_CTLDATA_SHMEM_GROUP_PERM "SHMEM_GROUP_PERM"
#define HYPORT_MAJOR_VERSION_NUMBER 4
-#define HYPORT_MINOR_VERSION_NUMBER 0
+#define HYPORT_MINOR_VERSION_NUMBER 1
#define HYPORT_CAPABILITY_BASE 0
#define HYPORT_CAPABILITY_STANDARD 1
#define HYPORT_CAPABILITY_FILESYSTEM 2
@@ -1132,14 +1134,12 @@
*portLibrary,
struct HyPortLibraryVersion
*version, UDATA size);
-extern HY_CFUNC I_32 VMCALL hyport_init_library (struct HyPortLibrary
- *portLibrary,
- struct HyPortLibraryVersion
- *version, UDATA size);
+extern HY_CFUNC I_32 VMCALL hyport_init_library (struct HyPortLibrary *portLibrary,
+ struct HyPortLibraryVersion *version,
+ UDATA size);
extern HY_CFUNC I_32 VMCALL hyport_shutdown_library (struct HyPortLibrary
*portLibrary);
-extern HY_CFUNC I_32 VMCALL hyport_startup_library (struct HyPortLibrary
- *portLibrary);
+extern HY_CFUNC I_32 VMCALL hyport_startup_library (struct HyPortLibrary *portLibrary);
/** Port library self allocation routines */
extern HY_CFUNC I_32 VMCALL hyport_allocate_library (struct
HyPortLibraryVersion
@@ -1180,6 +1180,7 @@
* @{
*/
#if !defined(HYPORT_LIBRARY_DEFINE)
+#define hyport_get_thread_library() privatePortLibrary->port_get_thread_library(privatePortLibrary)
#define hyport_shutdown_library() privatePortLibrary->port_shutdown_library(privatePortLibrary)
#define hyport_isFunctionOverridden(param1) privatePortLibrary->port_isFunctionOverridden(privatePortLibrary,param1)
#define hyport_tls_free() privatePortLibrary->port_tls_free(privatePortLibrary)
Index: trunk/modules/portlib/src/main/native/include/shared/hythread.h
===================================================================
--- trunk/modules/portlib/src/main/native/include/shared/hythread.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/include/shared/hythread.h (working copy)
@@ -24,73 +24,46 @@
#endif
#include
#include "hycomp.h"
- typedef UDATA hythread_tls_key_t;
+
+#define THREAD_ACCESS_FROM_ENV(jniEnv) \
+VMInterface *threadPrivateVMI = VMI_GetVMIFromJNIEnv(jniEnv); \
+HyThreadLibrary *privateThreadLibrary = (*threadPrivateVMI)->GetThreadLibrary(threadPrivateVMI)
+#define THREAD_ACCESS_FROM_JAVAVM(javaVM) \
+VMInterface *threadPrivateVMI = VMI_GetVMIFromJavaVM(javaVM); \
+HyThreadLibrary *privateThreadLibrary = (*threadPrivateVMI)->GetThreadLibrary(threadPrivateVMI)
+#define THREAD_ACCESS_FROM_VMI(vmi) HyThreadLibrary *privateThreadLibrary = (*vmi)->GetThreadLibrary(vmi)
+#define THREAD_ACCESS_FROM_PORT(portLib) HyThreadLibrary *privateThreadLibrary = portLib->port_get_thread_library(portLib)
+#define THREAD_ACCESS_FROM_THREAD(threadLibrary) HyThreadLibrary *privateThreadLibrary = threadLibrary
+
+#define THREADLIB privateThreadLibrary
+
+typedef UDATA hythread_tls_key_t;
+
#define HYTHREAD_PROC VMCALL
- typedef int (HYTHREAD_PROC * hythread_entrypoint_t) (void *);
- typedef void (HYTHREAD_PROC * hythread_tls_finalizer_t) (void *);
- typedef struct HyThread *hythread_t;
- typedef struct HyThreadMonitor *hythread_monitor_t;
- typedef struct HySemaphore *hysem_t;
- struct HyPortLibrary;
-#define HYTHREAD_PRIORITY_MIN 0
-#define HYTHREAD_PRIORITY_USER_MIN 1
-#define HYTHREAD_PRIORITY_NORMAL 5
-#define HYTHREAD_PRIORITY_USER_MAX 10
-#define HYTHREAD_PRIORITY_MAX 11
+#define HYTHREAD_MAJOR_VERSION_NUMBER 1
+#define HYTHREAD_MINOR_VERSION_NUMBER 0
+#define HYTHREAD_CAPABILITY_BASE 0
+#define HYTHREAD_CAPABILITY_STANDARD 1
+#define HYTHREAD_CAPABILITY_MASK ((U_64)(HYTHREAD_CAPABILITY_STANDARD))
+#define HYTHREAD_SET_VERSION(threadLibraryVersion, capabilityMask) \
+ (threadLibraryVersion)->majorVersionNumber = HYTHREAD_MAJOR_VERSION_NUMBER; \
+ (threadLibraryVersion)->minorVersionNumber = HYTHREAD_MINOR_VERSION_NUMBER; \
+ (threadLibraryVersion)->capabilities = (capabilityMask)
+#define HYTHREAD_SET_VERSION_DEFAULT(threadLibraryVersion) \
+ (threadLibraryVersion)->majorVersionNumber = HYTHREAD_MAJOR_VERSION_NUMBER; \
+ (threadLibraryVersion)->minorVersionNumber = HYTHREAD_MINOR_VERSION_NUMBER; \
+ (threadLibraryVersion)->capabilities = HYTHREAD_CAPABILITY_MASK
-#define HYTHREAD_LOCKING_DEFAULT 0 /* default locking policy for platform */
-#define HYTHREAD_LOCKING_NO_DATA (-1) /* if no policy data is provided */
-#define HYTHREAD_FLAG_BLOCKED 1
-#define HYTHREAD_ALREADY_INITIALIZED 4
-#define HYTHREAD_TIMED_OUT 3
-#define HYTHREAD_FLAG_STARTED 0x800
-#define HYTHREAD_FLAG_JLM_HAS_BEEN_ENABLED 0x20000
-#define HYTHREAD_ILLEGAL_MONITOR_STATE 1
-#define HYTHREAD_FLAG_PRIORITY_INTERRUPTED 0x100
-#define HYTHREAD_FLAG_JLMHST_ENABLED 0x10000
-#define HYTHREAD_FLAG_JLM_ENABLED 0x4000
-#define HYTHREAD_FLAG_INTERRUPTED 4
-#define HYTHREAD_INVALID_ARGUMENT 7
-#define HYTHREAD_FLAG_DETACHED 0x80
-#define HYTHREAD_PRIORITY_INTERRUPTED 5
-#define HYTHREAD_FLAG_CANCELED 0x400
-#define HYTHREAD_FLAG_NOTIFIED 16
-#define HYTHREAD_FLAG_ATTACHED 0x200
-#define HYTHREAD_WOULD_BLOCK 8
-#define HYTHREAD_FLAG_DEAD 32
-#define HYTHREAD_FLAG_WAITING 2
-#define HYTHREAD_FLAG_PARKED 0x40000
-#define HYTHREAD_FLAG_UNPARKED 0x80000
-#define HYTHREAD_FLAG_INTERRUPTABLE 0x2000
-#define HYTHREAD_FLAG_TIMER_SET 0x100000
-#define HYTHREAD_FLAG_JLM_ENABLED_ALL 0x1C000
-#define HYTHREAD_FLAG_JLMTS_ENABLED 0x8000
-#define HYTHREAD_INTERRUPTED 2
-#define HYTHREAD_FLAG_BLOCKED_AFTER_WAIT 0x1000
-#define HYTHREAD_ALREADY_ATTACHED 6
-#define HYTHREAD_FLAG_SUSPENDED 8
-#define HYTHREAD_FLAG_SLEEPING 64
-#define HYTHREAD_MONITOR_INFLATED 0x10000
-#define HYTHREAD_MONITOR_INTERRUPTABLE 0x20000
-#define HYTHREAD_MONITOR_PRIORITY_INTERRUPTABLE 0x40000
-#define HYTHREAD_MONITOR_SYSTEM 0
-#define HYTHREAD_MONITOR_OBJECT 0x60000
-#define HYTHREAD_MONITOR_MUTEX_UNINITIALIZED 0x80000
-#define HYTHREAD_MONITOR_SUPPRESS_CONTENDED_EXIT 0x100000
-#define HYTHREAD_MONITOR_MUTEX_IN_USE 0x200000
-#define HYTHREAD_MONITOR_SPINLOCK_UNOWNED 0
-#define HYTHREAD_MONITOR_SPINLOCK_OWNED 1
-#define HYTHREAD_MONITOR_SPINLOCK_EXCEEDED 2
-#define HYTHREAD_LIB_FLAG_JLMHST_ENABLED 0x10000
-#define HYTHREAD_LIB_FLAG_JLM_ENABLED 0x4000
-#define HYTHREAD_LIB_FLAG_JLM_ENABLED_ALL 0x1C000
-#define HYTHREAD_LIB_FLAG_JLM_HAS_BEEN_ENABLED 0x20000
-#define HYTHREAD_LIB_FLAG_JLMTS_ENABLED 0x8000
- typedef struct HyThreadMonitorTracing
- {
- char *monitor_name;
+typedef int (HYTHREAD_PROC * hythread_entrypoint_t) (void *);
+typedef struct HyThread *hythread_t;
+typedef struct HyThreadMonitor *hythread_monitor_t;
+typedef struct HySemaphore *hysem_t;
+
+typedef struct HyThreadMonitorTracing
+{
+ char *monitor_name;
UDATA enter_count;
UDATA slow_count;
UDATA recursive_count;
@@ -96,192 +69,143 @@
UDATA recursive_count;
UDATA spin2_count;
UDATA yield_count;
- } HyThreadMonitorTracing;
+} HyThreadMonitorTracing;
- extern HY_CFUNC void VMCALL hythread_detach PROTOTYPE ((hythread_t thread));
- extern HY_CFUNC UDATA VMCALL
- hythread_lib_set_flags PROTOTYPE ((UDATA flags));
- extern HY_CFUNC IDATA VMCALL
- hythread_tls_alloc PROTOTYPE ((hythread_tls_key_t * handle));
- extern HY_CFUNC IDATA VMCALL
- hythread_sleep_interruptable PROTOTYPE ((I_64 millis, IDATA nanos));
- extern HY_CFUNC IDATA VMCALL
- hythread_monitor_enter_using_threadId
- PROTOTYPE ((hythread_monitor_t monitor, hythread_t threadId));
- extern HY_CFUNC void VMCALL hythread_cancel PROTOTYPE ((hythread_t thread));
- extern HY_CFUNC UDATA VMCALL hythread_clear_interrupted PROTOTYPE ((void));
- extern HY_CFUNC void VMCALL
- hythread_lib_unlock PROTOTYPE ((hythread_t self));
- extern HY_CFUNC IDATA VMCALL
- hythread_monitor_enter PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC IDATA VMCALL
- hythread_monitor_notify_all PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC IDATA VMCALL
- hythread_attach PROTOTYPE ((hythread_t * handle));
- extern HY_CFUNC HyThreadMonitorTracing *VMCALL
- hythread_jlm_get_gc_lock_tracing PROTOTYPE (());
- extern HY_CFUNC UDATA VMCALL
- hythread_priority_interrupted PROTOTYPE ((hythread_t thread));
- extern HY_CFUNC IDATA VMCALL
- hythread_monitor_destroy PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC IDATA VMCALL hysem_post PROTOTYPE ((hysem_t s));
- extern HY_CFUNC UDATA VMCALL
- hythread_monitor_num_waiting PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC UDATA VMCALL
- hythread_interrupted PROTOTYPE ((hythread_t thread));
+typedef struct HyThreadLibraryVersion
+{
+ U_16 majorVersionNumber;
+ U_16 minorVersionNumber;
+ U_32 padding;
+ U_64 capabilities;
+} HyThreadLibraryVersion;
- extern HY_CFUNC void VMCALL
- hythread_monitor_lock
- PROTOTYPE ((hythread_t self, hythread_monitor_t monitor));
- extern HY_CFUNC IDATA VMCALL hythread_park
- PROTOTYPE ((I_64 millis, IDATA nanos));
- extern HY_CFUNC IDATA VMCALL hythread_monitor_init_with_name
- PROTOTYPE ((hythread_monitor_t * handle, UDATA flags, char *name));
- extern HY_CFUNC IDATA VMCALL hythread_monitor_try_enter
- PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC void VMCALL hythread_jlm_thread_clear
- PROTOTYPE ((hythread_t thread));
- extern HY_CFUNC hythread_t VMCALL hythread_self PROTOTYPE ((void));
- extern HY_CFUNC IDATA VMCALL
- hythread_tls_free PROTOTYPE ((hythread_tls_key_t key));
- extern HY_CFUNC UDATA VMCALL
- hythread_clear_priority_interrupted PROTOTYPE ((void));
- extern HY_CFUNC void VMCALL
- hythread_jlm_thread_init PROTOTYPE ((hythread_t thread));
+typedef struct HyThreadLibrary {
+ /** threadVersion */
+ struct HyThreadLibraryVersion threadVersion;
- extern HY_CFUNC void VMCALL hythread_jlm_gc_lock_init PROTOTYPE (());
- extern HY_CFUNC void VMCALL
- hythread_monitor_unlock
- PROTOTYPE ((hythread_t self, hythread_monitor_t monitor));
- extern HY_CFUNC IDATA VMCALL hysem_wait PROTOTYPE ((hysem_t s));
- extern HY_CFUNC void VMCALL hythread_yield PROTOTYPE ((void));
- extern HY_CFUNC void VMCALL hythread_suspend PROTOTYPE ((void));
- extern HY_CFUNC void VMCALL
- hythread_interrupt PROTOTYPE ((hythread_t thread));
- extern HY_CFUNC IDATA VMCALL
- hythread_tls_set
- PROTOTYPE ((hythread_t thread, hythread_tls_key_t key, void *value));
- extern HY_CFUNC IDATA VMCALL hythread_create
- PROTOTYPE ((hythread_t * handle, UDATA stacksize, UDATA priority,
+ IDATA (PVMCALL sem_destroy) (struct HyThreadLibrary * threadLibrary, hysem_t s);
+ IDATA (PVMCALL sem_init) (struct HyThreadLibrary * threadLibrary, hysem_t * sp, I_32 initValue);
+ IDATA (PVMCALL sem_post) (struct HyThreadLibrary * threadLibrary, hysem_t s);
+ IDATA (PVMCALL sem_wait) (struct HyThreadLibrary * threadLibrary, hysem_t s);
+
+ IDATA (PVMCALL thread_attach) (struct HyThreadLibrary * threadLibrary, hythread_t * handle);
+ IDATA (PVMCALL thread_create) (struct HyThreadLibrary * threadLibrary, hythread_t * handle, UDATA stacksize, UDATA priority,
UDATA suspend, hythread_entrypoint_t entrypoint,
- void *entryarg));
- extern HY_CFUNC IDATA VMCALL hysem_init
- PROTOTYPE ((hysem_t * sp, I_32 initValue));
- extern HY_CFUNC IDATA VMCALL hythread_monitor_wait
- PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC IDATA VMCALL hythread_monitor_init_policy
- PROTOTYPE ((hythread_monitor_t * handle, UDATA flags, IDATA policy,
- IDATA policyData));
- extern HY_CFUNC void VMCALL hythread_jlm_monitor_init
- PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC IDATA VMCALL hysem_destroy PROTOTYPE ((hysem_t s));
- extern HY_CFUNC IDATA VMCALL
- hythread_monitor_wait_interruptable
- PROTOTYPE ((hythread_monitor_t monitor, I_64 millis, IDATA nanos));
- extern HY_CFUNC IDATA VMCALL hythread_monitor_try_enter_using_threadId
- PROTOTYPE ((hythread_monitor_t monitor, hythread_t threadId));
- extern HY_CFUNC IDATA VMCALL hythread_monitor_exit
- PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC IDATA VMCALL hythread_set_priority
- PROTOTYPE ((hythread_t thread, UDATA priority));
- extern HY_CFUNC void VMCALL hythread_unpark PROTOTYPE ((hythread_t thread));
- extern HY_CFUNC void VMCALL hythread_lib_lock PROTOTYPE ((hythread_t self));
- extern HY_CFUNC IDATA VMCALL
- hythread_monitor_init
- PROTOTYPE ((hythread_monitor_t * handle, UDATA flags));
- extern HY_CFUNC IDATA VMCALL hythread_sleep PROTOTYPE ((I_64 millis));
- extern HY_CFUNC UDATA *VMCALL hythread_global PROTOTYPE ((char *name));
- extern HY_CFUNC IDATA VMCALL
- hythread_tls_alloc_with_finalizer
- PROTOTYPE ((hythread_tls_key_t * handle,
- hythread_tls_finalizer_t finalizer));
- extern HY_CFUNC void VMCALL hythread_jlm_monitor_clear
- PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC IDATA VMCALL hythread_monitor_wait_timed
- PROTOTYPE ((hythread_monitor_t monitor, I_64 millis, IDATA nanos));
- extern HY_CFUNC void VMCALL hythread_resume PROTOTYPE ((hythread_t thread));
- extern HY_CFUNC UDATA VMCALL
- hythread_lib_clear_flags PROTOTYPE ((UDATA flags));
- extern HY_CFUNC void VMCALL
- hythread_priority_interrupt PROTOTYPE ((hythread_t thread));
- extern HY_CFUNC void VMCALL NORETURN
- hythread_exit PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC IDATA VMCALL
- hythread_monitor_exit_using_threadId
- PROTOTYPE ((hythread_monitor_t monitor, hythread_t threadId));
+ void *entryarg);
+ void (PVMCALL thread_detach) (struct HyThreadLibrary * threadLibrary, hythread_t thread);
+ void (PVMCALL NORETURN thread_exit) (struct HyThreadLibrary * threadLibrary, hythread_monitor_t monitor);
+
+ UDATA *(PVMCALL thread_global) (struct HyThreadLibrary * threadLibrary, char *name);
+
+ IDATA (PVMCALL thread_monitor_destroy) (struct HyThreadLibrary * threadLibrary, hythread_monitor_t monitor);
+ IDATA (PVMCALL thread_monitor_enter) (struct HyThreadLibrary * threadLibrary, hythread_monitor_t monitor);
+ IDATA (PVMCALL thread_monitor_exit) (struct HyThreadLibrary * threadLibrary, hythread_monitor_t monitor);
+ IDATA (PVMCALL thread_monitor_init_with_name) (struct HyThreadLibrary * threadLibrary, hythread_monitor_t * handle, UDATA flags, char *name);
+ IDATA (PVMCALL thread_monitor_notify) (struct HyThreadLibrary * threadLibrary, hythread_monitor_t monitor);
+ IDATA (PVMCALL thread_monitor_notify_all) (struct HyThreadLibrary * threadLibrary, hythread_monitor_t monitor);
+ IDATA (PVMCALL thread_monitor_wait) (struct HyThreadLibrary * threadLibrary, hythread_monitor_t monitor);
+
+ hythread_t (PVMCALL thread_self) (struct HyThreadLibrary * threadLibrary);
+ IDATA (PVMCALL thread_sleep) (struct HyThreadLibrary * threadLibrary, I_64 millis);
+
+ IDATA (PVMCALL thread_tls_alloc) (struct HyThreadLibrary * threadLibrary, hythread_tls_key_t * handle);
+ IDATA (PVMCALL thread_tls_free) (struct HyThreadLibrary * threadLibrary, hythread_tls_key_t key);
+ void *(PVMCALL thread_tls_get) (struct HyThreadLibrary * threadLibrary, hythread_t thread, hythread_tls_key_t key);
+ IDATA (PVMCALL thread_tls_set) (struct HyThreadLibrary * threadLibrary, hythread_t thread, hythread_tls_key_t key, void *value);
+ /** self_handle*/
+ void *self_handle;
+} HyThreadLibrary;
+
+
+/**
+ * @name Thread library startup and shutdown functions
+ * @anchor ThreadStartup
+ * Create, initialize, startup and shutdow the thread library
+ * @{
+ */
+/** Standard startup and shutdown (thread library allocated on stack or by application) */
+extern HY_CFUNC I_32 VMCALL hythread_create_library (struct HyThreadLibrary
+ *threadLibrary,
+ struct HyThreadLibraryVersion
+ *version, UDATA size);
+extern HY_CFUNC I_32 VMCALL hythread_init_library (struct HyThreadLibrary
+ *threadLibrary,
+ struct HyThreadLibraryVersion
+ *version, UDATA size);
+extern HY_CFUNC I_32 VMCALL hythread_shutdown_library (struct HyThreadLibrary
+ *threadLibrary);
+extern HY_CFUNC I_32 VMCALL hythread_startup_library (struct HyThreadLibrary
+ *threadLibrary);
+/** Thread library self allocation routines */
+extern HY_CFUNC I_32 VMCALL hythread_allocate_library (struct HyThreadLibraryVersion
+ *expectedVersion,
+ struct HyThreadLibrary
+ **threadLibrary);
- extern HY_CFUNC UDATA VMCALL hythread_lib_get_flags PROTOTYPE (());
- extern HY_CFUNC IDATA VMCALL
- hythread_monitor_notify PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC void VMCALL
- hythread_enable_stack_usage PROTOTYPE ((UDATA enable));
+/** @} */
+/**
+ * @name Thread library version and compatability queries
+ * @anchor ThreadVersionControl
+ * Determine thread library compatability and version.
+ * @{
+ */
+extern HY_CFUNC UDATA VMCALL hythread_getSize (struct HyThreadLibraryVersion
+ *version);
+extern HY_CFUNC I_32 VMCALL hythread_getVersion (struct HyThreadLibrary
+ *threadLibrary,
+ struct HyThreadLibraryVersion
+ *version);
+extern HY_CFUNC I_32 VMCALL hythread_isCompatible (struct HyThreadLibraryVersion
+ *expectedVersion);
- extern HY_CFUNC UDATA VMCALL
- hythread_get_handle PROTOTYPE ((hythread_t thread));
+/** @} */
+/**
+ * @name ThreadLibrary Access functions
+ * Convenience helpers for accessing thread library functionality. Users can
+ * either call functions directly via the table or by help macros.
+ * @code
+ * if (0 != threadLibrary->thread_monitor_init_with_name (threadLibrary, &nls->monitor, 0, "NLS hash table"))...
+ * @endcode
+ * @code
+ * THREAD_ACCESS_FROM_ENV(jniEnv);
+ * if (0 != hythread_monitor_init_with_name (&nls->monitor, 0, "NLS hash table")) ...
+ * @endcode
+ * @{
+ */
- extern HY_CFUNC UDATA VMCALL
- hythread_get_stack_usage PROTOTYPE ((hythread_t thread));
+#if !defined(HYTHREAD_LIBRARY_DEFINE)
+#define hythread_global_monitor() (*(hythread_monitor_t*)privateThreadLibrary->thread_global(privateThreadLibrary,"global_monitor"))
+#define hythread_monitor_init(pMon,flags) privateThreadLibrary->thread_monitor_init_with_name(privateThreadLibrary,pMon,flags, #pMon)
- extern HY_CFUNC I_64 VMCALL
- hythread_get_cpu_time PROTOTYPE ((hythread_t thread));
+#define hysem_destroy(param1) privateThreadLibrary->sem_destroy(privateThreadLibrary,param1)
+#define hysem_init(param1,param2) privateThreadLibrary->sem_init(privateThreadLibrary,param1,param2)
+#define hysem_post(param1) privateThreadLibrary->sem_post(privateThreadLibrary,param1)
+#define hysem_wait(param1) privateThreadLibrary->sem_wait(privateThreadLibrary,param1)
- extern HY_CFUNC UDATA VMCALL
- hythread_get_stack_size PROTOTYPE ((hythread_t thread));
- extern HY_CFUNC I_64 VMCALL
- hythread_get_user_time PROTOTYPE ((hythread_t thread));
- extern HY_CFUNC IDATA VMCALL hythread_get_os_priority
- PROTOTYPE ((hythread_t thread, IDATA * policy, IDATA * priority));
- extern HY_CFUNC UDATA VMCALL hythread_get_flags
- PROTOTYPE ((hythread_t thread, hythread_monitor_t * blocker));
- extern HY_CFUNC HyThreadMonitorTracing *VMCALL hythread_monitor_get_tracing
- PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC UDATA VMCALL hythread_get_priority
- PROTOTYPE ((hythread_t thread));
- extern HY_CFUNC void *VMCALL hythread_tls_get
- PROTOTYPE ((hythread_t thread, hythread_tls_key_t key));
- extern HY_CFUNC char *VMCALL hythread_monitor_get_name
- PROTOTYPE ((hythread_monitor_t monitor));
- extern HY_CFUNC hythread_monitor_t VMCALL hythread_monitor_walk
- PROTOTYPE ((hythread_monitor_t monitor));
- struct RWMutex;
- typedef struct RWMutex *hythread_rwmutex_t;
- extern HY_CFUNC IDATA VMCALL
- hythread_rwmutex_enter_read PROTOTYPE ((hythread_rwmutex_t mutex));
- extern HY_CFUNC IDATA VMCALL
- hythread_rwmutex_destroy PROTOTYPE ((hythread_rwmutex_t mutex));
- extern HY_CFUNC IDATA VMCALL
- hythread_rwmutex_exit_read PROTOTYPE ((hythread_rwmutex_t mutex));
- extern HY_CFUNC IDATA VMCALL
- hythread_rwmutex_exit_write PROTOTYPE ((hythread_rwmutex_t mutex));
- extern HY_CFUNC IDATA VMCALL
- hythread_rwmutex_init
- PROTOTYPE ((hythread_rwmutex_t * handle, UDATA flags, const char *name));
- extern HY_CFUNC IDATA VMCALL hythread_rwmutex_enter_write
- PROTOTYPE ((hythread_rwmutex_t mutex));
-/* HyVMThreadHelpers*/
-#if !defined(_HYVMTHREADHELPERS_)
-#define _HYVMTHREADHELPERS_
- extern HY_CFUNC UDATA VMCALL current_stack_depth ();
- extern HY_CFUNC void VMCALL hythread_monitor_unpin (hythread_monitor_t
- monitor,
- hythread_t osThread);
- extern HY_CFUNC void VMCALL hythread_monitor_pin (hythread_monitor_t
- monitor,
- hythread_t osThread);
-#endif /* _HYVMTHREADHELPERS_ */
-/* HyVMThreadSpinlocks*/
-#if !defined(_HYVMTHREADSPINLOCKS_)
-#define _HYVMTHREADSPINLOCKS_
- extern HY_CFUNC IDATA VMCALL hythread_spinlock_acquire (hythread_t self,
- hythread_monitor_t
- monitor);
- extern HY_CFUNC UDATA VMCALL hythread_spinlock_swapState (hythread_monitor_t
- monitor,
- UDATA newState);
-#endif /* _HYVMTHREADSPINLOCKS_ */
-#define hythread_global_monitor() (*(hythread_monitor_t*)hythread_global("global_monitor"))
-#define hythread_monitor_init(pMon,flags) hythread_monitor_init_with_name(pMon,flags, #pMon)
-#define hythread_monitor_set_name(pMon,pName)
+#define hythread_attach(param1) privateThreadLibrary->thread_attach(privateThreadLibrary,param1)
+#define hythread_create(param1,param2,param3,param4,param5,param6) privateThreadLibrary->thread_create(privateThreadLibrary,param1,param2,param3,param4,param5,param6)
+#define hythread_detach(param1) privateThreadLibrary->thread_detach(privateThreadLibrary,param1)
+#define hythread_exit(param1) privateThreadLibrary->thread_exit(privateThreadLibrary,param1)
+
+#define hythread_global(param1) privateThreadLibrary->thread_global(privateThreadLibrary,param1)
+
+#define hythread_monitor_destroy(param1) privateThreadLibrary->thread_monitor_destroy(privateThreadLibrary,param1)
+#define hythread_monitor_enter(param1) privateThreadLibrary->thread_monitor_enter(privateThreadLibrary,param1)
+#define hythread_monitor_exit(param1) privateThreadLibrary->thread_monitor_exit(privateThreadLibrary,param1)
+#define hythread_monitor_init_with_name(param1,param2,param3) privateThreadLibrary->thread_monitor_init_with_name(privateThreadLibrary,param1,param2,param3)
+#define hythread_monitor_notify(param1) privateThreadLibrary->thread_monitor_notify(privateThreadLibrary,param1)
+#define hythread_monitor_notify_all(param1) privateThreadLibrary->thread_monitor_notify_all(privateThreadLibrary,param1)
+#define hythread_monitor_wait(param1) privateThreadLibrary->thread_monitor_wait(privateThreadLibrary,param1)
+
+#define hythread_self() privateThreadLibrary->thread_self(privateThreadLibrary)
+#define hythread_sleep(param1) privateThreadLibrary->thread_sleep(privateThreadLibrary,param1)
+
+#define hythread_tls_alloc(param1) privateThreadLibrary->thread_tls_alloc(privateThreadLibrary,param1)
+#define hythread_tls_free(param1) privateThreadLibrary->thread_tls_free(privateThreadLibrary,param1)
+#define hythread_tls_get(param1,param2) privateThreadLibrary->thread_tls_get(privateThreadLibrary,param1,param2)
+#define hythread_tls_set(param1,param2,param3) privateThreadLibrary->thread_tls_set(privateThreadLibrary,param1,param2,param3)
+
+#endif /* !HYTHREAD_LIBRARY_DEFINE */
#if defined(__cplusplus)
}
#endif
Index: trunk/modules/portlib/src/main/native/port/shared/hynls.c
===================================================================
--- trunk/modules/portlib/src/main/native/port/shared/hynls.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/port/shared/hynls.c (working copy)
@@ -83,7 +83,7 @@
hynls_set_locale (struct HyPortLibrary *portLibrary, const char *lang,
const char *region, const char *variant)
{
-
+ THREAD_ACCESS_FROM_PORT(portLibrary);
HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data;
#if defined(NLS_DEBUG_TRACE)
portLibrary->tty_printf (portLibrary, "NLS - hynls_set_locale\n");
@@ -265,6 +265,7 @@
U_32 module_name, U_32 message_num,
const char *default_string)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data;
const char *message;
#if defined(NLS_DEBUG_TRACE)
@@ -313,6 +314,7 @@
const int nPaths, const char *baseName,
const char *extension)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
int i;
char *p;
@@ -1058,6 +1060,7 @@
I_32 VMCALL
hynls_startup (struct HyPortLibrary *portLibrary)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data;
if (0 !=
@@ -1085,6 +1088,7 @@
void VMCALL
hynls_shutdown (struct HyPortLibrary *portLibrary)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
HyNLSDataCache *nls = &portLibrary->portGlobals->nls_data;
HyNLSHashEntry *entry;
U_32 i;
Index: trunk/modules/portlib/src/main/native/port/shared/hyport.c
===================================================================
--- trunk/modules/portlib/src/main/native/port/shared/hyport.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/port/shared/hyport.c (working copy)
@@ -73,6 +73,8 @@
I_32 VMCALL
hyport_shutdown_library (struct HyPortLibrary * portLibrary)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
+
portLibrary->sig_shutdown (portLibrary);
portLibrary->shmem_shutdown (portLibrary);
portLibrary->shsem_shutdown (portLibrary);
@@ -155,7 +157,7 @@
portLibrary->portVersion.majorVersionNumber = version->majorVersionNumber;
portLibrary->portVersion.minorVersionNumber = version->minorVersionNumber;
portLibrary->portVersion.capabilities = HYPORT_CAPABILITY_MASK;
-
+
return 0;
}
@@ -200,9 +202,25 @@
hyport_startup_library (struct HyPortLibrary * portLibrary)
{
I_32 rc = 0;
+ HyThreadLibrary *hyThreadLibrary;
+ HyThreadLibraryVersion hyThreadLibraryVersion;
+
+ HYTHREAD_SET_VERSION(&hyThreadLibraryVersion, HYTHREAD_CAPABILITY_MASK);
+ rc = hythread_allocate_library(&hyThreadLibraryVersion, &hyThreadLibrary);
+ if ( 0 != rc ) {
+ rc = HYPORT_ERROR_STARTUP_THREAD;
+ goto cleanup;
+ }
+
+ rc = hythread_startup_library(hyThreadLibrary);
+ if ( 0 != rc )
+ {
+ rc = HYPORT_ERROR_STARTUP_THREAD;
+ goto cleanup;
+ }
/* NLS uses the thread library */
- rc = hythread_attach (&portLibrary->attached_thread);
+ rc = hyThreadLibrary->thread_attach (hyThreadLibrary, &portLibrary->attached_thread);
if (0 != rc)
{
/* Reassign return code as hythread_attach only returns -1 on error */
@@ -217,7 +235,10 @@
{
goto cleanup;
}
-
+
+ /* Store threadLibrary in port globals */
+ portLibrary->portGlobals->threadLibrary = hyThreadLibrary;
+
/* Create the tls buffers as early as possible */
rc = hyport_tls_startup (portLibrary);
if (0 != rc)
@@ -539,6 +560,12 @@
return rc;
}
+HyThreadLibrary * VMCALL
+hyport_get_thread_library(HyPortLibrary * portLib)
+{
+ return portLib->portGlobals->threadLibrary;
+}
+
/* Set up the NLS catalog. This must be called prior to attempting
* any nls_printf() calls on the port library.
*/
Index: trunk/modules/portlib/src/main/native/port/shared/hytlshelpers.c
===================================================================
--- trunk/modules/portlib/src/main/native/port/shared/hytlshelpers.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/port/shared/hytlshelpers.c (working copy)
@@ -49,6 +49,7 @@
void *VMCALL
hyport_tls_get (struct HyPortLibrary *portLibrary)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
PortlibPTBuffers_t ptBuffers;
ptBuffers =
@@ -97,6 +98,7 @@
void VMCALL
hyport_tls_free (struct HyPortLibrary *portLibrary)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
PortlibPTBuffers_t ptBuffers;
MUTEX_ENTER (portLibrary->portGlobals->tls_mutex);
@@ -147,6 +149,7 @@
I_32 VMCALL
hyport_tls_startup (struct HyPortLibrary *portLibrary)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
if (hythread_tls_alloc (&portLibrary->portGlobals->tls_key))
{
return HYPORT_ERROR_STARTUP_TLS_ALLOC;
@@ -172,6 +175,7 @@
void VMCALL
hyport_tls_shutdown (struct HyPortLibrary *portLibrary)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
PortlibPTBuffers_t ptBuffers, next;
/* Free all remaining buffer sets */
@@ -207,6 +211,6 @@
void *VMCALL
hyport_tls_peek (struct HyPortLibrary *portLibrary)
{
- return hythread_tls_get (hythread_self (),
- portLibrary->portGlobals->tls_key);
+ THREAD_ACCESS_FROM_PORT(portLibrary);
+ return hythread_tls_get (hythread_self (), portLibrary->portGlobals->tls_key);
}
Index: trunk/modules/portlib/src/main/native/port/shared/portpriv.h
===================================================================
--- trunk/modules/portlib/src/main/native/port/shared/portpriv.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/port/shared/portpriv.h (working copy)
@@ -22,6 +22,7 @@
#include "hyportpg.h"
#include "hyportptb.h"
#include "hyport.h"
+#include "hythread.h"
#include "hymutex.h"
/* The following defines are used by hyshmem and hyshsem */
@@ -85,6 +86,7 @@
hythread_tls_key_t tls_key;
MUTEX tls_mutex;
void *buffer_list;
+ struct HyThreadLibrary *threadLibrary;
struct HyPortPlatformGlobals platformGlobals;
} HyPortLibraryGlobalData;
/* HySourceHyCPUControl*/
@@ -1159,6 +1161,9 @@
hysl_up_lookup_name
PROTOTYPE ((struct HyPortLibrary * portLibrary, UDATA descriptor, char *name,
UDATA * func, const char *argSignature));
+extern HY_CFUNC HyThreadLibrary * VMCALL
+ hyport_get_thread_library
+PROTOTYPE ((HyPortLibrary * portLib));
static HyPortLibrary MasterPortLibraryTable = {
{HYPORT_MAJOR_VERSION_NUMBER, HYPORT_MINOR_VERSION_NUMBER, 0, HYPORT_CAPABILITY_MASK}, /* portVersion */
NULL, /* portGlobals */
@@ -1394,6 +1399,7 @@
hyshmem_findclose, /* shmem_findclose */
hyshmem_stat, /* shmem_stat */
hysysinfo_get_processing_capacity, /* sysinfo_get_processing_capacity */
+ hyport_get_thread_library, /* port_get_thread_library */
};
#endif
Index: trunk/modules/portlib/src/main/native/port/unix/hysignal.c
===================================================================
--- trunk/modules/portlib/src/main/native/port/unix/hysignal.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/port/unix/hysignal.c (working copy)
@@ -222,7 +222,7 @@
void *fn_arg, hysig_handler_fn handler, void *handler_arg,
U_32 flags, UDATA * result)
{
-
+ THREAD_ACCESS_FROM_PORT(portLibrary);
struct HySignalHandlerRecord thisRecord;
hythread_t thisThread;
U_32 rc = 0;
Index: trunk/modules/portlib/src/main/native/port/unix/makefile
===================================================================
--- trunk/modules/portlib/src/main/native/port/unix/makefile (revision 501409)
+++ trunk/modules/portlib/src/main/native/port/unix/makefile (working copy)
@@ -33,7 +33,7 @@
hysysinfo.o hytime.o $(SHAREDSUB)hytlshelpers.o hytty.o hyvmem.o \
hysignal.o $(HY_PLATFORM)/hysignal_context.o
-MDLLIBFILES = $(DLLPATH)libhythr.so $(LIBPATH)libhycommon.a $(DLLPATH)libhysig.so
+MDLLIBFILES = $(LIBPATH)libhycommon.a $(DLLPATH)libhysig.so $(DLLPATH)libhythr.so
DLLNAME = ../libhyprt.so
Index: trunk/modules/portlib/src/main/native/port/windows/hysignal.c
===================================================================
--- trunk/modules/portlib/src/main/native/port/windows/hysignal.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/port/windows/hysignal.c (working copy)
@@ -18,6 +18,7 @@
#include
#include
#include "hyport.h"
+#include "portpriv.h"
#include "hythread.h"
#include "hysignal.h"
@@ -63,6 +64,7 @@
static U_32 countInfoInCategory (struct HyPortLibrary *portLibrary,
void *info, U_32 category);
+static HyThreadLibrary * threadLibraryForConsoleCtrlHandler;
static BOOL WINAPI consoleCtrlHandler (DWORD dwCtrlType);
int structuredExceptionHandler (struct HyPortLibrary *portLibrary,
@@ -142,6 +144,7 @@
hysig_handler_fn handler, void *handler_arg,
U_32 flags)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
U_32 rc = 0;
HyWin32AsyncHandlerRecord *cursor;
HyWin32AsyncHandlerRecord **previousLink;
@@ -169,9 +172,11 @@
/* if this is the last handler, unregister the Win32 handler function */
if (asyncHandlerList == NULL)
- {
- SetConsoleCtrlHandler (consoleCtrlHandler, FALSE);
- }
+ {
+ /* The static function consoleCtrlHandler needs a threadLibrary */
+ threadLibraryForConsoleCtrlHandler = privateThreadLibrary;
+ SetConsoleCtrlHandler (consoleCtrlHandler, FALSE);
+ }
}
else
{
@@ -205,9 +210,11 @@
/* if this is the first handler, register the Win32 handler function */
if (asyncHandlerList == NULL)
- {
- SetConsoleCtrlHandler (consoleCtrlHandler, TRUE);
- }
+ {
+ /* The static function consoleCtrlHandler needs a threadLibrary */
+ threadLibraryForConsoleCtrlHandler = privateThreadLibrary;
+ SetConsoleCtrlHandler (consoleCtrlHandler, TRUE);
+ }
/* add the new record to the end of the list */
*previousLink = record;
@@ -252,6 +259,8 @@
void VMCALL
hysig_shutdown (struct HyPortLibrary *portLibrary)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
+
hythread_monitor_t globalMonitor = hythread_global_monitor ();
removeAsyncHandlers (portLibrary);
@@ -275,6 +284,7 @@
I_32 VMCALL
hysig_startup (struct HyPortLibrary *portLibrary)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
hythread_monitor_t globalMonitor = hythread_global_monitor ();
I_32 result = 0;
@@ -654,6 +664,8 @@
static BOOL WINAPI
consoleCtrlHandler (DWORD dwCtrlType)
{
+ THREAD_ACCESS_FROM_THREAD(threadLibraryForConsoleCtrlHandler);
+
U_32 flags;
BOOL result = FALSE;
@@ -713,6 +725,7 @@
static void
removeAsyncHandlers (HyPortLibrary * portLibrary)
{
+ THREAD_ACCESS_FROM_PORT(portLibrary);
/* clean up the list of async handlers */
HyWin32AsyncHandlerRecord *cursor;
HyWin32AsyncHandlerRecord **previousLink;
@@ -744,6 +757,8 @@
if (asyncHandlerList == NULL)
{
+ /* The static function consoleCtrlHandler needs a threadLibrary */
+ threadLibraryForConsoleCtrlHandler = privateThreadLibrary;
SetConsoleCtrlHandler (consoleCtrlHandler, FALSE);
}
Index: trunk/modules/portlib/src/main/native/port/windows/makefile
===================================================================
--- trunk/modules/portlib/src/main/native/port/windows/makefile (revision 501409)
+++ trunk/modules/portlib/src/main/native/port/windows/makefile (working copy)
@@ -42,7 +42,7 @@
Delayimp.lib -delayload:shell32.dll -delayload:Iphlpapi.dll \
ws2_32.lib Iphlpapi.lib shell32.lib
-MDLLIBFILES = $(LIBPATH)hythr.lib $(LIBPATH)hycommon.lib $(LIBPATH)hysig.lib
+MDLLIBFILES = $(LIBPATH)hycommon.lib $(LIBPATH)hysig.lib $(LIBPATH)hythr.lib
DLLBASE=0x11100000
COMMENT=/comment:"Platform port library. (c) Copyright 1993, 2005 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/portlib/src/main/native/thread/shared/hythread.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/shared/hythread.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/shared/hythread.c (working copy)
@@ -21,3680 +21,74 @@
* @brief Threading and synchronization support
*/
-#include "threaddef.h"
+#include "hythread.h"
#include
-#define CDEV_CURRENT_FUNCTION _prototypes_private
-static hythread_t allocate_thread PROTOTYPE ((int globalIsLocked));
-static void free_thread
-PROTOTYPE ((hythread_t thread, int globalAlreadyLocked));
-static IDATA interrupt_waiting_thread
-PROTOTYPE ((hythread_t self, hythread_t threadToInterrupt));
-static void remove_from_queue
-PROTOTYPE ((hythread_t volatile *queue, hythread_t thread));
-static IDATA destroy_thread
-PROTOTYPE ((hythread_t thread, int globalAlreadyLocked));
-void VMCALL hythread_shutdown PROTOTYPE ((void));
-static void HYTHREAD_PROC tls_null_finalizer PROTOTYPE ((void *entry));
-static I_32 HYTHREAD_PROC interruptServer PROTOTYPE ((void *entryArg));
-static hythread_monitor_t VMCALL hythread_monitor_acquire
-PROTOTYPE ((hythread_t self, IDATA policy, IDATA policyData));
-void VMCALL hythread_init PROTOTYPE ((hythread_library_t lib));
-static IDATA init_global_monitor PROTOTYPE ((hythread_library_t lib));
-static void tls_finalize PROTOTYPE ((hythread_t thread));
-static void free_monitor_pools PROTOTYPE ((void));
-static void *VMCALL thread_malloc PROTOTYPE ((void *unused, U_32 size));
-static void NORETURN internal_exit PROTOTYPE ((void));
-static IDATA monitor_wait
-PROTOTYPE ((hythread_monitor_t monitor, I_64 millis, IDATA nanos,
- IDATA interruptable));
-static IDATA monitor_enter
-PROTOTYPE ((hythread_t self, hythread_monitor_t monitor));
-static UDATA init_monitor
-PROTOTYPE ((hythread_monitor_t monitor, UDATA flags));
-
-static IDATA monitor_enter_three_tier
-PROTOTYPE ((hythread_t self, hythread_monitor_t monitor));
-
-static hytime_t getCurrentCycles PROTOTYPE ((void));
-static hythread_monitor_pool_t allocate_monitor_pool PROTOTYPE ((void));
-static IDATA create_thread
-PROTOTYPE ((hythread_t * handle, UDATA stacksize, UDATA priority,
- UDATA suspend, hythread_entrypoint_t entrypoint, void *entryarg,
- int globalIsLocked));
-static void interrupt_thread
-PROTOTYPE ((hythread_t thread, UDATA interruptFlag));
-
-static void unblock_spinlock_threads
-PROTOTYPE ((hythread_t self, hythread_monitor_t monitor));
-
-static void notify_thread
-PROTOTYPE ((hythread_t threadToNotify, int setNotifiedFlag));
-static IDATA monitor_exit
-PROTOTYPE ((hythread_t self, hythread_monitor_t monitor));
-static WRAPPER_TYPE thread_wrapper PROTOTYPE ((WRAPPER_ARG arg));
-static void VMCALL thread_free PROTOTYPE ((void *unused, void *ptr));
-static void enqueue_thread
-PROTOTYPE ((hythread_t * queue, hythread_t thread));
-static IDATA monitor_notify_one_or_all
-PROTOTYPE ((hythread_monitor_t monitor, int notifyall));
-
-#undef CDEV_CURRENT_FUNCTION
-
-#if defined(THREAD_ASSERTS)
-/*
- * Helper variable for asserts.
- * We use this to keep track of when the global lock is owned.
- * We don't want to do a re-entrant enter on the global lock
- */
-hythread_t global_lock_owner = UNOWNED;
-#endif
-
-#define BOUNDED_I64_TO_IDATA(longValue) ((longValue) > 0x7FFFFFFF ? 0x7FFFFFFF : (IDATA)(longValue))
-
-#define HYTHREAD_MAX_TLS_KEYS (sizeof( ((HyThreadLibrary*)NULL)->tls_finalizers ) / sizeof( ((HyThreadLibrary*)NULL)->tls_finalizers[0] ))
-
-#define CDEV_CURRENT_FUNCTION hythread_init
/**
- * Initialize a Hy threading library.
- *
- * @note This must only be called once.
- *
- * If any OS threads were created before calling this function, they must be attached using
- * hythread_attach before accessing any Hy thread library functions.
- *
- * @param[in] lib pointer to the Hy thread library to be initialized (non-NULL)
- * @return The Hy thread library's initStatus will be set to 0 on success or
- * a negative value on failure.
- *
- * @see hythread_attach, hythread_shutdown
+ * @name Thread library startup and shutdown functions
+ * @anchor ThreadStartup
+ * Create, initialize, startup and shutdow the thread library
+ * @{
*/
-void VMCALL
-hythread_init (hythread_library_t lib)
+/** Standard startup and shutdown (thread library allocated on stack or by application) */
+HY_CFUNC I_32 VMCALL
+hythread_create_library (struct HyThreadLibrary *threadLibrary,
+ struct HyThreadLibraryVersion
+ *version, UDATA size)
{
- ASSERT (lib);
-
- lib->spinlock = 0;
- lib->threadCount = 0;
- lib->globals = NULL;
- lib->stack_usage = 0;
-
- /* set all TLS finalizers to NULL. This indicates that the key is unused */
- memset (lib->tls_finalizers, 0, sizeof (lib->tls_finalizers));
-
- STATIC_ASSERT (CALLER_LAST_INDEX <= MAX_CALLER_INDEX);
-
- if (TLS_ALLOC (lib->self_ptr))
- goto init_cleanup1;
-
- lib->monitor_pool = allocate_monitor_pool ();
- if (lib->monitor_pool == NULL)
- goto init_cleanup2;
-
- if (!MUTEX_INIT (lib->monitor_mutex))
- goto init_cleanup3;
- if (!MUTEX_INIT (lib->tls_mutex))
- goto init_cleanup4;
- if (!MUTEX_INIT (lib->global_mutex))
- goto init_cleanup5;
-
- lib->thread_pool =
- pool_new (sizeof (HyThread), 0, 0, 0, thread_malloc, thread_free, NULL);
- if (lib->thread_pool == NULL)
- goto init_cleanup6;
-
- lib->global_pool =
- pool_new (sizeof (HyThreadGlobal), 0, 0, 0, thread_malloc, thread_free,
- NULL);
- if (lib->global_pool == NULL)
- goto init_cleanup7;
-
- if (init_global_monitor (lib))
- goto init_cleanup8;
-
- lib->initStatus = 1;
- return;
-
-init_cleanup8:pool_kill (lib->global_pool);
-init_cleanup7:pool_kill (lib->thread_pool);
-init_cleanup6:MUTEX_DESTROY (lib->global_mutex);
-init_cleanup5:MUTEX_DESTROY (lib->tls_mutex);
-init_cleanup4:MUTEX_DESTROY (lib->monitor_mutex);
-init_cleanup3:free_monitor_pools ();
-init_cleanup2:TLS_DESTROY (lib->self_ptr);
-init_cleanup1:lib->initStatus = -1;
+ return -1;
}
-#undef CDEV_CURRENT_FUNCTION
-#define CDEV_CURRENT_FUNCTION hythread_self
-/**
- * Return the hythread_t for the current thread.
- *
- * @note Must be called only by an attached thread
- *
- * @return hythread_t for the current thread
- *
- * @see hythread_attach
- *
- */
-hythread_t VMCALL
-hythread_self (void)
+HY_CFUNC I_32 VMCALL
+hythread_init_library (struct HyThreadLibrary *threadLibrary,
+ struct HyThreadLibraryVersion *version, UDATA size)
{
- return MACRO_SELF ();
+ return -1;
}
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_create
-/**
- * Create a new OS thread.
- *
- * The created thread is attached to the threading library.
- *
- * Unlike POSIX, this doesn't require an attributes structure.
- * Instead, any interesting attributes (e.g. stacksize) are
- * passed in with the arguments.
- *
- * @param[out] handle a pointer to a hythread_t which will point to the thread (if successfully created)
- * @param[in] stacksize the size of the new thread's stack (bytes)
- * 0 indicates use default size
- * @param[in] priority priorities range from HYTHREAD_PRIORITY_MIN to HYTHREAD_PRIORITY_MAX (inclusive)
- * @param[in] suspend set to non-zero to create the thread in a suspended state.
- * @param[in] entrypoint pointer to the function which the thread will run
- * @param[in] entryarg a value to pass to the entrypoint function
- *
- * @return 0 on success or negative value on failure
- *
- * @see hythread_exit, hythread_resume
- */
-IDATA VMCALL
-hythread_create (hythread_t * handle, UDATA stacksize, UDATA priority,
- UDATA suspend, hythread_entrypoint_t entrypoint,
- void *entryarg)
+HY_CFUNC I_32 VMCALL
+hythread_shutdown_library (struct HyThreadLibrary *threadLibrary)
{
- return create_thread (handle, stacksize, priority, suspend, entrypoint,
- entryarg, GLOBAL_NOT_LOCKED);
+ return -1;
}
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION create_thread
-/*
- * Create a new OS thread and attach it.
- */
-static IDATA
-create_thread (hythread_t * handle, UDATA stacksize, UDATA priority,
- UDATA suspend, hythread_entrypoint_t entrypoint,
- void *entryarg, int globalIsLocked)
+HY_CFUNC I_32 VMCALL
+hythread_startup_library (struct HyThreadLibrary *threadLibrary)
{
- hythread_t thread;
- hythread_library_t lib = GLOBAL_DATA (default_library);
-
- ASSERT (lib->initStatus);
-
- if (priority > HYTHREAD_PRIORITY_MAX)
- {
- goto cleanup0;
- }
-
- if (stacksize == 0)
- {
- stacksize = STACK_DEFAULT_SIZE;
- }
-
- thread = allocate_thread (globalIsLocked);
- if (!thread)
- {
- goto cleanup0;
- }
- if (handle)
- {
- *handle = thread;
- }
- thread->library = lib;
- thread->priority = priority;
- thread->attachcount = 0;
- thread->stacksize = stacksize;
-
- memset (thread->tls, 0, sizeof (thread->tls));
-
- thread->interrupter = NULL;
-
- if (!COND_INIT (thread->condition))
- {
- goto cleanup1;
- }
- if (!MUTEX_INIT (thread->mutex))
- {
- goto cleanup2;
- }
-
- thread->flags = suspend ? HYTHREAD_FLAG_SUSPENDED : 0;
- thread->entrypoint = entrypoint;
- thread->entryarg = entryarg;
-
- if (IS_JLM_ENABLED (thread))
- {
- hythread_jlm_thread_init (thread);
- }
-
-#if defined(LINUX)
- thread->jumpBuffer = NULL;
-#endif
-
- if (!THREAD_CREATE (thread, stacksize, priority, thread_wrapper, thread))
- {
- goto cleanup3;
- }
-
- return 0;
-
-/* Cleanup points */
-cleanup3:MUTEX_DESTROY (thread->mutex);
-cleanup2:COND_DESTROY (thread->condition);
-cleanup1:free_thread (thread, GLOBAL_NOT_LOCKED);
-cleanup0:if (handle)
- *handle = NULL;
return -1;
}
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_attach
-/**
- * Attach an OS thread to the threading library.
- *
- * Create a new hythread_t to represent the existing OS thread.
- * Attaching a thread is required when a thread was created
- * outside of the Hy threading library wants to use any of the
- * Hy threading library functionality.
- *
- * If the OS thread is already attached, handle is set to point
- * to the existing hythread_t.
- *
- * @param[out] handle pointer to a hythread_t to be set (will be ignored if null)
- * @return 0 on success or negative value on failure
- *
- * @see hythread_detach
- */
-IDATA VMCALL
-hythread_attach (hythread_t * handle)
+/** Thread library self allocation routines */
+HY_CFUNC I_32 VMCALL
+hythread_allocate_library (struct HyThreadLibraryVersion*expectedVersion,
+ struct HyThreadLibrary **threadLibrary)
{
- hythread_t thread;
-
- if (init_thread_library ())
- {
- goto cleanup0;
- }
-
- if ((thread = MACRO_SELF ()) != NULL)
- {
- if (handle)
- {
- *handle = thread;
- }
- THREAD_LOCK (thread, thread, CALLER_ATTACH);
- thread->attachcount++;
- THREAD_UNLOCK (thread, thread);
- return 0;
- }
-
- thread = allocate_thread (GLOBAL_NOT_LOCKED);
- if (!thread)
- {
- goto cleanup0;
- }
-
- thread->library = GLOBAL_DATA (default_library);
- thread->attachcount = 1;
- thread->priority = HYTHREAD_PRIORITY_NORMAL;
- thread->flags = HYTHREAD_FLAG_ATTACHED;
-
- if (!COND_INIT (thread->condition))
- {
- goto cleanup1;
- }
-
- if (!MUTEX_INIT (thread->mutex))
- {
- goto cleanup2;
- }
-
-#if defined(WIN32)
- {
- DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
- GetCurrentProcess (), &thread->handle, 0, TRUE,
- DUPLICATE_SAME_ACCESS);
- }
-#else
- thread->handle = THREAD_SELF ();
-#endif
-
- initialize_thread_priority (thread);
-
- TLS_SET (thread->library->self_ptr, thread);
-
- thread->tid = RAS_THREAD_ID ();
-
- if (handle)
- {
- *handle = thread;
- }
- return 0;
-
-/* failure points */
-cleanup2:COND_DESTROY (thread->condition);
-cleanup1:free_thread (thread, GLOBAL_NOT_LOCKED);
-cleanup0:return -1;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_suspend
-/**
- * Suspend the current thread.
- *
- * Stop the current thread from executing until it is resumed.
- *
- * @return none
- *
- * @see hythread_resume
- */
-void VMCALL
-hythread_suspend (void)
-{
- hythread_t self = MACRO_SELF ();
- ASSERT (self);
-
- THREAD_LOCK (self, self, CALLER_SUSPEND);
- self->flags |= HYTHREAD_FLAG_SUSPENDED;
-
- COND_WAIT (self->condition, self->mutex);
- if ((self->flags & HYTHREAD_FLAG_SUSPENDED) == 0)
- break;
- COND_WAIT_LOOP ();
-
- THREAD_UNLOCK (self, self);
+ return -1;
}
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_resume
+/** @} */
/**
- * Resume a thread.
- *
- * Take a threads out of the suspended state.
- *
- * If the thread is not suspended, no action is taken.
- *
- * @param[in] thread a thread to be resumed
- * @return none
- *
- * @see hythread_create, hythread_suspend
- */
-void VMCALL
-hythread_resume (hythread_t thread)
-{
- hythread_t self;
-
- ASSERT (thread);
-
- if ((thread->flags & HYTHREAD_FLAG_SUSPENDED) == 0)
- {
- /* it wasn't suspended! */
- return;
- }
-
- self = MACRO_SELF ();
- ASSERT (self);
-
- THREAD_LOCK (self, thread, CALLER_RESUME);
-
- /*
- * The thread _should_ only be OS suspended once, but
- * handle the case where it's suspended more than once anyway.
- */
- COND_NOTIFY_ALL (thread->condition);
- thread->flags &= ~HYTHREAD_FLAG_SUSPENDED;
-
- THREAD_UNLOCK (self, thread);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_yield
-/**
- * Yield the processor.
- *
- * @return none
- */
-void VMCALL
-hythread_yield (void)
-{
- THREAD_YIELD ();
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_init
-/*
- * Acquire and initialize a new monitor from the threading library.
- *
- * @param[out] handle pointer to a hythread_monitor_t to be set to point to the new monitor
- * @param[in] flags initial flag values for the monitor
- * @return 0 on success, negative value on failure
- *
- * @deprecated This has been replaced by hythread_monitor_init_with_name
- * @see hythread_monitor_init_with_name
- */
-IDATA VMCALL
-hythread_monitor_init (hythread_monitor_t * handle, UDATA flags)
-{
- IDATA rc;
-
- /* Initialize monitor with default locking policy */
- rc =
- hythread_monitor_init_policy (handle, flags, HYTHREAD_LOCKING_DEFAULT,
- HYTHREAD_LOCKING_NO_DATA);
- return rc;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_init_policy
-/*
- * Acquire and initialize a new monitor with given locking policy from the threading library.
- *
- * @param[out] handle pointer to a hythread_monitor_t to be set to point to the new monitor
- * @param[in] flags initial flag values for the monitor
- * @param[in] locking policy for the monitor
- * @param[in] data associated with locking policy or HYTHREAD_LOCKING_NO_DATA
- * @return 0 on success, negative value on failure
- *
+ * @name Thread library version and compatability queries
+ * @anchor ThreadVersionControl
+ * Determine thread library compatability and version.
+ * @{
*/
-IDATA VMCALL
-hythread_monitor_init_policy (hythread_monitor_t * handle, UDATA flags,
- IDATA policy, IDATA policyData)
+HY_CFUNC UDATA VMCALL
+hythread_getSize (struct HyThreadLibraryVersion *version)
{
- hythread_monitor_t monitor;
-
- hythread_t self = MACRO_SELF ();
- ASSERT (self);
- ASSERT (handle);
-
- monitor = hythread_monitor_acquire (self, policy, policyData);
- if (NULL == monitor)
- {
- return -1;
- }
-
- if (init_monitor (monitor, flags) != 0)
- {
- return -1;
- }
-
- if (IS_JLM_ENABLED (self))
- {
- hythread_jlm_monitor_init (monitor);
- }
-
- *handle = monitor;
return 0;
}
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_destroy
-/**
- * Destroy a monitor.
- *
- * Destroying a monitor frees the internal resources associated
- * with it.
- *
- * @note A monitor must NOT be destroyed if threads are waiting on
- * it, or if it is currently owned.
- *
- * @param[in] monitor a monitor to be destroyed
- * @return 0 on success or non-0 on failure (the monitor is in use)
- *
- * @see hythread_monitor_init_with_name
- */
-IDATA VMCALL
-hythread_monitor_destroy (hythread_monitor_t monitor)
+HY_CFUNC I_32 VMCALL
+hythread_getVersion (struct HyThreadLibrary *threadLibrary,
+ struct HyThreadLibraryVersion *version)
{
- hythread_t self = MACRO_SELF ();
-
- ASSERT (self);
- ASSERT (monitor);
-
- GLOBAL_LOCK (self, CALLER_MONITOR_DESTROY);
-
- if (monitor->owner || monitor->waiting)
- {
- /* This monitor is in use! It was probably abandoned when a thread was cancelled.
- * There's actually a very small timing hole here -- if the thread had just locked the
- * mutex and not yet set the owner field when it was cancelled, we have no way of
- * knowing that the mutex may be in an invalid state. The same thing can happen
- * if the thread has just cleared the field and is about to unlock the mutex.
- * Hopefully the OS takes care of this for us, but it might not.
- */
- GLOBAL_UNLOCK (self);
- return HYTHREAD_ILLEGAL_MONITOR_STATE;
- }
-
- monitor->owner = (hythread_t) self->library->monitor_pool->next_free;
- monitor->count = FREE_TAG;
- monitor->userData = 0;
- self->library->monitor_pool->next_free = monitor;
-
- GLOBAL_UNLOCK (self);
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_enter
-/**
- * Enter a monitor.
- *
- * A thread may re-enter a monitor it owns multiple times, but must
- * exit the monitor the same number of times before any other thread
- * wanting to enter the monitor is permitted to continue.
- *
- * @param[in] monitor a monitor to be entered
- * @return 0 on success
- * HYTHREAD_PRIORITY_INTERRUPTED if the thread was priority interrupted while blocked
- *
- * @see hythread_monitor_enter_using_threadId, hythread_monitor_exit, hythread_monitor_exit_using_threadId
- */
-IDATA VMCALL
-hythread_monitor_enter (hythread_monitor_t monitor)
-{
- hythread_t self = MACRO_SELF ();
-
- ASSERT (self);
- ASSERT (monitor);
- ASSERT (FREE_TAG != monitor->count);
-
- if (monitor->owner == self)
- {
- ASSERT (monitor->count >= 1);
- monitor->count++;
-
- if (IS_JLM_ENABLED (self))
- {
- ASSERT (monitor->tracing);
- monitor->tracing->recursive_count++;
- monitor->tracing->enter_count++;
- } /* if (IS_JLM_ENABLED(self)) */
-
- return 0;
- }
-
- return monitor_enter (self, monitor);
+ return -1;
}
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_exit
-/**
- * Exit a monitor.
- *
- * Exit a monitor, and if the owning count is zero, release it.
- *
- * @param[in] monitor a monitor to be exited
- * @return 0 on success,
HYTHREAD_ILLEGAL_MONITOR_STATE if the current thread does not own the monitor
- *
- * @see hythread_monitor_exit_using_threadId, hythread_monitor_enter, hythread_monitor_enter_using_threadId
- */
-IDATA VMCALL
-hythread_monitor_exit (hythread_monitor_t monitor)
+HY_CFUNC I_32 VMCALL
+hythread_isCompatible (struct HyThreadLibraryVersion *expectedVersion)
{
- hythread_t self = MACRO_SELF ();
-
- ASSERT (self);
- ASSERT (monitor);
- ASSERT (FREE_TAG != monitor->count);
-
- if (monitor->owner != self)
- {
- return HYTHREAD_ILLEGAL_MONITOR_STATE;
- }
-
- return monitor_exit (self, monitor);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_wait
-/**
- * Wait on a monitor until notified.
- *
- * Release the monitor, wait for a signal (notification), then re-acquire the monitor.
- *
- * @param[in] monitor a monitor to be waited on
- * @return 0 if the monitor has been waited on, notified, and reobtained
- * HYTHREAD_INVALID_ARGUMENT if millis or nanos is out of range (millis or nanos < 0, or nanos >= 1E6)
- * HYTHREAD_ILLEGAL_MONITOR_STATE if the current thread does not own the monitor
- *
- * @see hythread_monitor_wait_interruptable, hythread_monitor_wait_timed, hythread_monitor_enter
- *
- */
-IDATA VMCALL
-hythread_monitor_wait (hythread_monitor_t monitor)
-{
- return monitor_wait (monitor, 0, 0, WAIT_UNINTERRUPTABLE);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_notify
-/**
- * Notify a single thread waiting on a monitor.
- *
- * A thread is considered to be waiting on the monitor if
- * it is currently blocked while executing hythread_monitor_wait on the monitor.
- *
- * If no threads are waiting, no action is taken.
- *
- * @param[in] monitor a monitor to be signaled
- * @return 0 once the monitor has been signaled
HYTHREAD_ILLEGAL_MONITOR_STATE if the current thread does not own the monitor
- *
- * @see hythread_monitor_notify_all, hythread_monitor_enter, hythread_monitor_wait
- */
-IDATA VMCALL
-hythread_monitor_notify (hythread_monitor_t monitor)
-{
- return monitor_notify_one_or_all (monitor, NOTIFY_ONE);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_notify_all
-/**
- * Notify all threads waiting on a monitor.
- *
- * A thread is considered to be waiting on the monitor if
- * it is currently blocked while executing hythread_monitor_wait on the monitor.
- *
- * If no threads are waiting, no action is taken.
- *
- *
- * @param[in] monitor a monitor to be signaled
- * @return 0 once the monitor has been signaled
HYTHREAD_ILLEGAL_MONITOR_STATE if the current thread does not own the monitor
- *
- * @see hythread_monitor_notify, hythread_monitor_enter, hythread_monitor_wait
- */
-IDATA VMCALL
-hythread_monitor_notify_all (hythread_monitor_t monitor)
-{
- return monitor_notify_one_or_all (monitor, NOTIFY_ALL);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_tls_alloc
-/**
- * Allocate a thread local storage (TLS) key.
- *
- * Create and return a new, unique key for thread local storage.
- *
- * @note The hande returned will be >=0, so it is safe to test the handle against 0 to see if it's been
- * allocated yet.
- *
- * @param[out] handle pointer to a key to be initialized with a key value
- * @return 0 on success or negative value if a key could not be allocated (i.e. all TLS has been allocated)
- *
- * @see hythread_tls_free, hythread_tls_set
- */
-IDATA VMCALL
-hythread_tls_alloc (hythread_tls_key_t * handle)
-{
- return hythread_tls_alloc_with_finalizer (handle, tls_null_finalizer);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_tls_free
-/**
- * Release a TLS key.
- *
- * Release a TLS key previously allocated by hythread_tls_alloc.
- *
- * @param[in] key TLS key to be freed
- * @return 0 on success or negative value on failure
- *
- * @see hythread_tls_alloc, hythread_tls_set
- *
- */
-IDATA VMCALL
-hythread_tls_free (hythread_tls_key_t key)
-{
- HyPoolState state;
- hythread_t each;
- hythread_library_t lib = GLOBAL_DATA (default_library);
- ASSERT (lib);
-
- /* clear the TLS in every existing thread */
- GLOBAL_LOCK_SIMPLE (lib);
- each = pool_startDo (lib->thread_pool, &state);
- while (each)
- {
- each->tls[key - 1] = NULL;
- each = pool_nextDo (&state);
- }
- GLOBAL_UNLOCK_SIMPLE (lib);
-
- /* now return the key to the free set */
- MUTEX_ENTER (lib->tls_mutex);
- lib->tls_finalizers[key - 1] = NULL;
- MUTEX_EXIT (lib->tls_mutex);
-
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_tls_set
-/**
- * Set a thread's TLS value.
- *
- * @param[in] thread a thread
- * @param[in] key key to have TLS value set (any value returned by hythread_alloc)
- * @param[in] value value to be stored in TLS
- * @return 0 on success or negative value on failure
- *
- * @see hythread_tls_alloc, hythread_tls_free, hythread_tls_get
- */
-IDATA VMCALL
-hythread_tls_set (hythread_t thread, hythread_tls_key_t key, void *value)
-{
- thread->tls[key - 1] = value;
-
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_set_priority
-/**
- * Set a thread's execution priority.
- *
- * @param[in] thread a thread
- * @param[in] priority
- * Use the following symbolic constants for priorities:
- * HYTHREAD_PRIORITY_MAX
- * HYTHREAD_PRIORITY_USER_MAX
- * HYTHREAD_PRIORITY_NORMAL
- * HYTHREAD_PRIORITY_USER_MIN
- * HYTHREAD_PRIORITY_MIN
- *
- * @returns 0 on success or negative value on failure (priority wasn't changed)
- *
- *
- */
-IDATA VMCALL
-hythread_set_priority (hythread_t thread, UDATA priority)
-{
- ASSERT (thread);
-
- if (priority > HYTHREAD_PRIORITY_MAX)
- {
- return -1;
- }
-
- if (THREAD_SET_PRIORITY (thread->handle, priority_map[priority]))
- {
- return -1;
- }
-
- thread->priority = priority;
-
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_interrupt
-/**
- * Interrupt a thread.
- *
- * If the thread is currently blocked (i.e. waiting on a monitor_wait or sleeping)
- * resume the thread and cause it to return from the blocking function with
- * HYTHREAD_INTERRUPTED.
- *
- * @param[in] thread a thead to be interrupted
- * @return none
- */
-void VMCALL
-hythread_interrupt (hythread_t thread)
-{
- interrupt_thread (thread, HYTHREAD_FLAG_INTERRUPTED);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_interrupted
-/**
- * Return the value of a thread's interrupted flag.
- *
- * @param[in] thread thread to be queried
- * @return 0 if not interrupted, non-zero if interrupted
- */
-UDATA VMCALL
-hythread_interrupted (hythread_t thread)
-{
- ASSERT (thread);
- return (thread->flags & HYTHREAD_FLAG_INTERRUPTED) != 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_clear_interrupted
-/**
- * Clear the interrupted flag of the current thread and return its previous value.
- *
- * @return previous value of interrupted flag: non-zero if the thread had been interrupted.
- */
-UDATA VMCALL
-hythread_clear_interrupted (void)
-{
- UDATA oldFlags;
- hythread_t self = MACRO_SELF ();
- ASSERT (self);
-
- THREAD_LOCK (self, self, CALLER_CLEAR_INTERRUPTED);
- oldFlags = self->flags;
- self->flags = oldFlags & ~HYTHREAD_FLAG_INTERRUPTED;
- THREAD_UNLOCK (self, self);
-
- return (oldFlags & HYTHREAD_FLAG_INTERRUPTED) != 0;
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION remove_from_queue
-/*
- * Remove a thread from a monitor's queue.
- *
- * @param[in] queue head of a monitor's queue
- * @param[in] thread thread to be removed from queue
- * @return none
- */
-static void
-remove_from_queue (hythread_t volatile *queue, hythread_t thread)
-{
- hythread_t queued, next;
-
- ASSERT (thread);
-
- if ((queued = *queue) == NULL)
- return;
-
- if (queued == thread)
- {
- *queue = thread->next;
- thread->next = NULL;
- }
- else
- {
- while ((next = queued->next) != NULL && next != thread)
- {
- queued = next;
- }
- if (next != NULL)
- {
- queued->next = thread->next;
- thread->next = NULL;
- }
- }
-
- ASSERT (NULL == thread->next);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION allocate_monitor_pool
-/*
- * Create and initialize a pool of monitors.
- *
- * @return pointer to a new monitor pool on success, NULL on failure
- *
- */
-static hythread_monitor_pool_t
-allocate_monitor_pool (void)
-{
- int i;
- hythread_monitor_t entry;
- hythread_monitor_pool_t pool =
- (hythread_monitor_pool_t) malloc (sizeof (HyThreadMonitorPool));
- if (pool == NULL)
- {
- return NULL;
- }
- memset (pool, 0, sizeof (HyThreadMonitorPool));
-
- pool->next_free = entry = &pool->entries[0];
- for (i = 0; i < MONITOR_POOL_SIZE - 1; i++, entry++)
- {
- entry->count = FREE_TAG;
- entry->owner = (hythread_t) (entry + 1);
- /* entry->waiting = entry->blocked = NULL; *//* (unnecessary) */
- entry->flags = HYTHREAD_MONITOR_MUTEX_UNINITIALIZED;
- }
- /* initialize the last monitor */
- entry->count = FREE_TAG;
- entry->flags = HYTHREAD_MONITOR_MUTEX_UNINITIALIZED;
-
- return pool;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION thread_wrapper
-/*
- * Function we pass to the OS for new threads.
- *
- * @param arg pointer to the hythread_t for the new thread
- * @return none
- */
-static WRAPPER_TYPE
-thread_wrapper (WRAPPER_ARG arg)
-{
- hythread_t thread = (hythread_t) arg;
- hythread_library_t lib = thread->library;
- UDATA flags;
-
- ASSERT (thread);
- ASSERT (lib);
-
- thread->tid = RAS_THREAD_ID ();
-
- TLS_SET (lib->self_ptr, thread);
-
- if (lib->stack_usage)
- {
- paint_stack (thread);
- }
-
- if (thread->flags & HYTHREAD_FLAG_CANCELED)
- {
- internal_exit ();
- }
-
- /* Handle the create-suspended case */
- /* (This code is basically the same as hythread_suspend, but we need to
- test the condition under mutex or else there's a timing hole) */
- THREAD_LOCK (thread, thread, CALLER_THREAD_WRAPPER);
- if (thread->flags & HYTHREAD_FLAG_SUSPENDED)
- {
- COND_WAIT (thread->condition, thread->mutex);
- if ((thread->flags & HYTHREAD_FLAG_SUSPENDED) == 0)
- break;
- COND_WAIT_LOOP ();
- }
- thread->flags |= HYTHREAD_FLAG_STARTED;
- flags = thread->flags;
- THREAD_UNLOCK (thread, thread);
-
- if (thread->flags & HYTHREAD_FLAG_CANCELED)
- {
- internal_exit ();
- }
-
-#if defined(LINUX)
- /* Workaround for NPTL bug on Linux. See hythread_exit() */
- {
- jmp_buf jumpBuffer;
- if (0 == setjmp (jumpBuffer))
- {
- thread->jumpBuffer = &jumpBuffer;
- thread->entrypoint (thread->entryarg);
- }
- thread->jumpBuffer = NULL;
- }
-#else
- thread->entrypoint (thread->entryarg);
-#endif
-
- internal_exit ();
- /* UNREACHABLE */
- WRAPPER_RETURN ();
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION monitor_notify_one_or_all
-/*
- * Signal one or all threads waiting on the monitor.
- *
- * If no threads are waiting, this does nothing.
- *
- * @param[in] monitor monitor to be notified on
- * @param[in] notifyall 0 to notify one, non-zero to notify all
- * @return 0 once the monitor has been signalled
- * HYTHREAD_ILLEGAL_MONITOR_STATE if the current thread does not
- * own the monitor
- *
- */
-static IDATA
-monitor_notify_one_or_all (hythread_monitor_t monitor, int notifyall)
-{
-
- hythread_t self = MACRO_SELF ();
- hythread_t queue, next;
- int someoneNotified = 0;
-
- ASSERT (self);
- ASSERT (monitor);
-
- if (monitor->owner != self)
- {
- ASSERT_DEBUG (0);
- return HYTHREAD_ILLEGAL_MONITOR_STATE;
- }
-
- MONITOR_LOCK (self, monitor, CALLER_NOTIFY_ONE_OR_ALL);
-
- next = monitor->waiting;
-
- while (next)
- {
- queue = next;
- next = queue->next;
- THREAD_LOCK (self, queue, CALLER_NOTIFY_ONE_OR_ALL);
- if (queue->flags & HYTHREAD_FLAG_WAITING)
- {
- notify_thread (queue, SET_NOTIFIED_FLAG);
- someoneNotified = 1;
- }
- THREAD_UNLOCK (self, queue);
-
- if ((someoneNotified) && (!notifyall))
- {
- break;
- }
- }
-
- MONITOR_UNLOCK (self, monitor);
-
- return 0;
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION notify_thread
-/*
- * Notify a thread.
- *
- * Helper routine because we notify a thread in
- * a couple of places.
- * @note: assumes the caller has THREAD_LOCK'd the
- * thread being notified (and owns the monitor being notified on)
- * @param[in] threadToNotify thread to notify
- * @param[in] setNotifiedFlag indicates whether to set the notified thread's notified flag.
- * @return none
- */
-static void
-notify_thread (hythread_t threadToNotify, int setNotifiedFlag)
-{
- ASSERT (threadToNotify);
- ASSERT (threadToNotify->flags & HYTHREAD_FLAG_WAITING);
-
- threadToNotify->flags &= ~HYTHREAD_FLAG_WAITING;
- threadToNotify->flags |= HYTHREAD_FLAG_BLOCKED;
- if (setNotifiedFlag)
- {
- threadToNotify->flags |= HYTHREAD_FLAG_NOTIFIED;
- }
- COND_NOTIFY_ALL (threadToNotify->condition);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_sleep_interruptable
-/**
- * Suspend the current thread from executing
- * for at least the specified time.
- *
- * @param[in] millis
- * @param[in] nanos
- * @return 0 on success
- * HYTHREAD_INVALID_ARGUMENT if the arguments are invalid
- * HYTHREAD_INTERRUPTED if the sleep was interrupted
- *
- * @see hythread_sleep
- */
-IDATA VMCALL
-hythread_sleep_interruptable (I_64 millis, IDATA nanos)
-{
- hythread_t self = MACRO_SELF ();
- IDATA boundedMillis = BOUNDED_I64_TO_IDATA (millis);
-
- ASSERT (self);
-
- if ((millis < 0) || (nanos < 0) || (nanos >= 1000000))
- {
- return HYTHREAD_INVALID_ARGUMENT;
- }
-
- THREAD_LOCK (self, self, CALLER_SLEEP_INTERRUPTABLE);
-
- if (self->flags & HYTHREAD_FLAG_INTERRUPTED)
- {
- self->flags &= ~HYTHREAD_FLAG_INTERRUPTED;
- THREAD_UNLOCK (self, self);
- return HYTHREAD_INTERRUPTED;
- }
-
- if (self->flags & HYTHREAD_FLAG_PRIORITY_INTERRUPTED)
- {
- self->flags &= ~HYTHREAD_FLAG_PRIORITY_INTERRUPTED;
- THREAD_UNLOCK (self, self);
- return HYTHREAD_PRIORITY_INTERRUPTED;
- }
-
- self->flags |=
- HYTHREAD_FLAG_SLEEPING | HYTHREAD_FLAG_INTERRUPTABLE |
- HYTHREAD_FLAG_TIMER_SET;
-
- COND_WAIT_IF_TIMEDOUT (self->condition, self->mutex, boundedMillis, nanos)
- {
- break;
- }
- else
- {
- if (self->flags & HYTHREAD_FLAG_INTERRUPTED)
- {
- self->flags &=
- ~(HYTHREAD_FLAG_INTERRUPTED | HYTHREAD_FLAG_SLEEPING |
- HYTHREAD_FLAG_INTERRUPTABLE | HYTHREAD_FLAG_TIMER_SET);
- THREAD_UNLOCK (self, self);
- return HYTHREAD_INTERRUPTED;
- }
- if (self->flags & HYTHREAD_FLAG_PRIORITY_INTERRUPTED)
- {
- self->flags &=
- ~(HYTHREAD_FLAG_PRIORITY_INTERRUPTED | HYTHREAD_FLAG_SLEEPING |
- HYTHREAD_FLAG_INTERRUPTABLE | HYTHREAD_FLAG_TIMER_SET);
- THREAD_UNLOCK (self, self);
- return HYTHREAD_PRIORITY_INTERRUPTED;
- }
- }
- COND_WAIT_TIMED_LOOP ();
-
- self->flags &=
- ~(HYTHREAD_FLAG_SLEEPING | HYTHREAD_FLAG_INTERRUPTABLE |
- HYTHREAD_FLAG_TIMER_SET);
- THREAD_UNLOCK (self, self);
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_sleep
-/**
- * Suspend the current thread from executing
- * for at least the specified time.
- *
- * @param[in] millis minimum number of milliseconds to sleep
- * @return 0 on success
HYTHREAD_INVALID_ARGUMENT if millis < 0
- *
- * @see hythread_sleep_interruptable
- */
-IDATA VMCALL
-hythread_sleep (I_64 millis)
-{
- hythread_t self = MACRO_SELF ();
-
- IDATA boundedMillis = (millis > 0x7FFFFFFF ? 0x7FFFFFFF : (IDATA) millis);
-
- ASSERT (self);
-
- if (millis < 0)
- {
- return HYTHREAD_INVALID_ARGUMENT;
- }
-
- THREAD_LOCK (self, self, CALLER_SLEEP);
-
- self->flags |= HYTHREAD_FLAG_SLEEPING | HYTHREAD_FLAG_TIMER_SET;
-
- COND_WAIT_IF_TIMEDOUT (self->condition, self->mutex, boundedMillis, 0)
- {
- break;
- }
- COND_WAIT_TIMED_LOOP ();
-
- self->flags &= ~(HYTHREAD_FLAG_SLEEPING | HYTHREAD_FLAG_TIMER_SET);
- THREAD_UNLOCK (self, self);
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_lock
-/*
- * Acquire the threading library's global lock.
- *
- * @param[in] self hythread_t for the current thread
- * @param[in] monitor must be NULL
- * @return none
- *
- * @deprecated This has been replaced by hythread_lib_lock.
- * @see hythread_lib_lock, hythread_lib_unlock
- */
-void VMCALL
-hythread_monitor_lock (hythread_t self, hythread_monitor_t monitor)
-{
- ASSERT (self);
-
- if (monitor == NULL)
- {
- GLOBAL_LOCK (self, CALLER_GLOBAL_LOCK);
- }
- else
- {
- ASSERT (0);
- }
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_unlock
-/*
- * Release the threading library's global lock.
- *
- * @param[in] self hythread_t for the current thread
- * @param[in] monitor
- * @return none
- *
- * @deprecated This has been replaced by hythread_lib_unlock.
- * @see hythread_lib_lock, hythread_lib_unlock
- */
-void VMCALL
-hythread_monitor_unlock (hythread_t self, hythread_monitor_t monitor)
-{
- ASSERT (self);
-
- if (monitor == NULL)
- {
- GLOBAL_UNLOCK (self);
- }
- else
- {
- ASSERT (0);
- }
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_acquire
-/*
- * Acquire a monitor from the threading library. (Private)
- *
- * @param[in] self current thread
- * @param[in] locking policy
- * @param[in] locking policy data or HYTHREAD_LOCKING_NO_DATA
- * @return NULL on failure, non-NULL on success
- *
- * @see hythread_monitor_init_with_name, hythread_monitor_destroy
- *
- *
- */
-static hythread_monitor_t VMCALL
-hythread_monitor_acquire (hythread_t self, IDATA policy, IDATA policyData)
-{
- hythread_monitor_t entry;
- hythread_monitor_pool_t pool = self->library->monitor_pool;
- IDATA rc;
-
- ASSERT (self);
- ASSERT (pool);
-
- GLOBAL_LOCK (self, CALLER_MONITOR_ACQUIRE);
-
- entry = pool->next_free;
- if (entry == NULL)
- {
- hythread_monitor_pool_t last_pool = pool;
- while (last_pool->next != NULL)
- last_pool = last_pool->next;
- last_pool->next = allocate_monitor_pool ();
- if (last_pool->next == NULL)
- {
- /* failed to grow monitor pool */
- GLOBAL_UNLOCK (self);
- return NULL;
- }
- entry = last_pool->next->next_free;
- }
-
- /* the first time that a mutex is acquired from the pool, we need to
- * initialize its mutex
- */
- if (entry->flags == HYTHREAD_MONITOR_MUTEX_UNINITIALIZED)
- {
-
- rc = MUTEX_INIT (entry->mutex);
-
- if (!rc)
- {
- /* failed to initialize mutex */
- ASSERT_DEBUG (0);
- GLOBAL_UNLOCK (self);
- return NULL;
- }
-
- entry->flags = 0;
-
- }
-
- pool->next_free = (hythread_monitor_t) entry->owner;
- entry->count = 0;
-
- GLOBAL_UNLOCK (self);
-
- return entry;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_cancel
-/**
- * Terminate a running thread.
- *
- * @note This should only be used as a last resort. The system may be in
- * an unpredictable state once a thread is cancelled. In addition, the thread
- * may not even stop running if it refuses to cancel.
- *
- * @param[in] thread a thread to be terminated
- * @return none
- */
-void VMCALL
-hythread_cancel (hythread_t thread)
-{
- hythread_monitor_t monitor = NULL;
- hythread_t self = MACRO_SELF ();
-
- ASSERT (thread);
- THREAD_LOCK (self, thread, CALLER_CANCEL);
-
- /* Special case -- we can cancel cleanly if the thread hasn't started yet */
- if ((thread->flags & HYTHREAD_FLAG_STARTED) == 0)
- {
- thread->flags |= HYTHREAD_FLAG_CANCELED;
- THREAD_UNLOCK (self, thread);
- hythread_resume (thread);
- return;
- }
-
- THREAD_CANCEL (thread->handle);
-
- thread->flags |= HYTHREAD_FLAG_CANCELED;
-
- THREAD_UNLOCK (self, thread);
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_detach
-/**
- * Detach a thread from the threading library.
- *
- * @note Assumes that the thread being detached is already attached.
- *
- * If the thread is an attached thread, then detach should only be called by the thread
- * itself. Internal resources associated with the thread are freed.
- *
- * If the thread is already dead, this call will destroy it.
- *
- * @param[in] thread a hythread_t representing the thread to be detached.
- * If this is NULL, the current thread is detached.
- * @return none
- *
- * @see hythread_attach
- */
-void VMCALL
-hythread_detach (hythread_t thread)
-{
- UDATA destroy = 0;
- UDATA attached = 0;
- hythread_t self = MACRO_SELF ();
-
- if (thread == NULL)
- {
- thread = self;
- }
- ASSERT (thread);
-
- THREAD_LOCK (self, thread, CALLER_DETACH);
- if (thread->attachcount < 1)
- {
- /* error! */
- }
- else
- {
- if (--thread->attachcount == 0)
- {
- if (thread->flags & HYTHREAD_FLAG_ATTACHED)
- {
- /* this is an attached thread, and it is now fully
- detached. Mark it dead so that it can be destroyed */
- thread->flags |= HYTHREAD_FLAG_DEAD;
- attached = destroy = 1;
- }
- else
- {
- destroy = thread->flags & HYTHREAD_FLAG_DEAD;
- }
- }
- }
- THREAD_UNLOCK (self, thread);
-
- if (destroy)
- {
- hythread_library_t library = thread->library;
-
- tls_finalize (thread);
-
- destroy_thread (thread, GLOBAL_NOT_LOCKED);
- if (attached)
- {
- TLS_SET (library->self_ptr, NULL);
- }
- }
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_exit
-/**
- * Exit the current thread.
- *
- * If the thread has been detached, it is destroyed.
- *
- * If monitor is not NULL, the monitor will be exited before the thread terminates.
- * This is useful if the thread wishes to signal its termination to a watcher, since
- * it exits the monitor and terminates the thread without ever returning control
- * to the thread's routine, which might be running in a DLL which is about to
- * be closed.
- *
- * @param[in] monitor monitor to be exited before exiting (ignored if NULL)
- * @return none
- */
-void VMCALL NORETURN
-hythread_exit (hythread_monitor_t monitor)
-{
- hythread_t self = MACRO_SELF ();
-
- if (monitor)
- {
- hythread_monitor_exit (monitor);
- }
-
- /* Walk all monitors: if this thread owns a monitor, exit it */
- monitor = NULL;
- while ((monitor = hythread_monitor_walk (monitor)) != NULL)
- {
- if (monitor->owner == self)
- {
- monitor->count = 1; /* exit n-1 times */
- hythread_monitor_exit (monitor);
- }
- }
-
-#if defined(LINUX)
- /* NPTL calls __pthread_unwind() from pthread_exit(). That walks the stack.
- * We can't allow that to happen, since our caller might have already been
- * unloaded. Walking the calling frame could cause a crash. Instead, we
- * longjmp back out to the initial frame.
- */
- if (self->jumpBuffer)
- {
- longjmp (*(jmp_buf *) self->jumpBuffer, 1);
- }
-#endif
-
- internal_exit ();
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_priority_interrupt
-/**
- * Priority interrupt a thread.
- *
- * If the thread is currently blocked (i.e. waiting on a monitor_wait or sleeping)
- * resume the thread and return from the blocking function with
- * HYTHREAD_PRIORITY_INTERRUPTED
- *
- * @param[in] thread a thead to be priority interrupted
- * @return none
- */
-void VMCALL
-hythread_priority_interrupt (hythread_t thread)
-{
- interrupt_thread (thread, HYTHREAD_FLAG_PRIORITY_INTERRUPTED);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_priority_interrupted
-/**
- * Return the value of a thread's priority interrupted flag.
- *
- * @param[in] thread thread to be queried
- * @return 0 if not priority interrupted, non-zero if priority interrupted flag set
- */
-UDATA VMCALL
-hythread_priority_interrupted (hythread_t thread)
-{
- return (thread->flags & HYTHREAD_FLAG_PRIORITY_INTERRUPTED) != 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_clear_priority_interrupted
-/**
- * Clear the priority interrupted flag of the current thread and return its previous value.
- *
- * @return previous value of priority interrupted flag: nonzero if the thread had been priority interrupted.
- */
-UDATA VMCALL
-hythread_clear_priority_interrupted (void)
-{
- UDATA oldFlags;
- hythread_t self = MACRO_SELF ();
- ASSERT (self);
-
- THREAD_LOCK (self, self, CALLER_CLEAR_PRIORITY_INTERRUPTED);
- oldFlags = self->flags;
- self->flags = oldFlags & ~HYTHREAD_FLAG_PRIORITY_INTERRUPTED;
- THREAD_UNLOCK (self, self);
-
- return (oldFlags & HYTHREAD_FLAG_PRIORITY_INTERRUPTED) != 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_try_enter
-/**
- * Attempt to enter a monitor without blocking.
- *
- * If the thread must block before it enters the monitor this function
- * returns immediately with a negative value to indicate failure.
- *
- * @param[in] monitor a monitor
- * @return 0 on success or negative value on failure
- *
- * @see hythread_monitor_try_enter_using_threadId
- *
- */
-IDATA VMCALL
-hythread_monitor_try_enter (hythread_monitor_t monitor)
-{
- return hythread_monitor_try_enter_using_threadId (monitor, MACRO_SELF ());
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_shutdown
-/**
- * Shut down the Hy threading library associated with the current thread.
- *
- * @return none
- *
- * @see hythread_init
- */
-void VMCALL
-hythread_shutdown (void)
-{
- hythread_library_t lib = GLOBAL_DATA (default_library);
- ASSERT (lib);
- MUTEX_DESTROY (lib->tls_mutex);
- MUTEX_DESTROY (lib->monitor_mutex);
- MUTEX_DESTROY (lib->global_mutex);
- pool_kill (lib->global_pool);
- free_monitor_pools ();
-#if !defined(LINUX)
- TLS_DESTROY (lib->self_ptr);
- pool_kill (lib->thread_pool);
-#endif /* LINUX */
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION allocate_thread
-/*
- * Allocate a hythread_t from the hythread_t pool.
- *
- * @note assumes the threading library's thread pool is already initialized
- * @param[in] globalIsLocked indicates whether the threading library global mutex is already locked.
- * @return a new hythread_t on success, NULL on failure.
- *
- */
-static hythread_t
-allocate_thread (int globalIsLocked)
-{
- hythread_t result;
- hythread_library_t lib = GLOBAL_DATA (default_library);
- ASSERT (lib);
-
- if (!globalIsLocked)
- {
- GLOBAL_LOCK_SIMPLE (lib);
- }
- lib->threadCount++;
- result = pool_newElement (lib->thread_pool);
- if (!globalIsLocked)
- {
- GLOBAL_UNLOCK_SIMPLE (lib);
- }
-
- if (result)
- {
- memset (result, 0, sizeof (HyThread));
- }
-
- return result;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION free_thread
-/*
- * Return a hythread_t to the threading library's monitor pool.
- *
- * @param[in] thread thread to be returned to the pool
- * @param[in] globalAlreadyLocked indicated whether the threading library global
- * mutex is already locked
- * @return none
- */
-static void
-free_thread (hythread_t thread, int globalAlreadyLocked)
-{
- hythread_library_t lib = thread->library;
-
- ASSERT (thread);
-
- if (!globalAlreadyLocked)
- {
- GLOBAL_LOCK_SIMPLE (lib);
- }
- pool_removeElement (lib->thread_pool, thread);
- lib->threadCount--;
-
- if (!globalAlreadyLocked)
- {
- GLOBAL_UNLOCK_SIMPLE (lib);
- }
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION thread_malloc
-/*
- * Malloc a thread (hythread_t struct).
- *
- * Helper function used by the library's thread pool
- *
- * @param unused ignored
- * @param size size of struct to be alloc'd
- * @return pointer to the malloc'd memory
- * 0 on failure
- *
- */
-static void *VMCALL
-thread_malloc (void *unused, U_32 size)
-{
- return malloc (size);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION thread_free
-/*
- * Free a thread (hythread_t struct)
- * Function used by the library's thread pool
- *
- * @param unused ignored
- * @param prt pointer to hythread_t to be freed
- * @return none
- *
- */
-static void VMCALL
-thread_free (void *unused, void *ptr)
-{
- free (ptr);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION free_monitor_pools
-/*
- * Free the Hy threading library's monitor pool.
- *
- * This requires destroying each and every one of the
- * monitors in the pool.
- *
- * @return none
- */
-static void
-free_monitor_pools (void)
-{
- hythread_library_t lib = GLOBAL_DATA (default_library);
- hythread_monitor_pool_t pool = lib->monitor_pool;
-
- ASSERT (lib);
- ASSERT (pool);
-
- while (pool)
- {
- int i;
- hythread_monitor_pool_t next = pool->next;
- hythread_monitor_t entry = &pool->entries[0];
- for (i = 0; i < MONITOR_POOL_SIZE - 1; i++, entry++)
- {
- if (entry->flags != HYTHREAD_MONITOR_MUTEX_UNINITIALIZED)
- {
- MUTEX_DESTROY (entry->mutex);
- }
- }
- free (pool);
- pool = next;
- }
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION init_global_monitor
-/*
- * Initialize the mutex used to synchronize access
- * to thread library global data.
- *
- * @param[in] lib pointer to the thread library
- * @return 0 on success or negative value on failure
- *
- */
-static IDATA
-init_global_monitor (hythread_library_t lib)
-{
- hythread_monitor_pool_t pool = lib->monitor_pool;
- hythread_monitor_t monitor = pool->next_free;
- ASSERT (monitor);
- pool->next_free = (hythread_monitor_t) monitor->owner;
-
- if (init_monitor (monitor, 0) != 0)
- {
- return -1;
- }
- if (!MUTEX_INIT (monitor->mutex))
- {
- return -1;
- }
-
- monitor->name = "Thread global";
-
- *hythread_global ("global_monitor") = (UDATA) monitor;
-
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION internal_exit
-/*
- * Exit from the current thread.
- *
- * If the thread has been detached it is destroyed.
- */
-static void NORETURN
-internal_exit (void)
-{
-
- hythread_t self = MACRO_SELF ();
- hythread_library_t lib = self->library;
- int detached;
-
- ASSERT (self);
- ASSERT (lib);
-
- tls_finalize (self);
-
- GLOBAL_LOCK (self, CALLER_INTERNAL_EXIT1);
- THREAD_LOCK (self, self, CALLER_INTERNAL_EXIT1);
- self->flags |= HYTHREAD_FLAG_DEAD;
- detached = self->attachcount == 0;
-
- /*
- * Is there an interruptServer thread out there
- * trying to interrupt us? Its services are
- * no longer required.
- */
- if (self->interrupter)
- {
- THREAD_LOCK (self, self->interrupter, CALLER_INTERNAL_EXIT1);
- self->interrupter->flags |= HYTHREAD_FLAG_CANCELED;
- THREAD_UNLOCK (self, self->interrupter);
- self->interrupter = NULL;
- }
-
- THREAD_UNLOCK (self, self);
-
- /* On z/OS we create the thread in the detached state, so the */
- /* call to pthread_detach is not required. @dfa1 */
- THREAD_DETACH (self->handle);
-
- if (detached)
- {
- destroy_thread (self, GLOBAL_IS_LOCKED);
- }
-
- GLOBAL_UNLOCK_SIMPLE (lib);
- THREAD_EXIT ();
- ASSERT (0);
- /* UNREACHABLE */
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION enqueue_thread
-/*
- * Add a thread to a monitor's wait queue.
- *
- * @note The calling thread must be the current owner of the monitor
- * @param[in] queue head of the monitor's wait queue
- * @param[in] thread thread to be added
- * @return none
- *
- */
-static void
-enqueue_thread (hythread_t * queue, hythread_t thread)
-{
- hythread_t qthread = *queue;
-
- ASSERT (thread);
- /* can't be on two queues at the same time */
- ASSERT (NULL == thread->next);
-
- if (qthread != NULL)
- {
- while (qthread->next)
- {
- qthread = qthread->next;
- }
- qthread->next = thread;
- }
- else
- {
- *queue = thread;
- }
-
- ASSERT (*queue != NULL);
- ASSERT (NULL == thread->next);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_wait_timed
-/**
- * Wait on a monitor until notified or timed out.
- *
- * A timeout of 0 (0ms, 0ns) indicates wait indefinitely.
- *
- * @param[in] monitor a monitor to be waited on
- * @param[in] millis >=0
- * @param[in] nanos >=0
- *
- * @return 0 the monitor has been waited on, notified, and reobtained
- * HYTHREAD_INVALID_ARGUMENT millis or nanos is out of range (millis or nanos < 0, or nanos >= 1E6)
- * HYTHREAD_ILLEGAL_MONITOR_STATE the current thread does not own the monitor
- * HYTHREAD_TIMED_OUT the timeout expired
- *
- * @see hythread_monitor_wait, hythread_monitor_wait_interruptable, hythread_monitor_enter
- *
- */
-IDATA VMCALL
-hythread_monitor_wait_timed (hythread_monitor_t monitor, I_64 millis,
- IDATA nanos)
-{
- return monitor_wait (monitor, millis, nanos, WAIT_UNINTERRUPTABLE);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_dump_trace
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_dump_all
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_dump_trace
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_global
-/**
- * Fetch or create a 'named global'.
- *
- * Return a pointer to the data associated with a named global with the specified name.
- * A new named global is created if a named global with the specified name can't be found.
- *
- * @param[in] name name of named global to read/create
- * @return a pointer to a UDATA associated with name
- * 0 on failure.
- *
- */
-UDATA *VMCALL
-hythread_global (char *name)
-{
- HyThreadGlobal *global;
- hythread_library_t lib = GLOBAL_DATA (default_library);
-
- MUTEX_ENTER (lib->global_mutex);
-
- global = lib->globals;
-
- while (global)
- {
- if (strcmp (global->name, name) == 0)
- {
- MUTEX_EXIT (lib->global_mutex);
- return &global->data;
- }
- global = global->next;
- }
-
- /*
- * If we got here, we couldn't find it, therefore
- * we will create a new one
- */
-
- global = pool_newElement (lib->global_pool);
- if (global == NULL)
- {
- MUTEX_EXIT (lib->global_mutex);
- return NULL;
- }
-
- global->next = lib->globals;
- global->name = name;
- global->data = 0;
- lib->globals = global;
-
- MUTEX_EXIT (lib->global_mutex);
-
- return &global->data;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hysem_init
-/*
- * Initialize a semaphore.
- *
- * Acquire a semaphore from the threading library.
- *
- * @param[out] sp pointer to semaphore to be initialized
- * @param[in] initValue initial count value (>=0) for the semaphore
- * @return 0 on success or negative value on failure
- *
- * @deprecated Semaphores are no longer supported.
- *
- * @see hysem_destroy, hysem_init, hysem_post
- */
-IDATA VMCALL
-hysem_init (hysem_t * sp, I_32 initValue)
-{
- hysem_t s;
- IDATA rc = -1;
-
- (*sp) = s = SEM_CREATE (initValue);
- if (s)
- {
- rc = SEM_INIT (s, 0, initValue);
- }
- return rc;
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hysem_destroy
-/*
- * Destroy a semaphore.
- *
- * Returns the resources associated with a semaphore back to the Hy threading library.
- *
- * @param[in] s semaphore to be destroyed
- * @return 0 on success or negative value on failure
- *
- * @deprecated Semaphores are no longer supported.
- *
- * @see hysem_init, hysem_wait, hysem_post
- */
-IDATA VMCALL
-hysem_destroy (hysem_t s)
-{
- int rval = 0;
- if (s)
- {
- rval = SEM_DESTROY (s);
- SEM_FREE (s);
- }
- return rval;
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hysem_post
-/*
- * Release a semaphore by 1.
- *
- * @param[in] s semaphore to be released by 1
- * @return 0 on success or negative value on failure
- *
- * @deprecated Semaphores are no longer supported.
- *
- * @see hysem_init, hysem_destroy, hysem_wait
- */
-IDATA VMCALL
-hysem_post (hysem_t s)
-{
- if (s)
- {
- return SEM_POST (s);
- }
- return -1;
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hysem_wait
-/*
- * Wait on a semaphore.
- *
- * @param[in] s semaphore to be waited on
- * @return 0 on success or negative value on failure
- *
- * @deprecated Semaphores are no longer supported.
- *
- * @see hysem_init, hysem_destroy, hysem_wait
- *
- */
-IDATA VMCALL
-hysem_wait (hysem_t s)
-{
- if (s)
- {
- while (SEM_WAIT (s) != 0)
- {
- /* loop until success */
- }
- return 0;
- }
- else
- {
- return -1;
- }
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION error
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION monitor_enter
-/*
- * Enter a monitor.
- *
- * A thread may enter a monitor it owns multiple times, but must
- * exit the monitor the same number of times before other threads
- * waiting on the monitor are permitted to continue
- *
- * @param[in] self current thread
- * @param[in] monitor monitor to enter
- * @return 0 on success
- * HYTHREAD_PRIORITY_INTERRUPTED if the thread was priority
- * interrupted while blocked
- */
-static IDATA
-monitor_enter (hythread_t self, hythread_monitor_t monitor)
-{
-
- ASSERT (self);
- ASSERT (0 == self->monitor);
- ASSERT (monitor);
- ASSERT (monitor->owner != self);
- ASSERT (FREE_TAG != monitor->count);
-
- return monitor_enter_three_tier (self, monitor);
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION monitor_enter_three_tier
-
-/*
- * Enter a three-tier monitor.
- *
- * Spin on a spinlock. Block when that fails, and repeat.
- *
- * @param[in] self current thread
- * @param[in] monitor monitor to enter
- * @return 0 on success
- */
-
-static IDATA
-monitor_enter_three_tier (hythread_t self, hythread_monitor_t monitor)
-{
- int firstTimeBlocking = 1;
-
- while (1)
- {
-
- if (hythread_spinlock_acquire (self, monitor) == 0)
- {
- monitor->owner = self;
- monitor->count = 1;
- ASSERT (monitor->spinlockState !=
- HYTHREAD_MONITOR_SPINLOCK_UNOWNED);
- break;
- }
-
- MONITOR_LOCK (self, monitor, CALLER_MONITOR_ENTER_THREE_TIER1);
-
- if (HYTHREAD_MONITOR_SPINLOCK_UNOWNED ==
- hythread_spinlock_swapState (monitor,
- HYTHREAD_MONITOR_SPINLOCK_EXCEEDED))
- {
- MONITOR_UNLOCK (self, monitor);
- monitor->owner = self;
- monitor->count = 1;
- ASSERT (monitor->spinlockState !=
- HYTHREAD_MONITOR_SPINLOCK_UNOWNED);
- break;
- }
-
- THREAD_LOCK (self, self, CALLER_MONITOR_ENTER_THREE_TIER2);
- self->flags |= (HYTHREAD_FLAG_BLOCKED);
- self->monitor = monitor;
- THREAD_UNLOCK (self, self);
-
- /*
- * First time we've had to block?
- * If so, record the info for JLM.
- */
- if (IS_JLM_ENABLED (self))
- {
- if (firstTimeBlocking)
- {
- firstTimeBlocking = 0;
-
- }
- }
-
- enqueue_thread (&monitor->blocking, self);
- COND_WAIT (self->condition, monitor->mutex);
- break;
- COND_WAIT_LOOP ();
- remove_from_queue (&monitor->blocking, self);
-
- MONITOR_UNLOCK (self, monitor);
-
- }
-
- /* We now own the monitor */
-
- /*
- * If the monitor field is set, we must have blocked on it
- * at some point. We're no longer blocked, so clear this.
- */
- if (self->monitor != 0)
- {
- THREAD_LOCK (self, self, CALLER_MONITOR_ENTER_THREE_TIER3);
- self->flags &= ~(HYTHREAD_FLAG_BLOCKED);
- self->monitor = 0;
- THREAD_UNLOCK (self, self);
- }
-
- /* Did we block? If so, finish up the JLM calcs */
- /* TODO: this is pretty much the same as in monitor_enter.... */
- if (IS_JLM_ENABLED (self))
- {
- monitor->tracing->enter_count++;
- if (0 == firstTimeBlocking)
- {
- monitor->tracing->slow_count++;
-
- }
- }
-
- ASSERT (!(self->flags & HYTHREAD_FLAG_BLOCKED));
- ASSERT (0 == self->monitor);
-
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION monitor_exit
-/*
- * Exit a monitor.
- *
- * If the current thread is not the owner of the monitor, the
- * mutex is unaffected, and an error is returned. This should be
- * tested to determine if IllegalMonitorState should be
- * thrown.
- *
- * @param[in] self current thread
- * @param[in] monitor monitor to be exited
- * @return 0 on success
- * HYTHREAD_ILLEGAL_MONITOR_STATE if the current thread does not
- * own the monitor
- */
-static IDATA
-monitor_exit (hythread_t self, hythread_monitor_t monitor)
-{
-
- ASSERT (monitor);
- ASSERT (self);
- ASSERT (0 == self->monitor);
-
- if (monitor->owner != self)
- {
- ASSERT_DEBUG (0);
- return HYTHREAD_ILLEGAL_MONITOR_STATE;
- }
-
- monitor->count--;
- ASSERT (monitor->count >= 0);
-
- if (monitor->count == 0)
- {
- monitor->owner = NULL;
-
- if (HYTHREAD_MONITOR_SPINLOCK_EXCEEDED ==
- hythread_spinlock_swapState (monitor,
- HYTHREAD_MONITOR_SPINLOCK_UNOWNED))
- {
- MONITOR_LOCK (self, monitor, CALLER_MONITOR_EXIT1);
- unblock_spinlock_threads (self, monitor);
- MONITOR_UNLOCK (self, monitor);
- }
-
- }
-
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION unblock_spinlock_threads
-
-/*
- * Notify all threads blocked on the monitor's mutex, waiting
- * to be told that it's ok to try again to get the spinlock.
- *
- * Assumes that the caller already owns the monitor's mutex.
- *
- */
-static void
-unblock_spinlock_threads (hythread_t self, hythread_monitor_t monitor)
-{
- hythread_t queue, next;
-
- ASSERT (self);
- ASSERT (monitor);
-
- next = monitor->blocking;
- while (next)
- {
- queue = next;
- next = queue->next;
- COND_NOTIFY_ALL (queue->condition);
- }
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_reset_tracing
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_wait_interruptable
-/**
- * Wait on a monitor until notified, interrupted (priority or normal), or timed out.
- *
- * A timeout of 0 (0ms, 0ns) indicates wait indefinitely.
- *
- * If 'interruptable' is non-zero, the wait may be interrupted by one of the
- * interrupt functions. (i.e. hythread_interrupt, hythread_priority_interrupt);
- *
- * @param[in] monitor a monitor to be waited on
- * @param[in] millis >=0
- * @param[in] nanos >=0
- * @param[in] interruptable non-zero if the wait is to be interruptable
- *
- * @return 0 the monitor has been waited on, notified, and reobtained
- * HYTHREAD_INVALID_ARGUMENT if millis or nanos is out of range (millis or nanos < 0, or nanos >= 1E6)
- * HYTHREAD_ILLEGAL_MONITOR_STATE if the current thread does not own the monitor
- * HYTHREAD_INTERRUPTED if the thread was interrupted while waiting
- * HYTHREAD_PRIORITY_INTERRUPTED if the thread was priority interrupted while waiting, or while re-obtaining the monitor
- * HYTHREAD_TIMED_OUT if the timeout expired
- *
- * @see hythread_monitor_wait, hythread_monitor_wait_timed, hythread_monitor_enter
- * @see hythread_interrupt, hythread_priority_interrupt *
- */
-IDATA VMCALL
-hythread_monitor_wait_interruptable (hythread_monitor_t monitor, I_64 millis,
- IDATA nanos)
-{
- return monitor_wait (monitor, millis, nanos, WAIT_INTERRUPTABLE);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_num_waiting
-/**
- * Returns how many threads are currently waiting on a monitor.
- *
- * @note This can only be called by the owner of this monitor.
- *
- * @param[in] monitor a monitor
- * @return number of threads waiting on the monitor (>=0)
- */
-UDATA VMCALL
-hythread_monitor_num_waiting (hythread_monitor_t monitor)
-{
- UDATA numWaiting = 0;
- hythread_t curr;
- hythread_t self = MACRO_SELF ();
-
- ASSERT (monitor);
-
- MONITOR_LOCK (self, monitor, CALLER_MONITOR_NUM_WAITING);
-
- curr = monitor->waiting;
- while (curr != NULL)
- {
- numWaiting++;
- curr = curr->next;
- }
-
- MONITOR_UNLOCK (self, monitor);
-
- return numWaiting;
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION monitor_wait
-/*
- *
- * Wait on a monitor.
- *
- * Release the monitor, wait for a signal (notification), then re-acquire the monitor.
- *
- * In this function, we 'unwind' any recursive hold (monitor->count) the thread has
- * on the monitor and release the OS monitor. When the monitor is re-acquired,
- * the recursive count is restored to its original value.
- *
- * A timeout of 0 (0ms, 0ns) indicates wait indefinitely.
- *
- * If 'interruptable' is non-zero, the wait may be interrupted by one of the
- * interrupt functions. (i.e. hythread_interrupt, hythread_priority_interrupt);
- *
- * @param[in] monitor monitor to be waited on
- * @param[in] millis >=0
- * @param[in] nanos >=0
- * @param[in] interruptable non-zero if the wait is to be interruptable
- *
- * @return HYTHREAD_INVALID_ARGUMENT - if millis or nanos is out of range (millis or nanos < 0, or nanos >= 1E6)
- * HYTHREAD_ILLEGAL_MONITOR_STATE - the current thread does not own the monitor
- * 0 - the monitor has been waited on, notified, and reobtained
- * HYTHREAD_INTERRUPTED - the thread was interrupted while waiting
- * HYTHREAD_PRIORITY_INTERRUPTED - if the thread was priority interrupted while waiting, or while re-obtaining the monitor
- * HYTHREAD_TIMED_OUT - the timeout expired
- *
- * @see hythread_monitor_wait, hythread_monitor_wait_interruptable, hythread_monitor_enter
- * @see hythread_interrupt, hythread_priority_interrupt
- */
-static IDATA
-monitor_wait (hythread_monitor_t monitor, I_64 millis, IDATA nanos,
- IDATA interruptable)
-{
- hythread_t self = MACRO_SELF ();
- IDATA count = -1;
- UDATA flags;
- UDATA interrupted = 0, notified = 0, priorityinterrupted = 0;
- UDATA timedOut = 0;
-
- ASSERT (monitor);
- ASSERT (FREE_TAG != monitor->count);
-
- if (monitor->owner != self)
- {
- ASSERT_DEBUG (0);
- return HYTHREAD_ILLEGAL_MONITOR_STATE;
- }
-
- if ((millis < 0) || (nanos < 0) || (nanos >= 1000000))
- {
- ASSERT_DEBUG (0);
- return HYTHREAD_INVALID_ARGUMENT;
- }
-
- count = monitor->count;
- flags = monitor->flags;
-
- THREAD_LOCK (self, self, CALLER_MONITOR_WAIT1);
- ASSERT (0 == self->monitor);
-
- /*
- * Before we wait, check if we've already been either interrupted or pri interrupted
- */
- if (interruptable && (self->flags & HYTHREAD_FLAG_INTERRUPTED))
- {
- self->flags &= ~HYTHREAD_FLAG_INTERRUPTED;
- THREAD_UNLOCK (self, self);
- return HYTHREAD_INTERRUPTED;
- }
-
- if (interruptable && (self->flags & HYTHREAD_FLAG_PRIORITY_INTERRUPTED))
- {
- self->flags &= ~HYTHREAD_FLAG_PRIORITY_INTERRUPTED;
- THREAD_UNLOCK (self, self);
- return HYTHREAD_PRIORITY_INTERRUPTED;
- }
-
- self->flags |=
- (HYTHREAD_FLAG_WAITING |
- (interruptable ? HYTHREAD_FLAG_INTERRUPTABLE : 0));
- if (millis || nanos)
- {
- self->flags |= HYTHREAD_FLAG_TIMER_SET;
- }
- self->monitor = monitor;
- THREAD_UNLOCK (self, self);
-
- ASSERT (self->flags & HYTHREAD_FLAG_WAITING);
- monitor->owner = NULL;
- monitor->count = 0;
-
- MONITOR_LOCK (self, monitor, CALLER_MONITOR_WAIT);
- if (HYTHREAD_MONITOR_SPINLOCK_EXCEEDED ==
- hythread_spinlock_swapState (monitor,
- HYTHREAD_MONITOR_SPINLOCK_UNOWNED))
- {
- unblock_spinlock_threads (self, monitor);
- }
-
- enqueue_thread (&monitor->waiting, self);
-
- if (millis || nanos)
- {
- IDATA boundedMillis = BOUNDED_I64_TO_IDATA (millis);
-
- COND_WAIT_IF_TIMEDOUT (self->condition, monitor->mutex, boundedMillis,
- nanos)
- {
-
- THREAD_LOCK (self, self, CALLER_MONITOR_WAIT2);
- interrupted = interruptable
- && ((self->flags & HYTHREAD_FLAG_INTERRUPTED) != 0);
- priorityinterrupted = interruptable
- && ((self->flags & HYTHREAD_FLAG_PRIORITY_INTERRUPTED) != 0);
- notified = self->flags & HYTHREAD_FLAG_NOTIFIED;
- if (!(interrupted || priorityinterrupted || notified))
- {
- timedOut = 1;
- }
- break;
- }
- else
- {
-
- THREAD_LOCK (self, self, CALLER_MONITOR_WAIT2);
- interrupted = interruptable
- && ((self->flags & HYTHREAD_FLAG_INTERRUPTED) != 0);
- priorityinterrupted = interruptable
- && ((self->flags & HYTHREAD_FLAG_PRIORITY_INTERRUPTED) != 0);
- notified = self->flags & HYTHREAD_FLAG_NOTIFIED;
- if (interrupted || priorityinterrupted || notified)
- {
- break;
- }
- /* must have been spurious */
- ASSERT_DEBUG (0);
- THREAD_UNLOCK (self, self);
- }
- COND_WAIT_TIMED_LOOP ();
- }
- else
- {
- /*
- * WAIT UNTIL NOTIFIED
- */
-
- COND_WAIT (self->condition, monitor->mutex);
-
- THREAD_LOCK (self, self, CALLER_MONITOR_WAIT2);
- interrupted = interruptable
- && ((self->flags & HYTHREAD_FLAG_INTERRUPTED) != 0);
- priorityinterrupted = interruptable
- && ((self->flags & HYTHREAD_FLAG_PRIORITY_INTERRUPTED) != 0);
- notified = self->flags & HYTHREAD_FLAG_NOTIFIED;
- if (interrupted || priorityinterrupted || notified)
- {
- break;
- }
- /* must have been spurious */
- ASSERT_DEBUG (0);
- THREAD_UNLOCK (self, self);
- COND_WAIT_LOOP ();
- }
-
- /* DONE WAITING AT THIS POINT */
-
- /* we have to remove self from the wait queue */
- remove_from_queue (&monitor->waiting, self);
-
- MONITOR_UNLOCK (self, monitor);
-
- /* at this point, this thread should already be locked */
- ASSERT (notified || interrupted || priorityinterrupted || timedOut);
- ASSERT (!interrupted || interruptable); /* if we were interrupted, then we'd better have been interruptable */
-
- self->flags &=
- ~(HYTHREAD_FLAG_WAITING | HYTHREAD_FLAG_NOTIFIED |
- HYTHREAD_FLAG_PRIORITY_INTERRUPTED | HYTHREAD_FLAG_INTERRUPTABLE |
- HYTHREAD_FLAG_TIMER_SET);
-
- if (interrupted && !(notified || priorityinterrupted))
- self->flags &= ~HYTHREAD_FLAG_INTERRUPTED;
-
- /*
- * Is there an interruptServer thread out there
- * trying to interrupt us? Its services are
- * no longer required.
- */
- if (self->interrupter)
- {
- ASSERT (interrupted || priorityinterrupted);
- THREAD_LOCK (self, self->interrupter, CALLER_MONITOR_WAIT2);
- self->interrupter->flags |= HYTHREAD_FLAG_CANCELED;
- THREAD_UNLOCK (self, self->interrupter);
- self->interrupter = NULL;
- }
-
- THREAD_UNLOCK (self, self);
-
- monitor_enter_three_tier (self, monitor);
-
- monitor->count = count;
-
- ASSERT (monitor->owner == self);
- ASSERT (monitor->count == count);
- ASSERT (monitor->count >= 1);
- ASSERT (0 == self->monitor);
- ASSERT (!(monitor->flags & HYTHREAD_FLAG_WAITING));
- ASSERT (!(monitor->flags & HYTHREAD_FLAG_TIMER_SET));
- ASSERT (!(monitor->flags & HYTHREAD_FLAG_BLOCKED));
- ASSERT (!(monitor->flags & HYTHREAD_FLAG_NOTIFIED));
- ASSERT (!(monitor->flags & HYTHREAD_FLAG_INTERRUPTABLE));
- ASSERT (NULL == self->next);
-
- if (priorityinterrupted)
- return HYTHREAD_PRIORITY_INTERRUPTED;
- if (notified)
- return 0;
- if (interrupted)
- return HYTHREAD_INTERRUPTED;
- if (timedOut)
- return HYTHREAD_TIMED_OUT;
- ASSERT (0);
- return 0;
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION interrupt_thread
-/*
- * Interrupt a thread.
- *
- * If the thread is currently blocked (e.g. waiting on monitor_wait)
- * resume the thread and return from the blocking function with
- * HYTHREAD_INTERRUPTED or HYTHREAD_PRIORITY_INTERRUPTED
- *
- * If it can't be resumed (it's not in an interruptable state)
- * then just set the appropriate interrupt flag.
- *
- * @param[in] thread thread to be interrupted
- * @param[in] interruptFlag indicated whether to priority interrupt or just normally interrupt.
- * @return none
- */
-static void
-interrupt_thread (hythread_t thread, UDATA interruptFlag)
-{
- UDATA currFlags, newFlags;
- hythread_t self = MACRO_SELF ();
-
- ASSERT (self);
- ASSERT (thread);
-
- GLOBAL_LOCK (self, CALLER_INTERRUPT_THREAD);
- THREAD_LOCK (self, thread, CALLER_INTERRUPT_THREAD);
- if (thread->flags & interruptFlag)
- {
- THREAD_UNLOCK (self, thread);
- GLOBAL_UNLOCK (self);
- return;
- }
-
- currFlags = thread->flags;
- newFlags = currFlags | interruptFlag;
- if (currFlags & HYTHREAD_FLAG_INTERRUPTABLE)
- {
- if (currFlags & (HYTHREAD_FLAG_SLEEPING | HYTHREAD_FLAG_PARKED))
- {
- COND_NOTIFY_ALL (thread->condition);
- }
- else if (currFlags & HYTHREAD_FLAG_WAITING)
- {
- if (interrupt_waiting_thread (self, thread))
- {
- newFlags |= HYTHREAD_FLAG_BLOCKED;
- }
- }
- }
-
- thread->flags = newFlags;
- THREAD_UNLOCK (self, thread);
- GLOBAL_UNLOCK (self);
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION interrupt_waiting_thread
-/*
- * Interrupt a waiting thread.
- *
- * @param[in] self current thread
- * @param[in] threadToInterrupt
- * @return 1 if the thread was immediately interrupted
- * 0 if the thread will be interrupted asap by a special thread.
- * @note: Assumes caller has locked the global mutex
- */
-static IDATA
-interrupt_waiting_thread (hythread_t self, hythread_t threadToInterrupt)
-{
-
- IDATA retVal = 0;
- hythread_monitor_t monitor;
-
- ASSERT (self);
- ASSERT (threadToInterrupt);
- ASSERT (self != threadToInterrupt);
- ASSERT (threadToInterrupt->flags & HYTHREAD_FLAG_INTERRUPTABLE);
- ASSERT (threadToInterrupt->monitor);
- ASSERT (NULL == threadToInterrupt->interrupter);
-
-#if !defined(ALWAYS_SPAWN_THREAD_TO_INTERRUPT)
- /*
- * If we can enter the monitor without blocking, we don't need the
- * interruptServer thread
- */
- monitor = threadToInterrupt->monitor;
- if (hythread_monitor_try_enter_using_threadId (monitor, self) == 0)
- {
- ASSERT (monitor->owner == self);
- COND_NOTIFY_ALL (threadToInterrupt->condition);
- hythread_monitor_exit_using_threadId (monitor, self);
- retVal = 1;
- }
- else
-#endif
-
- {
- /*
- * spawn a thread to do it for us, because it's possible that
- * having this thread lock the waiting thread's monitor may
- * cause deadlock
- */
- create_thread (&threadToInterrupt->interrupter, 0,
- HYTHREAD_PRIORITY_NORMAL, 0, interruptServer,
- (void *) threadToInterrupt, GLOBAL_IS_LOCKED);
- }
- return retVal;
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION interruptServer
-/*
- * Interrupt a thread waiting on a monitor.
- *
- * This function serves as the entry point for a
- * thread whose sole purpose is to interrupt another
- * thread.
- *
- * @param[in] entryArg pointer to the thread to interrupt (non-NULL)
- * @return 0
- */
-static I_32 HYTHREAD_PROC
-interruptServer (void *entryArg)
-{
- hythread_t self = MACRO_SELF ();
- hythread_t threadToInterrupt = (hythread_t) entryArg;
- hythread_monitor_t monitor;
-
- ASSERT (threadToInterrupt);
- ASSERT (self);
-
- GLOBAL_LOCK (self, CALLER_INTERRUPT_SERVER);
-
- /*
- * Did the thread to interrupt die or come out of wait already?
- * If it did, it cancelled this thread (set our CANCELED bit)
- */
- if (self->flags & HYTHREAD_FLAG_CANCELED)
- {
- GLOBAL_UNLOCK (self);
- hythread_exit (NULL); /* this should not return */
- }
-
- THREAD_LOCK (self, threadToInterrupt, CALLER_INTERRUPT_SERVER);
-
- if (threadToInterrupt->interrupter != self)
- {
- THREAD_UNLOCK (self, threadToInterrupt);
- GLOBAL_UNLOCK (self);
- hythread_exit (NULL); /* this should not return */
- }
-
- monitor = threadToInterrupt->monitor;
- ASSERT (monitor);
- ASSERT (threadToInterrupt->flags & HYTHREAD_FLAG_WAITING);
-
- hythread_monitor_pin (monitor, self);
- THREAD_UNLOCK (self, threadToInterrupt);
- GLOBAL_UNLOCK (self);
-
- /* try to take the monitor so that we can notify the thread to interrupt */
- hythread_monitor_enter (monitor);
-
- GLOBAL_LOCK (self, CALLER_INTERRUPT_SERVER);
- hythread_monitor_unpin (monitor, self);
-
- /* Did the thread to interrupt die or come out of wait already? */
- if (self->flags & HYTHREAD_FLAG_CANCELED)
- {
- GLOBAL_UNLOCK (self);
- hythread_exit (monitor); /* this should not return */
- ASSERT (0);
- }
-
- THREAD_LOCK (self, threadToInterrupt, CALLER_INTERRUPT_SERVER);
- if ((threadToInterrupt->interrupter == self)
- && (threadToInterrupt->flags & HYTHREAD_FLAG_WAITING))
- {
- notify_thread (threadToInterrupt, DONT_SET_NOTIFIED_FLAG);
- }
- threadToInterrupt->interrupter = NULL;
- ASSERT (threadToInterrupt->flags & HYTHREAD_FLAG_INTERRUPTED);
- THREAD_UNLOCK (self, threadToInterrupt);
-
- GLOBAL_UNLOCK (self);
- hythread_exit (monitor);
-
- ASSERT (0);
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_exit_using_threadId
-/**
- * Exit a monitor.
- *
- * This is a slightly faster version of hythread_monitor_exit because
- * the hythread_t for the current thread doesn't have to be looked up
- *
- * @param[in] monitor a monitor to be exited
- * @param[in] threadId hythread_t for the current thread
- * @return 0 on success
- * HYTHREAD_ILLEGAL_MONITOR_STATE if the current thread does not own the monitor
- *
- * @see hythread_monitor_exit, hythread_monitor_enter, hythread_monitor_enter_using_threadId
- */
-IDATA VMCALL
-hythread_monitor_exit_using_threadId (hythread_monitor_t monitor,
- hythread_t threadId)
-{
- ASSERT (threadId == MACRO_SELF ());
- ASSERT (monitor);
- ASSERT (FREE_TAG != monitor->count);
-
- if (monitor->owner != threadId)
- {
- ASSERT_DEBUG (0);
- return HYTHREAD_ILLEGAL_MONITOR_STATE;
- }
-
- return monitor_exit (threadId, monitor);
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_enter_using_threadId
-/**
- * Enter a monitor.
- *
- * This is a slightly faster version of hythread_monitor_enter because
- * the hythread_t for the current thread doesn't have to be looked up
- *
- * @param[in] monitor a monitor to be entered
- * @param[in] threadId hythread_t for the current thread
- * @return 0 on success
- * HYTHREAD_PRIORITY_INTERRUPTED if the thread was priority interrupted while blocked
- *
- * @see hythread_monitor_enter, hythread_monitor_exit, hythread_monitor_exit_using_threadId
- *
- */
-IDATA VMCALL
-hythread_monitor_enter_using_threadId (hythread_monitor_t monitor,
- hythread_t threadId)
-{
- ASSERT (threadId != 0);
- ASSERT (threadId == MACRO_SELF ());
- ASSERT (monitor);
- ASSERT (FREE_TAG != monitor->count);
-
- if (monitor->owner == threadId)
- {
- ASSERT (monitor->count >= 1);
- monitor->count++;
-
- if (IS_JLM_ENABLED (threadId))
- {
- ASSERT (monitor->tracing);
- monitor->tracing->recursive_count++;
- monitor->tracing->enter_count++;
- } /* if (IS_JLM_ENABLED(threadId)) */
-
- return 0;
- }
- return monitor_enter (threadId, monitor);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_try_enter_using_threadId
-/**
- * Attempt to enter a monitor without blocking.
- *
- * If the thread must block before it enters the monitor this function
- * returns immediately with a negative value to indicate failure.
- *
- * This is a slightly faster version of hythread_monitor_try_enter because
- * the current thread's hythread_t doesn't have to be looked up.
- *
- * @param[in] monitor a monitor
- * @param[in] threadId the current thread
- * @return 0 on success or negative value on failure
- *
- * @see hythread_monitor_try_enter
- *
- */
-IDATA VMCALL
-hythread_monitor_try_enter_using_threadId (hythread_monitor_t monitor,
- hythread_t threadId)
-{
-
- ASSERT (threadId != 0);
- ASSERT (threadId == MACRO_SELF ());
- ASSERT (FREE_TAG != monitor->count);
-
- /* Are we already the owner? */
- if (monitor->owner == threadId)
- {
- ASSERT (monitor->count >= 1);
- monitor->count++;
-
- if (IS_JLM_ENABLED (threadId))
- {
- monitor->tracing->recursive_count++;
- monitor->tracing->enter_count++;
- } /* if (IS_JLM_ENABLED(threadId)) */
-
- return 0;
- }
-
- if (hythread_spinlock_acquire (threadId, monitor) == 0)
-
- {
- ASSERT (NULL == monitor->owner);
- ASSERT (0 == monitor->count);
-
- monitor->owner = threadId;
- monitor->count = 1;
-
- if (IS_JLM_ENABLED (threadId))
- {
- monitor->tracing->enter_count++;
-
- } /* if (IS_JLM_ENABLED(threadId)) */
-
- return 0;
- }
-
- return -1;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_probe
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION destroy_thread
-/*
- * Destroy the resources associated with the thread.
- *
- * If the thread is not already dead, the function fails.
- *
- * @param[in] thread thread to be destroyed
- * @param[in] globalAlreadyLocked indicated whether the thread library global mutex is already locked
- * @return 0 on success or negative value on failure.
- */
-static IDATA
-destroy_thread (hythread_t thread, int globalAlreadyLocked)
-{
-
- hythread_t self = MACRO_SELF ();
- hythread_library_t lib = self->library;
-
- ASSERT (thread);
- ASSERT (lib);
-
- THREAD_LOCK (self, thread, CALLER_DESTROY);
- if ((thread->flags & HYTHREAD_FLAG_DEAD) == 0)
- {
- THREAD_UNLOCK (self, thread);
- return -1;
- }
- THREAD_UNLOCK (self, thread);
-
- COND_DESTROY (thread->condition);
-
- MUTEX_DESTROY (thread->mutex);
-
-#if defined(WIN32)
- if (thread->flags & HYTHREAD_FLAG_ATTACHED)
- {
- CloseHandle (thread->handle);
- }
-#endif
-
- free_thread (thread, globalAlreadyLocked);
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_jlm_thread_init
-
-/*
- * Initialize and clear a thread's JLM tracing information.
- *
- * Tracing information for the thread is allocated if not already allocated
- * The library's thread tracing pool is initialized if not already initialized.
- *
- * @param[in] thread thread to be initialized
- * @return none
- *
- */
-void VMCALL
-hythread_jlm_thread_init (hythread_t thread)
-{
- hythread_library_t library = thread->library;
-
- ASSERT (thread);
- ASSERT (library);
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_jlm_thread_clear
-
-/*
- * Clear (reset) a thread's JLM tracing structure.
- *
- * Assumes the thread's tracing structure has already been allocated.
- *
- * @param[in] thread thread to be initialized (non-NULL)
- * @return none
- *
- */
-void VMCALL
-hythread_jlm_thread_clear (hythread_t thread)
-{
- ASSERT (thread);
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_jlm_monitor_init
-
-/*
- * Initialize and clear a monitor's JLM tracing information.
- *
- * Tracing information for the monitor is allocated if not already allocated
- * The library's monitor tracing pool is initialized if not already initialized.
- *
- * @param[in] monitor monitor to be initialized
- * @return none
- *
- */
-void VMCALL
-hythread_jlm_monitor_init (hythread_monitor_t monitor)
-{
- hythread_t self = MACRO_SELF ();
- hythread_library_t library;
- ASSERT (self);
- ASSERT (monitor);
- library = self->library;
- ASSERT (library);
-
- if (library->monitor_tracing_pool == NULL)
- {
- library->monitor_tracing_pool =
- pool_new (sizeof (HyThreadMonitorTracing), 0, 0, 0, thread_malloc,
- thread_free, NULL);
- }
-
- if (monitor->tracing == NULL)
- {
- /* cannot have been set, so set it now */
- monitor->tracing = pool_newElement (library->monitor_tracing_pool);
- }
-
- hythread_jlm_monitor_clear (monitor);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_jlm_monitor_clear
-
-/*
- * Clear (reset) a monitor's JLM tracing structure.
- *
- * Assumes the monitor's tracing structure has already been allocated.
- *
- * @param[in] monitor a monitor to be initialized
- * @return none
- */
-void VMCALL
-hythread_jlm_monitor_clear (hythread_monitor_t monitor)
-{
- ASSERT (monitor);
- ASSERT (monitor->tracing);
- memset (monitor->tracing, 0, sizeof (*monitor->tracing));
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION init_monitor
-/*
- * Re-initialize the 'simple' fields of a monitor
- * that has been initialized previously, but is now
- * being re-used.
- *
- * @param[in] monitor monitor to be initialized
- * @return 0 on success or negative value on failure.
- * @see hythread_monitor_init_with_name
- *
- */
-static UDATA
-init_monitor (hythread_monitor_t monitor, UDATA flags)
-{
- ASSERT (monitor);
- monitor->count = 0;
- monitor->owner = NULL;
- monitor->waiting = NULL;
- monitor->flags = flags;
- monitor->userData = 0;
- monitor->name = 0;
- monitor->pinCount = 0;
-
- monitor->proDeflationCount = 0;
- monitor->antiDeflationCount = 0;
-
- monitor->blocking = NULL;
- monitor->spinlockState = HYTHREAD_MONITOR_SPINLOCK_UNOWNED;
- monitor->lockingWord = 0;
- /* these numbers are taken from the GC spinlock. They probably need to be tuned more (dynamically?) */
- /* note that every spinCount must be > 0! */
-
- monitor->spinCount1 = 256;
- monitor->spinCount2 = 32;
- monitor->spinCount3 = 45;
-
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION getCurrentCycles
-/*
- * Return the cycle count on the current processor.
- *
- * Units will be platform dependent.
- * @todo This will be implmented in builder
- */
-static hytime_t
-getCurrentCycles (void)
-{
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_lib_get_flags
-
-/**
- * Get threading library global flags.
- *
- * Returns the flags for the threading library associated with the current thread.
- *
- * @note: assumes caller has global lock
- *
- * @see hythread_lib_clear_flags, hythread_lib_set_flags, hythread_lib_lock
- * @return current flags value
- */
-UDATA VMCALL
-hythread_lib_get_flags ()
-{
- hythread_t self;
- self = MACRO_SELF ();
-
- ASSERT (self);
- ASSERT (self->library);
-
- return self->library->flags;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_lib_set_flags
-
-/**
- * Set threading library global flags.
- *
- * Sets the flags for the threading library associated with the current thread.
- *
- * @param[in] flags flags to be set (bit vector: 1 means set the flag, 0 means ignore)
- * @return old flags values
- * @see hythread_lib_clear_flags, hythread_lib_get_flags
- *
- */
-UDATA VMCALL
-hythread_lib_set_flags (UDATA flags)
-{
- hythread_t self;
- UDATA oldFlags;
- self = MACRO_SELF ();
-
- ASSERT (self);
- ASSERT (self->library);
-
- GLOBAL_LOCK (self, CALLER_LIB_SET_FLAGS);
- oldFlags = self->library->flags;
- self->library->flags |= flags;
- GLOBAL_UNLOCK (self);
-
- return oldFlags;
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_lib_clear_flags
-
-/**
- * Clear specified threading library global flags.
- *
- * @see hythread_lib_set_flags, hythread_lib_get_flags
- * @param[in] flags flags to be cleared (bit vector: 1 means clear the flag, 0 means ignore)
- * @return old flags values
- */
-UDATA VMCALL
-hythread_lib_clear_flags (UDATA flags)
-{
- hythread_t self;
- UDATA oldFlags;
- self = MACRO_SELF ();
-
- ASSERT (self);
- ASSERT (self->library);
-
- GLOBAL_LOCK (self, CALLER_LIB_CLEAR_FLAGS);
- oldFlags = self->library->flags;
- self->library->flags &= ~flags;
- GLOBAL_UNLOCK (self);
-
- return oldFlags;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_init_with_name
-/**
- * Acquire and initialize a new monitor from the threading library.
- *
- * @param[out] handle pointer to a hythread_monitor_t to be set to point to the new monitor
- * @param[in] flags initial flag values for the monitor
- * @param[in] name pointer to a C string with a description of how the monitor will be used (may be NULL)
- * If non-NULL, the C string must be valid for the entire life of the monitor
- *
- * @return 0 on success or negative value on failure
- *
- * @see hythread_monitor_destroy
- *
- */
-IDATA VMCALL
-hythread_monitor_init_with_name (hythread_monitor_t * handle, UDATA flags,
- char *name)
-{
- ASSERT (handle);
-
- if (hythread_monitor_init (handle, flags) == 0)
- {
- (*handle)->name = name;
- return 0;
- }
-
- return -1;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_jlm_gc_lock_init
-
-/*
- * Initialize pools and tracing structures for JLM tracing.
- *
- * Can be called multiple times.
- *
- * @return none
- */
-void VMCALL
-hythread_jlm_gc_lock_init ()
-{
- hythread_t self = MACRO_SELF ();
- hythread_library_t library;
- ASSERT (self);
- library = self->library;
- ASSERT (library);
-
- /* If no monitor_tracing pool yet, create it */
- if (library->monitor_tracing_pool == NULL)
- {
- library->monitor_tracing_pool =
- pool_new (sizeof (HyThreadMonitorTracing), 0, 0, 0, thread_malloc,
- thread_free, NULL);
- }
-
- /* If no GC lock tracing pool yet, create it */
- if (library->gc_lock_tracing == NULL)
- {
- library->gc_lock_tracing =
- pool_newElement (library->monitor_tracing_pool);
- }
-
- /* Init the tracing structure */
- memset (library->gc_lock_tracing, 0, sizeof (*library->gc_lock_tracing));
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_jlm_get_gc_lock_tracing
-
-/*
- * Return tracing info.
- *
- * @return pointer to GC lock tracing structure. 0 of not yet initialized
- */
-HyThreadMonitorTracing *VMCALL
-hythread_jlm_get_gc_lock_tracing ()
-{
- hythread_t self = MACRO_SELF ();
- ASSERT (self);
- ASSERT (self->library);
- return self->library->gc_lock_tracing;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_lib_lock
-/**
- * Acquire the threading library's global lock.
- *
- * @note This must not be called recursively by a thread that already owns the global lock.
- * @param[in] self hythread_t for the current thread
- * @return none
- *
- * @see hythread_lib_unlock
- */
-void VMCALL
-hythread_lib_lock (hythread_t self)
-{
- ASSERT (self);
- GLOBAL_LOCK (self, CALLER_GLOBAL_LOCK);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_lib_unlock
-/**
- * Release the threading library's global lock.
- *
- * @note This must be called only by the thread that currently has the global lock locked.
- * @param[in] self hythread_t for the current thread
- * @return none
- *
- * @see hythread_lib_lock
- */
-void VMCALL
-hythread_lib_unlock (hythread_t self)
-{
- ASSERT (self);
- GLOBAL_UNLOCK (self);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_park
-/**
- * 'Park' the current thread.
- *
- * Stop the current thread from executing until it is unparked, interrupted, or the specified timeout elapses.
- *
- * Unlike wait or sleep, the interrupted flag is NOT cleared by this API.
- *
- * @param[in] millis
- * @param[in] nanos
- *
- * @return 0 if the thread is unparked
- * HYTHREAD_INTERRUPTED if the thread was interrupted while parked
- * HYTHREAD_PRIORITY_INTERRUPTED if the thread was priority interrupted while parked
- * HYTHREAD_TIMED_OUT if the timeout expired
- *
- * @see hythread_unpark
- */
-IDATA VMCALL
-hythread_park (I_64 millis, IDATA nanos)
-{
- IDATA rc = 0;
- hythread_t self = MACRO_SELF ();
- ASSERT (self);
-
- THREAD_LOCK (self, self, CALLER_PARK);
-
- if (self->flags & HYTHREAD_FLAG_UNPARKED)
- {
- self->flags &= ~HYTHREAD_FLAG_UNPARKED;
- }
- else if (self->flags & HYTHREAD_FLAG_INTERRUPTED)
- {
- rc = HYTHREAD_INTERRUPTED;
- }
- else if (self->flags & HYTHREAD_FLAG_PRIORITY_INTERRUPTED)
- {
- rc = HYTHREAD_PRIORITY_INTERRUPTED;
- }
- else
- {
- self->flags |= HYTHREAD_FLAG_PARKED | HYTHREAD_FLAG_INTERRUPTABLE;
-
- if (millis || nanos)
- {
- IDATA boundedMillis = BOUNDED_I64_TO_IDATA (millis);
-
- self->flags |= HYTHREAD_FLAG_TIMER_SET;
-
- COND_WAIT_IF_TIMEDOUT (self->condition, self->mutex, boundedMillis,
- nanos)
- {
- rc = HYTHREAD_TIMED_OUT;
- break;
- }
- else
- if (self->flags & HYTHREAD_FLAG_UNPARKED)
- {
- self->flags &= ~HYTHREAD_FLAG_UNPARKED;
- break;
- }
- else if (self->flags & HYTHREAD_FLAG_INTERRUPTED)
- {
- rc = HYTHREAD_INTERRUPTED;
- break;
- }
- else if (self->flags & HYTHREAD_FLAG_PRIORITY_INTERRUPTED)
- {
- rc = HYTHREAD_PRIORITY_INTERRUPTED;
- break;
- }
- COND_WAIT_TIMED_LOOP ();
- }
- else
- {
- COND_WAIT (self->condition, self->mutex);
- if (self->flags & HYTHREAD_FLAG_UNPARKED)
- {
- self->flags &= ~HYTHREAD_FLAG_UNPARKED;
- break;
- }
- else if (self->flags & HYTHREAD_FLAG_INTERRUPTED)
- {
- rc = HYTHREAD_INTERRUPTED;
- break;
- }
- else if (self->flags & HYTHREAD_FLAG_PRIORITY_INTERRUPTED)
- {
- rc = HYTHREAD_PRIORITY_INTERRUPTED;
- break;
- }
- COND_WAIT_LOOP ();
- }
- }
-
- self->flags &=
- ~(HYTHREAD_FLAG_PARKED | HYTHREAD_FLAG_INTERRUPTABLE |
- HYTHREAD_FLAG_TIMER_SET);
-
- THREAD_UNLOCK (self, self);
-
- return rc;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_unpark
-/**
- * 'Unpark' the specified thread.
- *
- * If the thread is parked, it will return from park.
- * If the thread is not parked, its 'UNPARKED' flag will be set, and it will return immediately the next time it is parked.
- *
- * Note that unparks are not counted. Unparking a thread once is the same as unparking it n times.
- *
- * @see hythread_park
- */
-void VMCALL
-hythread_unpark (hythread_t thread)
-{
- hythread_t self = MACRO_SELF ();
-
- ASSERT (self);
- ASSERT (thread);
-
- /* TODO: is GLOBAL_LOCK/GLOBAl_UNLOCK required here? */
-
- GLOBAL_LOCK (self, CALLER_UNPARK_THREAD);
- THREAD_LOCK (self, thread, CALLER_UNPARK_THREAD);
-
- thread->flags |= HYTHREAD_FLAG_UNPARKED;
-
- if (thread->flags & HYTHREAD_FLAG_PARKED)
- {
- COND_NOTIFY_ALL (thread->condition);
- }
-
- THREAD_UNLOCK (self, thread);
- GLOBAL_UNLOCK (self);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_tls_alloc_with_finalizer
-/**
- * Allocate a thread local storage (TLS) key.
- *
- * Create and return a new, unique key for thread local storage.
- *
- * @note The hande returned will be >=0, so it is safe to test the handle against 0 to see if it's been
- * allocated yet.
- *
- * @param[out] handle pointer to a key to be initialized with a key value
- * @param[in] a finalizer function which will be invoked when a thread is detached or terminates if the thread's TLS entry for this key is non-NULL
- * @return 0 on success or negative value if a key could not be allocated (i.e. all TLS has been allocated)
- *
- * @see hythread_tls_free, hythread_tls_set
- */
-IDATA VMCALL
-hythread_tls_alloc_with_finalizer (hythread_tls_key_t * handle,
- hythread_tls_finalizer_t finalizer)
-{
- IDATA index;
- hythread_library_t lib = GLOBAL_DATA (default_library);
- ASSERT (lib);
-
- *handle = 0;
-
- MUTEX_ENTER (lib->tls_mutex);
-
- for (index = 0; index < HYTHREAD_MAX_TLS_KEYS; index++)
- {
- if (lib->tls_finalizers[index] == NULL)
- {
- *handle = index + 1;
- lib->tls_finalizers[index] = finalizer;
- break;
- }
- }
-
- MUTEX_EXIT (lib->tls_mutex);
-
- return index < HYTHREAD_MAX_TLS_KEYS ? 0 : -1;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION tls_finalize
-/*
- * Run finalizers on any non-NULL TLS values for the current thread
- *
- * @param[in] thread current thread
- * @return none
- */
-static void
-tls_finalize (hythread_t thread)
-{
- IDATA index;
- hythread_library_t lib = thread->library;
-
- for (index = 0; index < HYTHREAD_MAX_TLS_KEYS; index++)
- {
- if (thread->tls[index] != NULL)
- {
- void *value;
- hythread_tls_finalizer_t finalizer;
-
- /* read the value and finalizer together under mutex to be sure that they belong together */
- MUTEX_ENTER (lib->tls_mutex);
- value = thread->tls[index];
- finalizer = lib->tls_finalizers[index];
- MUTEX_EXIT (lib->tls_mutex);
-
- if (value)
- {
- finalizer (value);
- }
- }
- }
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION tls_null_finalizer
-static void HYTHREAD_PROC
-tls_null_finalizer (void *entry)
-{
- /* do nothing */
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_current_stack_free
-/**
- * Return the remaining useable bytes of the current thread's OS stack.
- *
- * @return OS stack free size in bytes, 0 if it cannot be determined.
- */
-UDATA VMCALL
-hythread_current_stack_free(void)
-{
-#if defined(WIN32)
- MEMORY_BASIC_INFORMATION memInfo;
- SYSTEM_INFO sysInfo;
- UDATA stackFree;
- UDATA guardPageSize;
-
- GetSystemInfo(&sysInfo);
- VirtualQuery(&memInfo, &memInfo, sizeof(MEMORY_BASIC_INFORMATION));
- stackFree = ((UDATA) &memInfo - (UDATA) memInfo.AllocationBase) & ~sizeof(UDATA);
-
- /* By observation, Win32 reserves 3 pages at the low end of the stack for guard pages, so omit them */
-
- guardPageSize = 3 * (UDATA) sysInfo.dwPageSize;
- return (stackFree < guardPageSize) ? 0 : stackFree - guardPageSize;
-#else
- return 0;
-#endif
+ return -1;
}
Index: trunk/modules/portlib/src/main/native/thread/shared/hythreadinspect.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/shared/hythreadinspect.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/shared/hythreadinspect.c (working copy)
@@ -1,285 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @file
- * @ingroup Thread
- */
-
-/*
- * This file contains thread routines which are compiled twice -- once for in-process, and
- * once for out-of-process uses (e.g. debug extensions).
- * The APIs in this file are only used for inspecting threads -- not for modifying them
- */
-
-#if defined(HYVM_OUT_OF_PROCESS)
-#include "hydbgext.h"
-#endif
-
-#include "threaddef.h"
-
-#if defined(HYVM_OUT_OF_PROCESS)
-#define READU(field) dbgReadUDATA((UDATA*)&(field))
-#define READP(field) ((void*)dbgReadUDATA((UDATA*)&(field)))
-#undef MUTEX_ENTER
-#define MUTEX_ENTER(a)
-#undef MUTEX_EXIT
-#define MUTEX_EXIT(a)
-#undef GLOBAL_LOCK
-#define GLOBAL_LOCK(a, b)
-#undef GLOBAL_UNLOCK
-#define GLOBAL_UNLOCK(a)
-#else /* defined (HYVM_OUT_OF_PROCESS) */
-#define READU(field) ((UDATA)(field))
-#define READP(field) (field)
-#endif
-
-#define CDEV_CURRENT_FUNCTION _prototypes_private
-static hythread_monitor_pool_t pool_for_monitor
-PROTOTYPE ((hythread_library_t lib, hythread_monitor_t monitor));
-static hythread_library_t get_default_library PROTOTYPE ((void));
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_walk
-/**
- * Walk all active monitors.
- *
- * @param[in] monitor If NULL, the first monitor is returned and the monitor pool is locked (thread lib is globally locked)
- * If non-NULL, the next monitor is returned.
- * @return a pointer to a monitor, or NULL if all monitors walked (and thread lib is globally unlocked).
- *
- * @note As this is currently implemented, this must be called to walk ALL monitors. It can't
- * be used to look for a specific monitor and then quit.
- *
- */
-hythread_monitor_t VMCALL
-hythread_monitor_walk (hythread_monitor_t monitor)
-{
- hythread_monitor_pool_t pool;
- hythread_library_t lib = get_default_library ();
-
- ASSERT (lib);
- ASSERT (lib->monitor_pool);
- ASSERT (lib->monitor_pool->entries);
- ASSERT (MACRO_SELF () != 0);
-
- if (monitor == NULL)
- {
- GLOBAL_LOCK (MACRO_SELF (), CALLER_MONITOR_WALK);
- pool = READP (lib->monitor_pool);
- monitor = &pool->entries[0];
- if (READU (monitor->count) != FREE_TAG)
- return monitor;
- }
- else
- {
- pool = pool_for_monitor (lib, monitor);
- if (pool == NULL)
- {
- /* should never happen */
- GLOBAL_UNLOCK (MACRO_SELF ());
- return NULL;
- }
- }
-
- do
- {
- if (monitor >= &pool->entries[MONITOR_POOL_SIZE - 1])
- {
- if ((pool = READP (pool->next)) == NULL)
- {
- /* we've walked all monitors */
- GLOBAL_UNLOCK (MACRO_SELF ());
- return NULL;
- }
- monitor = &pool->entries[0];
- }
- else
- {
- monitor++;
- }
- }
- while (READU (monitor->count) == FREE_TAG);
-
- return monitor;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_tls_get
-/**
- * Get a thread's thread local storage (TLS) value.
- *
- * @param[in] thread a thread
- * @param[in] key key to have TLS value returned (value returned by hythread_tls_alloc)
- * @return pointer to location of TLS or NULL on failure.
- *
- */
-void *VMCALL
-hythread_tls_get (hythread_t thread, hythread_tls_key_t key)
-{
- return (void *) READU (thread->tls[key - 1]);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION pool_for_monitor
-/*
- * Return the monitor pool holding a monitor.
- *
- * @param[in] lib threading library (non-NULL)
- * @param[in] monitor
- * @return pointer to pool on success, NULL on failure (invalid monitor?)
- */
-static hythread_monitor_pool_t
-pool_for_monitor (hythread_library_t lib, hythread_monitor_t monitor)
-{
- hythread_monitor_pool_t pool = READP (lib->monitor_pool);
-
- /* find out which pool the monitor is from (cache this, maybe?)
- (NOTE: technically, this search invokes undefined behaviour (comparing pointers from different
- malloc's). But it should work on every platform with a flat memory model. */
-
- ASSERT (lib);
- ASSERT (monitor);
- ASSERT (pool);
-
- while (monitor < &pool->entries[0]
- || monitor > &pool->entries[MONITOR_POOL_SIZE - 1])
- {
- if ((pool = READP (pool->next)) == NULL)
- {
- break;
- }
- }
-
- return pool;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_get_priority
-/**
- * Return a thread's scheduling priority.
- *
- * @param[in] thread (non-NULL)
- * @return scheduling priority
- * @see hythread_create, hythread_set_priority
- *
- */
-UDATA VMCALL
-hythread_get_priority (hythread_t thread)
-{
- ASSERT (thread);
- return READU (thread->priority);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_get_flags
-/**
- * Return a thread's flags.
- *
- * @param[in] thread (non-NULL)
- * @param[in] blocker if non-NULL, will be set to the monitor on which the thread is blocked (if any)
- * @return flags
- *
- */
-UDATA VMCALL
-hythread_get_flags (hythread_t thread, hythread_monitor_t * blocker)
-{
- UDATA flags;
-
- ASSERT (thread);
-
- MUTEX_ENTER (thread->mutex);
-
- if (blocker)
- {
- *blocker = READP (thread->monitor);
- }
- flags = READU (thread->flags);
-
- MUTEX_EXIT (thread->mutex);
-
- return flags;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_get_name
-/**
- * Return a monitor's name.
- *
- * @param[in] monitor (non-NULL)
- * @return pointer to the monitor's name (may be NULL)
- *
- * @see hythread_monitor_init_with_name
- *
- */
-char *VMCALL
-hythread_monitor_get_name (hythread_monitor_t monitor)
-{
- ASSERT (monitor);
- return READP (monitor->name);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_monitor_get_tracing
-
-/*
- * Return a monitor's tracing information.
- *
- * @param[in] monitor (non-NULL)
- * @return pointer to the monitor's tracing information (may be NULL)
- *
- */
-HyThreadMonitorTracing *VMCALL
-hythread_monitor_get_tracing (hythread_monitor_t monitor)
-{
- ASSERT (monitor);
-
- return READP (monitor->tracing);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION getDefaultLibrary
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION get_default_library
-/*
- * Return the default threading library.
- *
- * @return pointer to the default threading library
- *
- */
-static hythread_library_t
-get_default_library (void)
-{
-#if defined(HYVM_OUT_OF_PROCESS)
- return dbgGetThreadLibrary ();
-#else
- return GLOBAL_DATA (default_library);
-#endif
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
Index: trunk/modules/portlib/src/main/native/thread/shared/hythreadinspect.h
===================================================================
--- trunk/modules/portlib/src/main/native/thread/shared/hythreadinspect.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/shared/hythreadinspect.h (working copy)
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if !defined(hythreadinspect_h)
-#define hythreadinspect_h
-
-#if defined(HYVM_OUT_OF_PROCESS)
-/* redefine thread functions */
-#define hythread_monitor_walk dbg_hythread_monitor_walk
-#define hythread_tls_get dbg_hythread_tls_get
-#define hythread_get_priority dbg_hythread_get_priority
-#define hythread_get_flags dbg_hythread_get_flags
-#define hythread_monitor_get_name dbg_hythread_monitor_get_name
-#define hythread_monitor_get_tracing dbg_hythread_monitor_get_tracing
-#define getVMThreadStatus dbgGetVMThreadStatus
-#endif
-
-#endif /* hythreadinspect_h */
-
-/* Note: This section is NOT protected by #ifdefs.
- * It may be safely included more than once.
- */
-UDATA VMCALL hythread_get_flags
-PROTOTYPE ((hythread_t thread, hythread_monitor_t * blocker));
-HyThreadMonitorTracing *VMCALL hythread_monitor_get_tracing
-PROTOTYPE ((hythread_monitor_t monitor));
-UDATA VMCALL hythread_get_priority PROTOTYPE ((hythread_t thread));
-void *VMCALL hythread_tls_get
-PROTOTYPE ((hythread_t thread, hythread_tls_key_t key));
-char *VMCALL hythread_monitor_get_name
-PROTOTYPE ((hythread_monitor_t monitor));
-hythread_monitor_t VMCALL hythread_monitor_walk
-PROTOTYPE ((hythread_monitor_t monitor));
Index: trunk/modules/portlib/src/main/native/thread/shared/rwmutex.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/shared/rwmutex.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/shared/rwmutex.c (working copy)
@@ -1,254 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include
-#include "threaddef.h"
-
-#undef ASSERT
-#define ASSERT(x) /**/
- typedef struct RWMutex
-{
- hythread_monitor_t syncMon;
- IDATA status;
- hythread_t writer;
-} RWMutex;
-
-#define ASSERT_RWMUTEX(m)\
- ASSERT((m));\
- ASSERT((m)->syncMon);
-
-#define RWMUTEX_STATUS_IDLE(m) ((m)->status == 0)
-#define RWMUTEX_STATUS_READING(m) ((m)->status > 0)
-#define RWMUTEX_STATUS_WRITING(m) ((m)->status < 0)
-
-/**
- * Acquire and initialize a new read/write mutex from the threading library.
- *
- * @param[out] handle pointer to a hythread_rwmutex_t to be set to point to the new mutex
- * @param[in] flags initial flag values for the mutex
- * @return 0 on success, negative value on failure
- *
- * @see hythread_rwmutex_destroy
- */
-IDATA VMCALL
-hythread_rwmutex_init (hythread_rwmutex_t * handle, UDATA flags,
- const char *name)
-{
- RWMutex *mutex = (RWMutex *) malloc (sizeof (RWMutex));
- hythread_monitor_init_with_name (&mutex->syncMon, 0, (char *) name);
- mutex->status = 0;
- mutex->writer = 0;
-
- ASSERT (handle);
- *handle = mutex;
-
- return 0;
-}
-
-/**
- * Destroy a read/write mutex.
- *
- * Destroying a mutex frees the internal resources associated
- * with it.
- *
- * @note A mutex must NOT be destroyed if it is owned
- * by any threads for either read or write access.
- *
- * @param[in] mutex a mutex to be destroyed
- * @return 0 on success or negative value on failure
- *
- * @see hythread_rwmutex_init
- */
-IDATA VMCALL
-hythread_rwmutex_destroy (hythread_rwmutex_t mutex)
-{
- ASSERT (mutex);
- ASSERT (mutex->syncMon);
- ASSERT (0 == mutex->status);
- ASSERT (0 == mutex->writer);
- hythread_monitor_destroy (mutex->syncMon);
- free (mutex);
- return 0;
-}
-
-/**
- * Enter a read/write mutex as a reader.
- *
- * A thread may re-enter a mutex it owns multiple times, but
- * must exit the same number of times as a reader
- * using hythread_rwmutex_exit_read.
- *
- * A thread with writer access can enter a monitor
- * with reader access, but must exit the mutex in the
- * opposite order.
- *
- * e.g. The following is acceptable
- * hythread_rwmutex_enter_write(mutex);
- * hythread_rwmutex_enter_read(mutex);
- * hythread_rwmutex_exit_read(mutex);
- * hythread_rwmutex_exit_write(mutex);
- *
- * However, a thread with read access MUST NOT
- * ask for write access on the same mutex.
- *
- * @param[in] mutex a mutex to be entered for read access
- * @return 0 on success
- *
- * @see hythread_rwmutex_exit_read
- */
-IDATA VMCALL
-hythread_rwmutex_enter_read (hythread_rwmutex_t mutex)
-{
- ASSERT_RWMUTEX (mutex);
-
- if (mutex->writer == hythread_self ())
- {
- hythread_monitor_exit (mutex->syncMon);
- return 0;
- }
-
- hythread_monitor_enter (mutex->syncMon);
-
- while (mutex->status < 0)
- {
- hythread_monitor_wait (mutex->syncMon);
- }
- mutex->status++;
-
- hythread_monitor_exit (mutex->syncMon);
- return 0;
-
-}
-
-/**
- * Exit a read/write mutex as a reader.
- *
- * @param[in] mutex a mutex to be exited
- * @return 0 on success
- *
- * @see hythread_rwmutex_enter_read
- *
- */
-IDATA VMCALL
-hythread_rwmutex_exit_read (hythread_rwmutex_t mutex)
-{
- ASSERT_RWMUTEX (mon);
-
- if (mutex->writer == hythread_self ())
- {
- return 0;
- }
-
- hythread_monitor_enter (mutex->syncMon);
-
- mutex->status--;
- if (0 == mutex->status)
- {
- hythread_monitor_notify (mutex->syncMon);
- }
-
- hythread_monitor_exit (mutex->syncMon);
-
- return 0;
-
-}
-
-/**
- * Enter a read/write mutex as a writer.
- *
- * A thread may re-enter a mutex it owns multiple times, but
- * must exit the same number of times as a writer
- * using hythread_rwmutex_exit_write.
- *
- * A thread with writer access can enter a monitor
- * with reader access, but must exit the mutex in the
- * opposite order.
- *
- * e.g. The following is acceptable
- * hythread_rwmutex_enter_write(mutex);
- * hythread_rwmutex_enter_read(mutex);
- * hythread_rwmutex_exit_read(mutex);
- * hythread_rwmutex_exit_write(mutex);
- *
- * However, a thread with read access MUST NOT
- * ask for write access on the same mutex.
- *
- * @param[in] mutex a mutex to be entered for read access
- * @return 0 on success
- *
- * @see hythread_rwmutex_exit_write
- */
-IDATA VMCALL
-hythread_rwmutex_enter_write (hythread_rwmutex_t mutex)
-{
-
- hythread_t self = hythread_self ();
- ASSERT_RWMUTEX (mutex);
-
- /* recursive? */
- if (mutex->writer == self)
- {
- mutex->status--;
- return 0;
- }
-
- hythread_monitor_enter (mutex->syncMon);
-
- while (mutex->status != 0)
- {
- hythread_monitor_wait (mutex->syncMon);
- }
- mutex->status--;
- mutex->writer = self;
-
- ASSERT (RWMUTEX_STATUS_WRITING (mutex));
-
- hythread_monitor_exit (mutex->syncMon);
-
- return 0;
-
-}
-
-/**
- * Exit a read/write mutex as a writer.
- *
- * @param[in] mutex a mutex to be exited
- * @return 0 on success
- *
- * @see hythread_rwmutex_enter_write
- *
- */
-IDATA VMCALL
-hythread_rwmutex_exit_write (hythread_rwmutex_t mutex)
-{
- ASSERT_RWMUTEX (mon);
-
- ASSERT (mutex->writer == hythread_self ());
- ASSERT (RWMUTEX_STATUS_WRITING (mutex));
- hythread_monitor_enter (mutex->syncMon);
-
- mutex->status++;
- if (0 == mutex->status)
- {
- mutex->writer = NULL;
- hythread_monitor_notify_all (mutex->syncMon);
- }
-
- hythread_monitor_exit (mutex->syncMon);
- return 0;
-
-}
Index: trunk/modules/portlib/src/main/native/thread/shared/thread_copyright.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/shared/thread_copyright.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/shared/thread_copyright.c (working copy)
@@ -1,21 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* A copyright string included in each DLL and executable */
-
-const char hyCopyright[] =
- "(c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable.";
Index: trunk/modules/portlib/src/main/native/thread/shared/threaddef.h
===================================================================
--- trunk/modules/portlib/src/main/native/thread/shared/threaddef.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/shared/threaddef.h (working copy)
@@ -1,225 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if !defined(threaddef_h)
-#define threaddef_h
-
-#include
-
-#include "thrdsup.h"
-#include "rasthrsup.h"
-#include "hythread.h"
-#undef hythread_monitor_init
-#undef hythread_monitor_init_with_name
-#include "thrtypes.h"
-#include "hypool.h"
-
-/*
- Define this to force a thread to be spawned when
- interrupting a waiting thread
- (it's a debug thing)
-*/
-#undef ALWAYS_SPAWN_THREAD_TO_INTERRUPT
-
-/* You got to know what time it is */
-typedef U_64 hytime_t;
-typedef I_64 hytime_delta_t;
-/* ASSERT and Debug */
-
-#if !defined(STATIC_ASSERT)
-#define STATIC_ASSERT(x) do { typedef int failed_assert[(x) ? 1 : -1]; } while(0)
-#endif /* STATIC_ASSERT */
-
-#if defined(THREAD_ASSERTS)
-
-#define UNOWNED ((hythread_t)-1)
-extern hythread_t global_lock_owner;
-#undef NDEBUG
-#include
-#if !defined(ASSERT)
-#define ASSERT(x) assert((x))
-#endif /* !ASSERT */
-
-#if !defined(ASSERT_DEBUG)
-#define ASSERT_DEBUG(x) assert((x))
-#endif
-
-#else /* THREAD_ASSERTS */
-
-#if !defined(ASSERT)
-#define ASSERT(ignore) ((void)0)
-#endif /* !ASSERT */
-
-#if !defined(ASSERT_DEBUG)
-#define ASSERT_DEBUG(ignore) ((void)0)
-#endif /* !ASSERT_DEBUG */
-
-#endif /* THREAD_ASSERTS */
-
-#undef DEBUG
-#define DEBUG (0)
-
-/* Helper defines for notify_thread() */
-#define SET_NOTIFIED_FLAG (1)
-#define DONT_SET_NOTIFIED_FLAG (0)
-
-void hythread_monitor_pin
-PROTOTYPE ((hythread_monitor_t monitor, hythread_t self));
-void hythread_monitor_unpin
-PROTOTYPE ((hythread_monitor_t monitor, hythread_t self));
-void paint_stack PROTOTYPE ((hythread_t thread));
-
-/*
- * constants for profiling
- */
-#define MAX_CALLER_INDEX 63
-enum
-{
- CALLER_ATTACH = 0,
- CALLER_DESTROY,
- CALLER_SUSPEND,
- CALLER_RESUME,
- CALLER_CLEAR_INTERRUPTED,
- CALLER_THREAD_WRAPPER,
- CALLER_NOTIFY_ONE_OR_ALL,
- CALLER_SLEEP_INTERRUPTABLE,
- CALLER_TRY_ENTER_USING,
- CALLER_SLEEP,
- CALLER_EXIT_MONITOR,
- CALLER_DETACH,
- CALLER_CLEAR_PRIORITY_INTERRUPTED,
- CALLER_INTERNAL_EXIT1,
- CALLER_INTERNAL_EXIT2,
- CALLER_MONITOR_ENTER1,
- CALLER_MONITOR_ENTER2,
- CALLER_MONITOR_ENTER_THREE_TIER1,
- CALLER_MONITOR_ENTER_THREE_TIER2,
- CALLER_MONITOR_ENTER_THREE_TIER3,
- CALLER_MONITOR_EXIT1,
- CALLER_MONITOR_WAIT1,
- CALLER_MONITOR_WAIT2,
- CALLER_INTERRUPT_THREAD,
- CALLER_MONITOR_NUM_WAITING,
- CALLER_MONITOR_DESTROY,
- CALLER_GLOBAL_LOCK,
- CALLER_MONITOR_ACQUIRE,
- CALLER_INTERRUPT_SERVER,
- CALLER_RESET_TRACING,
- CALLER_LIB_SET_FLAGS,
- CALLER_LIB_CLEAR_FLAGS,
- CALLER_PARK,
- CALLER_UNPARK,
- CALLER_LAST_INDEX
-};
-
-/* helper defines for local functions */
-#define WAIT_INTERRUPTABLE (1)
-#define WAIT_UNINTERRUPTABLE (0)
-#define NOTIFY_ONE (0)
-#define NOTIFY_ALL (1)
-#define GLOBAL_NOT_LOCKED (0)
-#define GLOBAL_IS_LOCKED (1)
-
-/* MACRO_SELF */
-#define MACRO_SELF() ((hythread_t)TLS_GET( ((hythread_library_t)GLOBAL_DATA(default_library))->self_ptr))
-
-/* GLOBAL_LOCK */
-#if defined(THREAD_ASSERTS)
-#define GLOBAL_LOCK(self,caller) { ASSERT(global_lock_owner != self); MUTEX_ENTER((self)->library->monitor_mutex); ASSERT(UNOWNED == global_lock_owner); global_lock_owner = self; }
-#else
-#define GLOBAL_LOCK(self, caller) MUTEX_ENTER(self->library->monitor_mutex)
-#endif
-
-/* GLOBAL_UNLOCK */
-#if defined(THREAD_ASSERTS)
-#define GLOBAL_UNLOCK(self) { ASSERT (self == global_lock_owner); global_lock_owner = UNOWNED; MUTEX_EXIT(self->library->monitor_mutex); }
-#else
-#define GLOBAL_UNLOCK(self) MUTEX_EXIT(self->library->monitor_mutex)
-#endif
-
-/*
- * GLOBAL_LOCK_SIMPLE
- * locking when you don't have a thread, just a lib
- */
-#if defined(THREAD_ASSERTS)
-#define GLOBAL_LOCK_SIMPLE(lib) { hythread_t self = MACRO_SELF(); ASSERT (self != global_lock_owner); MUTEX_ENTER(lib->monitor_mutex); ASSERT(UNOWNED == global_lock_owner); global_lock_owner = self; }
-#else
-#define GLOBAL_LOCK_SIMPLE(lib) MUTEX_ENTER(lib->monitor_mutex)
-#endif
-
-/*
- * GLOBAL_UNLOCK_SIMPLE
- * unlocking when you don't have a thread, just a lib
- */
-#if defined(THREAD_ASSERTS)
-#define GLOBAL_UNLOCK_SIMPLE(lib) { ASSERT (MACRO_SELF() == global_lock_owner); global_lock_owner = UNOWNED; MUTEX_EXIT(lib->monitor_mutex); }
-#else
-#define GLOBAL_UNLOCK_SIMPLE(lib) MUTEX_EXIT(lib->monitor_mutex)
-#endif
-
-/* THREAD_LOCK */
-#define THREAD_LOCK(self, thread, caller) MUTEX_ENTER(thread->mutex)
-
-/* THREAD_UNLOCK */
-#define THREAD_UNLOCK(self, thread) MUTEX_EXIT(thread->mutex)
-
-/* MONITOR_LOCK */
-#define MONITOR_LOCK(self, monitor, caller) MUTEX_ENTER(monitor->mutex)
-
-/* MONITOR_TRY_LOCK */
-#if defined(FORCE_TO_USE_IS_THREAD)
-/*
- * Force the use of the interruptServer (IS) thread by always failing
- * when trying to enter a monitor without blocking
- */
-#define MONITOR_TRY_LOCK(monitor) (-1)
-#else
-#define MONITOR_TRY_LOCK(monitor) (MUTEX_TRY_ENTER(monitor->mutex))
-#endif
-
-/* MONITOR_UNLOCK */
-#define MONITOR_UNLOCK(self, monitor) MUTEX_EXIT(monitor->mutex)
-
-/* IS_JLM_ENABLED */
-#define IS_JLM_ENABLED(thread) ((thread)->library->flags & HYTHREAD_FLAG_JLM_ENABLED)
-
-/* IS_JLM_TS_ENABLED */
-#define IS_JLM_TS_ENABLED(thread) ((thread)->library->flags & HYTHREAD_FLAG_JLMTS_ENABLED)
-
-/* IS_JLM_HST_ENABLED */
-#define IS_JLM_HST_ENABLED(thread) ((thread)->library->flags & HYTHREAD_FLAG_JLMHST_ENABLED)
-
-/* ACCUMULATE_SPIN_TIME */
-#define ACCUMULATE_SPIN_TIME(spinTime, endSpinTime, startSpinTime, endPauseSpinTime, startPauseSpinTime) \
- \
- /* accumulate spin interval in monitor: \
- - again delta could be negative if CPU clocks not sync, and thread has moved to another processor \
- - also the spin start time will be zero if no spinning has occurred. This is a convention \
- */ \
- if ((startSpinTime) > 0) { \
- /* must be declared as a local variable in the C function from which this is called */ \
- deltaTime = (TIME_DELTA) ((endSpinTime) - (startSpinTime)); \
- \
- if (deltaTime > 0) { \
- (spinTime) += (TIME) deltaTime; \
- deltaTime = (TIME_DELTA) ((endPauseSpinTime) - (startPauseSpinTime)); \
- if ((spinTime) > deltaTime) { \
- (spinTime) -= deltaTime; /* assumes gc can't run once spinning on try_enter starts */ \
- } \
- }
-
-#endif /* threaddef_h */
Index: trunk/modules/portlib/src/main/native/thread/shared/thrprof.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/shared/thrprof.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/shared/thrprof.c (working copy)
@@ -1,302 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * @file
- * @ingroup Thread
- */
-
-
-/*
- * the following must come before the standard includes because thrdsup.h
- * includes windows.h in Win32.
- */
-#include "thrdsup.h"
-
-#include "hythread.h"
-#include "thrtypes.h"
-
-#define CDEV_CURRENT_FUNCTION _prototypes_private
-
-void paint_stack PROTOTYPE ((hythread_t thread));
-
-#undef CDEV_CURRENT_FUNCTION
-
-extern UDATA current_stack_depth PROTOTYPE ((void));
-
-#define STACK_PATTERN 0xBAADF00D
-
-#define CDEV_CURRENT_FUNCTION hythread_get_flags
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_get_cpu_time
-/**
- * Return the amount of CPU time used by a thread.
- *
- * @param[in] thread
- * @return actual time on CPU used by thread (nanoseconds) or
- * negative value if not supported.
- */
-I_64 VMCALL
-hythread_get_cpu_time (hythread_t thread)
-{
-
-#if defined(WIN32)
- FILETIME creationTime, exitTime, kernelTime, userTime;
- I_64 totalTime;
- /* WARNING! Not supported on Win95! Need to test to ensure this fails gracefully */
- if (GetThreadTimes
- (thread->handle, &creationTime, &exitTime, &kernelTime, &userTime))
- {
- totalTime =
- ((I_64) kernelTime.
- dwLowDateTime | ((I_64) kernelTime.dwHighDateTime << 32)) +
- ((I_64) userTime.
- dwLowDateTime | ((I_64) userTime.dwHighDateTime << 32));
- /* totalTime is in 100's of nanos. Convert to nanos */
- return totalTime * 100;
- }
-#endif /* WIN32 */
-
- return -1;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_get_handle
-/**
- * Return the OS handle for a thread.
- *
- * @param thread a thread
- * @return OS handle
- */
-UDATA VMCALL
-hythread_get_handle (hythread_t thread)
-{
- return (UDATA) thread->handle;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_enable_stack_usage
-/**
- * Enable or disable monitoring of stack usage.
- *
- * @param[in] enable 0 to disable or non-zero to enable.
- * @return none
- *
- */
-void VMCALL
-hythread_enable_stack_usage (UDATA enable)
-{
- hythread_library_t lib = GLOBAL_DATA (default_library);
- lib->stack_usage = enable;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_get_stack_usage
-/**
- * Return the approximate stack usage by a thread
- *
- * @param[in] thread a thread
- * @return 0 if the stack has not been painted
- * (UDATA)-1 if the stack has overflowed
- * otherwise the approximate maximum number of bytes used on the stack
- */
-UDATA VMCALL
-hythread_get_stack_usage (hythread_t thread)
-{
-#if defined(LINUX)
- return 0;
-#else
- UDATA *tos = thread->tos;
- UDATA count = thread->stacksize;
- if (tos == NULL || count == 0)
- {
- return 0;
- }
- if (*tos != STACK_PATTERN)
- {
- return (UDATA) - 1;
- }
- while (*tos++ == STACK_PATTERN)
- {
- count -= sizeof (UDATA);
- }
- return count;
-#endif
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION paint_stack
-/*
- * Paint a thread's stack.
- *
- * Attempt to paint the stack region with STACK_PATTERN so we can
- * detect stack usage. Sets thread->tos to the maximum stack
- * address.
- * @note This won't work on PA-RISC because of backwards stacks
- *
- * @param thread a thread
- * @return none
- */
-void
-paint_stack (hythread_t thread)
-{
-#if defined(LINUX)
- /* z/OS and Linux don't let us set the stack size, so we can't paint the stack safely */
-#elif defined(WIN32)
- MEMORY_BASIC_INFORMATION memInfo;
- SYSTEM_INFO sysInfo;
- UDATA *curr;
- UDATA *stack = (UDATA *) & stack;
- /* Find out where the stack starts. */
- VirtualQuery (stack, &memInfo, sizeof (MEMORY_BASIC_INFORMATION));
- /* Start painting. Skip the top 32 slots (to protect this stack frame) */
- curr = stack - 32;
- __try
- {
- while (curr > (UDATA *) memInfo.AllocationBase)
- *curr-- = STACK_PATTERN;
- }
- __except (1)
- {
- /* Ran off the end of the stack. Stop */
- }
- thread->tos = curr + 1;
- /* Round up to the system page size. */
- GetSystemInfo (&sysInfo);
- thread->stacksize =
- ((UDATA) stack - (UDATA) thread->tos +
- sysInfo.dwPageSize) & ~(sysInfo.dwPageSize - 1);
-#else
- IDATA maxStack, stackSize, index;
- UDATA *stack = (UDATA *) & stack;
- stackSize = thread->stacksize - current_stack_depth ();
- maxStack = stackSize / sizeof (UDATA) - 32;
- if (maxStack <= 0)
- {
- return;
- }
- thread->tos = stack - maxStack;
- /* don't paint the top 32 slots (to protect this stack frame) */
- for (index = 32; index <= maxStack; index++)
- {
- *(stack - index) = STACK_PATTERN;
- }
-#endif
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_get_stack_size
-/**
- * Returns a thread's stack size.
- *
- * @param[in] thread a thread
- * @return 0 if the thread is an attached thread
- * or the initial size of the thread's stack,
- *
- */
-UDATA VMCALL
-hythread_get_stack_size (hythread_t thread)
-{
- return thread->stacksize;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_get_os_priority
-/**
- * Return the OS's scheduling policy and priority for a thread.
- *
- * Query the OS to determine the actual priority of the specified thread.
- * The priority and scheduling policy are stored in the pointers provided.
- * On Windows the "policy" contains the thread's priority class.
- * On POSIX systems it contains the scheduling policy
- * On OS/2 no information is available. 0 is stored in both pointers.
- *
- * @param[in] thread a thread
- * @param[in] policy pointer to location where policy will be stored (non-NULL)
- * @param[in] priority pointer to location where priority will be stored (non-NULL)
- * @return 0 on success or negative value on failure
- */
-IDATA VMCALL
-hythread_get_os_priority (hythread_t thread, IDATA * policy, IDATA * priority)
-{
-#if defined(HY_POSIX_THREADS)
- struct sched_param sched_param;
- int osPolicy, rc;
- rc = pthread_getschedparam (thread->handle, &osPolicy, &sched_param);
- if (rc)
- return -1;
- *priority = sched_param.sched_priority;
- *policy = osPolicy;
-#else
-#if defined(WIN32)
- *priority = GetThreadPriority (thread->handle);
- if (*priority == THREAD_PRIORITY_ERROR_RETURN)
- return -1;
-
- *policy = GetPriorityClass (thread->handle);
- if (*policy == 0)
- return -1;
-#else
-
-#error Unknown platform
-
-#endif /* HY_POSIX_THREADS */
-#endif /* HYEPOC32 */
-
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION hythread_get_user_time
-/**
- * Return the amount of USER time used by a thread.
- *
- * @param[in] thread
- * @return actual time on USER used by thread (nanoseconds) or
- * negative value if not supported.
- */
-I_64 VMCALL
-hythread_get_user_time (hythread_t thread)
-{
-
-#if defined(WIN32)
- FILETIME creationTime, exitTime, kernelTime, userTime;
- I_64 totalTime;
- /* WARNING! Not supported on Win95! Need to test to ensure this fails gracefully */
- if (GetThreadTimes
- (thread->handle, &creationTime, &exitTime, &kernelTime, &userTime))
- {
- totalTime =
- ((I_64) userTime.
- dwLowDateTime | ((I_64) userTime.dwHighDateTime << 32));
- /* totalTime is in 100's of nanos. Convert to nanos */
- return totalTime * 100;
- }
-#endif /* WIN32 */
-
- return -1;
-}
-
-#undef CDEV_CURRENT_FUNCTION
Index: trunk/modules/portlib/src/main/native/thread/unix/ia64/thrhelp.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/ia64/thrhelp.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/ia64/thrhelp.c (working copy)
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "hycomp.h"
-#include "hythread.h"
-#include "assert.h"
-
-HY_CFUNC void VMCALL hythread_monitor_unpin (hythread_monitor_t monitor,
- hythread_t osThread) {
- assert(0); // should never be executed
-}
-
-HY_CFUNC void VMCALL hythread_monitor_pin (hythread_monitor_t monitor,
- hythread_t osThread) {
- assert(0); // should never be executed
-}
-
-HY_CFUNC IDATA VMCALL hythread_spinlock_acquire (hythread_t self,
- hythread_monitor_t monitor) {
- assert(0); // should never be executed
-}
-
-HY_CFUNC UDATA VMCALL hythread_spinlock_swapState (hythread_monitor_t monitor,
- UDATA newState) {
- assert(0); // should never be executed
-}
Index: trunk/modules/portlib/src/main/native/thread/unix/ia64/thrspinlock.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/ia64/thrspinlock.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/ia64/thrspinlock.c (working copy)
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "assert.h"
-
-void thrspinlock_foo() {
- assert(0); // should never be executed
-}
Index: trunk/modules/portlib/src/main/native/thread/unix/libhythr.exp
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/libhythr.exp (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/libhythr.exp (working copy)
@@ -1,81 +1,12 @@
HYTHR_0.1 {
global :
- hythread_current_stack_free;
- hythread_attach;
- hythread_create;
- hythread_cancel;
- hythread_interrupt;
- hythread_clear_interrupted;
- hythread_interrupted;
- hythread_priority_interrupt;
- hythread_clear_priority_interrupted;
- hythread_priority_interrupted;
- hythread_monitor_destroy;
- hythread_monitor_enter;
- hythread_monitor_get_name;
- hythread_monitor_enter_using_threadId;
- hythread_monitor_try_enter;
- hythread_monitor_try_enter_using_threadId;
- hythread_monitor_exit;
- hythread_monitor_exit_using_threadId;
- hythread_monitor_init;
- hythread_monitor_init_with_name;
- hythread_monitor_notify;
- hythread_monitor_notify_all;
- hythread_monitor_wait;
- hythread_monitor_wait_timed;
- hythread_monitor_wait_interruptable;
- hythread_monitor_num_waiting;
- hythread_resume;
- hythread_self;
- hythread_set_priority;
- hythread_get_priority;
- hythread_sleep;
- hythread_sleep_interruptable;
- hythread_suspend;
- hythread_tls_alloc;
- hythread_tls_alloc_with_finalizer;
- hythread_tls_free;
- hythread_tls_get;
- hythread_tls_set;
- hythread_yield;
- hythread_exit;
- hythread_detach;
- hythread_global;
- hythread_get_flags;
- hythread_monitor_walk;
- hythread_lib_lock;
- hythread_lib_unlock;
- hythread_rwmutex_init;
- hythread_rwmutex_destroy;
- hythread_rwmutex_enter_read;
- hythread_rwmutex_exit_read;
- hythread_rwmutex_enter_write;
- hythread_rwmutex_exit_write;
- hythread_park;
- hythread_unpark;
- hythread_monitor_lock;
- hythread_monitor_unlock;
- hythread_monitor_pin;
- hythread_monitor_unpin;
- hythread_lib_get_flags;
- hythread_lib_set_flags;
- hythread_lib_clear_flags;
- hythread_jlm_monitor_init;
- hythread_jlm_thread_init;
- hythread_jlm_gc_lock_init;
- hythread_jlm_get_gc_lock_tracing;
- hythread_monitor_get_tracing;
- hythread_get_user_time;
- hythread_get_cpu_time;
- hythread_get_handle;
- hythread_get_stack_size;
- hythread_get_os_priority;
- hythread_get_stack_usage;
- hythread_enable_stack_usage;
- hysem_init;
- hysem_post;
- hysem_wait;
- hysem_destroy;
+ hythread_create_library;
+ hythread_init_library;
+ hythread_shutdown_library;
+ hythread_startup_library;
+ hythread_allocate_library;
+ hythread_getSize;
+ hythread_getVersion;
+ hythread_isCompatible;
local : *;
};
Index: trunk/modules/portlib/src/main/native/thread/unix/linuxonexit.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/linuxonexit.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/linuxonexit.c (working copy)
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if defined(LINUX)
-#include "linuxonexit.h"
-
-#include
-#include
-#include
-
-#define __USE_GNU
-#include
-#undef __USE_GNU
-
-static void linux_on_exit_sig_handler PROTOTYPE ((int signum));
-static void linux_on_exit_hook PROTOTYPE ((int exit_code, void *opaque));
-static int linux_on_exit_code = -1;
-static void
-linux_on_exit_sig_handler (int signum)
-{
- /* exit without trying to cleanup (ala exit()) since thats what got us into
- * this mess in the first place */
- _exit (linux_on_exit_code);
-}
-
-static void
-linux_on_exit_hook (int exit_code, void *opaque)
-{
- sigset_t set;
- struct sigaction act;
- /**
- * Hook handler registered via on_exit(). Added as a resultion
- * for buggy linux pthread lock handling on thread exit.
- *
- * Note that this fix should be revisited/reversed on systems running NPTL
- * threads. Ie glibc 2.3+ and 2.6 series kernels. It _is_ feasible that
- * such a system could still use old linuxthreads depending on distribution.
- */
- /* Kill any previously set alarms */
- alarm (0);
-
- sigemptyset (&set);
- act.sa_handler = linux_on_exit_sig_handler;
- act.sa_flags = 0;
- act.sa_mask = set;
-
- sigaction (SIGALRM, &act, NULL);
-
- /* Unblock SIGALRM */
- sigemptyset (&set);
- sigaddset (&set, SIGALRM);
- sigprocmask (SIG_UNBLOCK, &set, NULL);
-
- /* remember the correct exit code, to be passed to _exit() in case we dead lock */
- linux_on_exit_code = exit_code;
-
- /* signal an alarm in N seconds, ie thats how long we've got to exit */
- alarm (5);
-}
-
-void
-linux_set_on_exit_hook (void)
-{
- Dl_info dl_info;
- int dl_result;
- return;
- dl_result = dladdr ((void *) linux_on_exit_hook, &dl_info);
- if (dl_result)
- {
- /* best effort case, try to dlopen the .so where our on exit hook code resides.
- * This is done in order to prevent it from ever being unloaded once the .so usage
- * reference counter drops to zero. This dlopen will incrament it (we never close it)
- * thus never allowing an unload to occur */
- dlopen (dl_info.dli_fname, RTLD_LAZY);
- }
- on_exit (linux_on_exit_hook, NULL);
-}
-#endif
-
-static void
-toAvoidCompilerWarnings (void)
-{
- /* As stated. This is a common file for Unix platforms.
- The alternative is to change all makefile generators */
- return;
-}
Index: trunk/modules/portlib/src/main/native/thread/unix/linuxonexit.h
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/linuxonexit.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/linuxonexit.h (working copy)
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if !defined(linuxonexit_h)
-#define linuxonexit_h
-
-#include "hycomp.h"
-
-static void toAvoidCompilerWarnings PROTOTYPE ((void));
-void linux_set_on_exit_hook PROTOTYPE ((void));
-
-#endif /* linuxonexit_h */
Index: trunk/modules/portlib/src/main/native/thread/unix/makefile
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/makefile (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/makefile (working copy)
@@ -22,12 +22,8 @@
CFLAGS += -fpic
BUILDFILES = \
- $(SHAREDSUB)thread_copyright.o $(HY_ARCH)/thrhelp.o $(HY_ARCH)/thrspinlock.o \
- $(SHAREDSUB)hythread.o $(SHAREDSUB)hythreadinspect.o linuxonexit.o priority.o \
- rasthrsup.o $(SHAREDSUB)rwmutex.o thrcreate.o thrdsup.o $(SHAREDSUB)thrprof.o
+ $(SHAREDSUB)hythread.o
-OSLIBS += -lpthread
-MDLLIBFILES = $(LIBPATH)libhypool.a $(LIBPATH)libhycommon.a
DLLNAME = ../libhythr.so
include $(HY_HDK)/build/make/rules.mk
Index: trunk/modules/portlib/src/main/native/thread/unix/priority.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/priority.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/priority.c (working copy)
@@ -1,135 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "thrdsup.h"
-
-#include /* must be after or DECUNIX kaks */
-
-#include
-
-static int min, max;
-
-#if defined(HY_PRIORITY_MAP)
-const int priority_map[HYTHREAD_PRIORITY_MAX + 1] = HY_PRIORITY_MAP;
-#else
-int priority_map[HYTHREAD_PRIORITY_MAX + 1];
-void
-initialize_priority_map (void)
-{
- int policy, rc;
- policy = HY_DEFAULT_SCHED;
- initialize_priority_range (0, HYTHREAD_PRIORITY_MAX, policy);
-}
-
-void
-initialize_priority_range (int range_start, int range_end, int policy)
-{
- int delta, i, tmpmax, tmpmin, mid, midrange, tailcount;
- max = sched_get_priority_max (policy);
- min = sched_get_priority_min (policy);
- if (max == min)
- {
- /* get this thread's priority and use that for all threads */
- struct sched_param schedParam;
- int currPolicy;
- int rv =
- pthread_getschedparam (pthread_self (), &currPolicy, &schedParam);
- max = schedParam.sched_priority;
- min = max;
- }
- /* give us some room to do some math */
- tmpmax = max * 1024;
- tmpmin = min * 1024;
- mid = (tmpmin + tmpmax) / 2;
- midrange = range_start + (range_end - range_start) / 2;
- priority_map[range_start] = min;
- delta = (mid - tmpmin) / midrange;
- for (i = 1; i < midrange; i++)
- {
- priority_map[midrange - i] = (mid - delta * i) / 1024;
- }
- tailcount = range_end - midrange;
- delta = (tmpmax - mid) / tailcount;
- for (i = 0; i < tailcount; i++)
- {
- priority_map[midrange + i] = (mid + delta * i) / 1024;;
- }
- priority_map[range_end] = max;
-#if defined(DEBUG)
- for (i = range_start; i <= range_end; i++)
- {
- printf ("prio %d: %d\n", i, priority_map[i]);
- }
-#endif
-}
-#endif
-
-IDATA
-set_pthread_priority (pthread_t handle, IDATA priority)
-{
- struct sched_param sched_param;
- int policy, rc;
-
- policy = HY_DEFAULT_SCHED;
- sched_param.sched_priority = priority;
- rc = pthread_setschedparam (handle, policy, &sched_param);
- return rc;
-}
-
-void
-initialize_thread_priority (hythread_t thread)
-{
- int policy, priority, i;
- struct sched_param sched_param;
-
- /* set the default value */
- thread->priority = HYTHREAD_PRIORITY_NORMAL;
-
- /* are we using priorities at all? */
- if (priority_map[HYTHREAD_PRIORITY_MIN] ==
- priority_map[HYTHREAD_PRIORITY_MAX])
- return;
-
- if (pthread_getschedparam (thread->handle, &policy, &sched_param))
- {
- /* the call failed */
- return;
- }
-
- if (policy != HY_DEFAULT_SCHED)
- {
- /* printf ("Policy isn't SCHED_OTHER!\n"); */
- /* what to do?? */
- return;
- }
-
- /* on some platforms (i.e. Solaris) we get out of range values (e.g. 0) for threads with no explicitly set priority */
- if (sched_param.sched_priority < min || sched_param.sched_priority > max)
- {
- return;
- }
-
- priority = sched_param.sched_priority;
- for (i = HYTHREAD_PRIORITY_MIN; i <= HYTHREAD_PRIORITY_MAX; i++)
- {
- if (priority <= priority_map[i])
- {
- thread->priority = i;
- return;
- }
- }
-}
Index: trunk/modules/portlib/src/main/native/thread/unix/priority.h
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/priority.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/priority.h (working copy)
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if !defined(priority_h)
-#define priority_h
-#include "thrdsup.h"
-void initialize_priority_map PROTOTYPE ((void));
-void initialize_priority_range
-PROTOTYPE ((int range_start, int range_end, int policy));
-void initialize_thread_priority PROTOTYPE ((hythread_t thread));
-IDATA set_pthread_priority PROTOTYPE ((pthread_t handle, IDATA priority));
-#endif /* priority_h */
Index: trunk/modules/portlib/src/main/native/thread/unix/rasthrsup.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/rasthrsup.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/rasthrsup.c (working copy)
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "rasthrsup.h"
-
-#include
-
-#include "hycomp.h"
-
-UDATA
-Unix_GetKernelThreadID (void)
-{
- pthread_t myThread = pthread_self ();
-
- /*
- * Convert the local pthread_t variable, which could be a structure or a scalar value, into a UDATA
- * by getting its address, casting that to a UDATA pointer and then dereferencing to get the value
- *
- * The result seems to match the thread id observed in GDB...
- */
- if (sizeof (pthread_t) >= sizeof (UDATA))
- {
- return *((UDATA *) & myThread);
- }
- else
- {
- return 0;
- }
-}
Index: trunk/modules/portlib/src/main/native/thread/unix/rasthrsup.h
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/rasthrsup.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/rasthrsup.h (working copy)
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if !defined(rasthrsup_h)
-#define rasthrsup_h
-/* RAS_THREAD_ID */
-#define RAS_THREAD_ID() Unix_GetKernelThreadID()
-#endif /* rasthrsup_h */
Index: trunk/modules/portlib/src/main/native/thread/unix/thrcreate.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/thrcreate.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/thrcreate.c (working copy)
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "thrcreate.h"
-
-#include /* for printf */
-#include /* for abort */
-#include /* for PTHREAD_STACK_MIN */
-#if defined(LINUX)
-#include "linuxonexit.h"
-#endif
-
-#include "hythread.h"
-
-IDATA
-create_pthread (pthread_t * handle, UDATA stacksize, UDATA priority,
- entrypoint_t entrypoint, void *entryarg)
-{
- pthread_attr_t attr;
- struct sched_param sched_param;
- IDATA retCode;
-#if defined(LINUX)
- static int linux_on_exit_hook_set = 0;
-#endif
-
- if (pthread_attr_init (&attr) != 0)
- return -1;
-
- /* verify that there are no extra fields in sched_param! This should be optimized out by any half decent compiler */
- if (sizeof (sched_param) != sizeof (sched_param.sched_priority))
- {
- printf ("Assertion failed %s:%d\n", __FILE__, __LINE__);
- abort ();
- }
-
- sched_param.sched_priority = priority;
- pthread_attr_setschedparam (&attr, &sched_param);
-
-/* Linux allocates 2MB if you ask for a stack smaller than STACK_MIN */
-#if defined(LINUX)
- if (stacksize < PTHREAD_STACK_MIN)
- stacksize = PTHREAD_STACK_MIN;
-#endif
-
- pthread_attr_setstacksize (&attr, stacksize);
-
- retCode = pthread_create (handle, &attr, entrypoint, entryarg);
-
-#if defined(LINUX)
- if (!linux_on_exit_hook_set)
- {
- linux_set_on_exit_hook ();
- linux_on_exit_hook_set = 1;
- }
-#endif
-
- return retCode;
-}
Index: trunk/modules/portlib/src/main/native/thread/unix/thrcreate.h
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/thrcreate.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/thrcreate.h (working copy)
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if !defined(thrcreate_h)
-#define thrcreate_h
-#include
-#include "hycomp.h"
-typedef void *(*entrypoint_t) (void *);
-IDATA create_pthread
-PROTOTYPE ((pthread_t * handle, UDATA stacksize, UDATA priority,
- entrypoint_t entrypoint, void *entryarg));
-#endif /* thrcreate_h */
Index: trunk/modules/portlib/src/main/native/thread/unix/thrdsup.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/thrdsup.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/thrdsup.c (working copy)
@@ -1,146 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include
-#include
-#include "hycomp.h"
-#include "hymutex.h"
-/* ostypes */
-
-typedef pthread_t OSTHREAD;
-typedef pthread_key_t TLSKEY;
-typedef pthread_cond_t COND;
-#define WRAPPER_TYPE void*
-typedef void *WRAPPER_ARG;
-#define WRAPPER_RETURN() return NULL
-#if defined(LINUX)
-#include
-typedef sem_t OSSEMAPHORE;
-#else
-
-typedef IDATA OSSEMAPHORE;
-
-#endif
-
-#include "thrtypes.h"
-
-#if defined(LINUX) && defined(HYX86)
-#include
-#endif
-
-#if !defined(HY_PRIORITY_MAP)
-extern void initialize_priority_map (void);
-#endif
-
-int linux_pthread_cond_timedwait
-PROTOTYPE ((pthread_cond_t * cond, pthread_mutex_t * mutex,
- const struct timespec * abstime));
-IDATA VMCALL hythread_sigthreadmask_sigQuit PROTOTYPE ((void));
-IDATA init_thread_library PROTOTYPE ((void));
-IDATA VMCALL hythread_signalThread_sigQuit
-PROTOTYPE ((hythread_t sigQuitThread));
-IDATA VMCALL hythread_sigwait_sigQuit PROTOTYPE ((int *sig));
-IDATA nto_cond_init PROTOTYPE ((pthread_cond_t * cond));
-
-IDATA VMCALL sem_getvalue_zos PROTOTYPE ((hysem_t s));
-IDATA VMCALL sem_init_zos PROTOTYPE ((hysem_t s, int pShared, int initValue));
-IDATA VMCALL sem_trywait_aix PROTOTYPE ((hysem_t s));
-void call_hythread_init PROTOTYPE ((void));
-IDATA VMCALL sem_wait_zos PROTOTYPE ((hysem_t s));
-IDATA VMCALL sem_trywait_zos PROTOTYPE ((hysem_t s));
-IDATA VMCALL sem_wait_aix PROTOTYPE ((hysem_t s));
-IDATA VMCALL sem_init_aix PROTOTYPE ((hysem_t s, int pShared, int initValue));
-IDATA VMCALL sem_post_zos PROTOTYPE ((hysem_t s));
-IDATA VMCALL sem_post_aix PROTOTYPE ((hysem_t s));
-IDATA VMCALL sem_destroy_aix PROTOTYPE ((hysem_t s));
-
-void VMCALL hythread_init (struct HyThreadLibrary *lib);
-void VMCALL hythread_shutdown (void);
-
-struct HyThreadLibrary default_library;
-
-pthread_once_t init_once = PTHREAD_ONCE_INIT;
-
-void
-call_hythread_init (void)
-{
- hythread_library_t lib = GLOBAL_DATA (default_library);
-
-#if !defined(HY_PRIORITY_MAP)
- initialize_priority_map ();
-#endif
-
- hythread_init (lib);
-}
-
-IDATA
-init_thread_library (void)
-{
- hythread_library_t lib = GLOBAL_DATA (default_library);
- pthread_once (&init_once, call_hythread_init);
-
- return lib->initStatus != 1;
-}
-
-#if defined(LINUX) && defined(HYX86)
-int
-linux_pthread_cond_timedwait (pthread_cond_t * cond, pthread_mutex_t * mutex,
- const struct timespec *abstime)
-{
- /* This is a wrapper around the pthread_cond_timedwait which restores the
- fpu control word. The libpthread-0.9 version pthread_cond_timedwait on return resets the fpu control word to 0x37f
- */
-
- int rValue, oldCW;
- _FPU_GETCW (oldCW);
- rValue = pthread_cond_timedwait (cond, mutex, abstime);
- oldCW &= 0xffff;
- _FPU_SETCW (oldCW);
- return rValue;
-}
-#endif
-
-#include
-/* waits for SIGQUIT to arrive
- Used by the dedicated SIGQUIT handler thread
-*/
-IDATA VMCALL
-hythread_sigwait_sigQuit (int *sig)
-{
-
- return 0;
-}
-
-/* Block all signals except SIGQUIT
- Used by the dedicated SIGQUIT handler thread
-*/
-IDATA VMCALL
-hythread_sigthreadmask_sigQuit (void)
-{
-
- return 0;
-}
-
-/*
- Used to send a signal to a specific thread
-*/
-IDATA VMCALL
-hythread_signalThread_sigQuit (hythread_t sigQuitThread)
-{
-
- return 0;
-}
Index: trunk/modules/portlib/src/main/native/thread/unix/thrdsup.h
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/thrdsup.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/thrdsup.h (working copy)
@@ -1,258 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if !defined(thrdsup_h)
-#define thrdsup_h
-#define HY_POSIX_THREADS
-#include
-#include
-#include
-#include
-#include
-#include
-#include "hycomp.h"
-
-#if (defined(LINUX))
-#include
-#endif
-
-#include "hymutex.h"
-/* ostypes */
-typedef pthread_t OSTHREAD;
-typedef pthread_key_t TLSKEY;
-typedef pthread_cond_t COND;
-#define WRAPPER_TYPE void*
-typedef void *WRAPPER_ARG;
-#define WRAPPER_RETURN() return NULL
-#if defined(LINUX) || defined(FREEBSD)
-#include
-typedef sem_t OSSEMAPHORE;
-#else
-
-typedef IDATA OSSEMAPHORE;
-
-#endif
-#include "thrtypes.h"
-#include "priority.h"
-#include "thrcreate.h"
-
-int linux_pthread_cond_timedwait
-PROTOTYPE ((pthread_cond_t * cond, pthread_mutex_t * mutex,
- const struct timespec * abstime));
-IDATA VMCALL hythread_sigthreadmask_sigQuit PROTOTYPE ((void));
-IDATA init_thread_library PROTOTYPE ((void));
-IDATA VMCALL hythread_signalThread_sigQuit
-PROTOTYPE ((hythread_t sigQuitThread));
-IDATA VMCALL hythread_sigwait_sigQuit PROTOTYPE ((int *sig));
-IDATA nto_cond_init PROTOTYPE ((pthread_cond_t * cond));
-extern struct HyThreadLibrary default_library;
-/* priority_map */
-#if defined(HY_PRIORITY_MAP)
-extern const int priority_map[];
-#else
-extern int priority_map[];
-#endif
-
-/* SETUP_TIMEOUT */
-
-#define HYDIV_T div_t
-#define HYDIV div
-/* do we really need nanosecond clock accuracy even on platforms which support gettime? */
-
-#define TIMEOUT_CLOCK CLOCK_REALTIME
-
-#if (defined(LINUX))
-#define SETUP_TIMEOUT(ts_, millis, nanos) { \
- struct timeval tv_; \
- HYDIV_T secs_ = HYDIV(millis, 1000); \
- int nanos_ = secs_.rem * 1000000 + nanos; \
- gettimeofday(&tv_, NULL); \
- nanos_ += tv_.tv_usec * 1000; \
- if (nanos_ >= 1000000000) { \
- ts_.tv_sec = tv_.tv_sec + secs_.quot + 1; \
- ts_.tv_nsec = nanos_ - 1000000000; \
- } else { \
- ts_.tv_sec = tv_.tv_sec + secs_.quot; \
- ts_.tv_nsec = nanos_; \
- } }
-#elif defined(HYOSE)
-#define SETUP_TIMEOUT(ts_, millis, nanos) { \
- struct TimePair tvp; \
- HYDIV_T secs_ = HYDIV(millis, 1000); \
- int nanos_ = secs_.rem * 1000000 + nanos; \
- rtc_get_time(&tvp); \
- nanos_ += tvp.micros * 1000; \
- if (nanos_ >= 1000000000) { \
- ts_.tv_sec = tvp.seconds + secs_.quot + 1; \
- ts_.tv_nsec = nanos_ - 1000000000; \
- } else { \
- ts_.tv_sec = tvp.seconds + secs_.quot; \
- ts_.tv_nsec = nanos_; \
- } }
-#else
-#define SETUP_TIMEOUT(ts_, millis, nanos) { \
- HYDIV_T secs_ = HYDIV(millis, 1000); \
- int nanos_ = secs_.rem * 1000000 + nanos; \
- clock_gettime(TIMEOUT_CLOCK, &ts_); \
- nanos_ += ts_.tv_nsec; \
- if (nanos_ >= 1000000000) { \
- ts_.tv_sec += secs_.quot + 1; \
- ts_.tv_nsec = nanos_ - 1000000000; \
- } else { \
- ts_.tv_sec += secs_.quot; \
- ts_.tv_nsec = nanos_; \
- } }
-#endif
-
-/* COND_DESTROY */
-#define COND_DESTROY(cond) pthread_cond_destroy(&(cond))
-
-/* TLS_GET */
-#define TLS_GET(key) (pthread_getspecific(key))
-
-/* TLS_ALLOC */
-#define TLS_ALLOC(key) (pthread_key_create(&key, NULL))
-
-/* TLS_SET */
-#define TLS_SET(key, value) (pthread_setspecific(key, value))
-
-/* COND_WAIT */
-/* NOTE: the calling thread must already own mutex */
-/* NOTE: a timeout less than zero indicates infinity */
-#define COND_WAIT(cond, mutex) \
- do { \
- pthread_cond_wait(&(cond), &(mutex))
-#define COND_WAIT_LOOP() } while(1)
-
-/* THREAD_SELF */
-#define THREAD_SELF() (pthread_self())
-
-/* THREAD_YIELD */
-#if defined(LINUX) || defined(FREEBSD)
-#define THREAD_YIELD() (sched_yield())
-#endif
-
-#if defined(LINUX) && defined(HARDHAT)
-#undef THREAD_YIELD /* undo the one defined above */
-#define THREAD_YIELD() (usleep(0))
-#endif
-
-/* last chance. If it's not defined by now, use yield */
-#if !defined(THREAD_YIELD)
-#define THREAD_YIELD() (yield())
-#endif
-
-/* THREAD_CREATE */
-#define THREAD_CREATE(thread, stacksize, priority, entrypoint, entryarg) \
- (create_pthread(&(thread)->handle, (stacksize), priority_map[(priority)], (entrypoint), (entryarg)) == 0)
-
-/* THREAD_CANCEL */
-/* pthread_cancel is asynchronous. Use join to wait for it to complete */
-#define THREAD_CANCEL(thread) (pthread_cancel(thread) || pthread_join(thread, NULL))
-
-/* COND_NOTIFY_ALL */
-#define COND_NOTIFY_ALL(cond) pthread_cond_broadcast(&(cond))
-
-/* COND_WAIT_IF_TIMEDOUT */
-/* NOTE: the calling thread must already own the mutex! */
-#if defined(LINUX) && defined(HYX86)
-#define PTHREAD_COND_TIMEDWAIT(x,y,z) linux_pthread_cond_timedwait(x,y,z)
-#else
-#define PTHREAD_COND_TIMEDWAIT(x,y,z) pthread_cond_timedwait(x,y,z)
-#endif
-
-#define COND_WAIT_RC_TIMEDOUT ETIMEDOUT
-
-#define COND_WAIT_IF_TIMEDOUT(cond, mutex, millis, nanos) \
- do { \
- struct timespec ts_; \
- SETUP_TIMEOUT(ts_, millis, nanos); \
- while (1) { \
- if (PTHREAD_COND_TIMEDWAIT(&(cond), &(mutex), &ts_) == COND_WAIT_RC_TIMEDOUT)
-
-#define COND_WAIT_TIMED_LOOP() } } while(0)
-
-/* COND_INIT */
-#define COND_INIT(cond) (pthread_cond_init(&(cond), NULL) == 0)
-
-/* TLS_DESTROY */
-#define TLS_DESTROY(key) (pthread_key_delete(key))
-
-/* THREAD_EXIT */
-#define THREAD_EXIT() pthread_exit(NULL)
-
-/* THREAD_DETACH */
-#define THREAD_DETACH(thread) pthread_detach(thread)
-
-/* THREAD_SET_PRIORITY */
-#define THREAD_SET_PRIORITY(thread, priority) set_pthread_priority((thread), (priority))
-
-/* SEM_CREATE */
-#if defined(LINUX) || defined(FREEBSD)
-#define SEM_CREATE(initValue) thread_malloc(NULL, sizeof(OSSEMAPHORE))
-#else
-#define SEM_CREATE(initValue)
-#endif
-
-/* SEM_INIT */
-#if defined(LINUX) || defined(FREEBSD)
-#define SEM_INIT(sm, pshrd, inval) (sem_init((sem_t*)sm, pshrd, inval))
-#else
-#define SEM_INIT(sm,pshrd,inval)
-#endif
-
-/* SEM_DESTROY */
-#if defined(LINUX) || defined(FREEBSD)
-#define SEM_DESTROY(sm) (sem_destroy((sem_t*)sm))
-#else
-#define SEM_DESTROY(sm)
-#endif
-
-/* SEM_FREE */
-#if defined(LINUX) || defined(FREEBSD)
-#define SEM_FREE(s) thread_free(NULL, (sem_t*)s);
-#endif
-
-/* SEM_POST */
-#if defined(LINUX) || defined(FREEBSD)
-#define SEM_POST(smP) (sem_post((sem_t*)smP))
-#else
-#define SEM_POST(sm)
-#endif
-
-/* SEM_WAIT */
-#if defined(LINUX) || defined(FREEBSD)
-#define SEM_WAIT(smP) (sem_wait((sem_t*)smP))
-#else
-#define SEM_WAIT(sm)
-#endif
-
-/* SEM_TRYWAIT */
-#if defined(LINUX) || defined(FREEBSD)
-#define SEM_TRYWAIT(smP) (sem_trywait(smP))
-#else
-#define SEM_TRYWAIT(sm)
-#endif
-
-/* SEM_GETVALUE */
-#if defined(LINUX) || defined(FREEBSD)
-#define SEM_GETVALUE(smP, intP) (sem_getvalue(smP, intP))
-#else
-#define SEM_GETVALUE(sm)
-#endif
-
-#endif /* thrdsup_h */
Index: trunk/modules/portlib/src/main/native/thread/unix/thrtypes.h
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/thrtypes.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/thrtypes.h (working copy)
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if !defined(THRTYPES_H)
-#define THRTYPES_H
-#if defined(__cplusplus)
-extern "C"
-{
-#endif
-#include "hythread.h"
- typedef struct HyThread
- {
- struct HyThreadLibrary *library;
- UDATA attachcount;
- UDATA priority;
- struct HyThreadMonitor *monitor;
- struct HyThread *next;
- void *tls[128];
- hythread_entrypoint_t entrypoint;
- void *entryarg;
- UDATA flags;
- UDATA tid;
- struct HyThread *interrupter;
- OSTHREAD handle;
- COND condition;
- MUTEX mutex;
- UDATA stacksize;
- UDATA *tos;
- void *jumpBuffer;
- } HyThread;
- typedef struct HyThreadMonitor
- {
- UDATA count;
- struct HyThread *owner;
- struct HyThread *waiting;
- UDATA flags;
- UDATA userData;
- struct HyThreadMonitorTracing *tracing;
- char *name;
- UDATA pinCount;
- UDATA antiDeflationCount;
- UDATA proDeflationCount;
- UDATA spinlockState;
- UDATA lockingWord;
- UDATA spinCount1;
- UDATA spinCount2;
- UDATA spinCount3;
- struct HyThread *blocking;
- MUTEX mutex;
- } HyThreadMonitor;
- typedef struct HyThreadMonitorPool
- {
- struct HyThreadMonitorPool *next;
- struct HyThreadMonitor *next_free;
- struct HyThreadMonitor entries[64];
- } HyThreadMonitorPool;
-#define MONITOR_POOL_SIZE 64
- typedef struct HyThreadGlobal
- {
- struct HyThreadGlobal *next;
- char *name;
- UDATA data;
- } HyThreadGlobal;
- typedef struct HyThreadLibrary
- {
- UDATA spinlock;
- struct HyThreadMonitorPool *monitor_pool;
- struct HyPool *thread_pool;
- UDATA threadCount;
- UDATA stack_usage;
- IDATA initStatus;
- UDATA flags;
- struct HyThreadMonitorTracing *gc_lock_tracing;
- struct HyThreadGlobal *globals;
- struct HyPool *global_pool;
- MUTEX global_mutex;
- TLSKEY self_ptr;
- MUTEX monitor_mutex;
- MUTEX tls_mutex;
- hythread_tls_finalizer_t tls_finalizers[128];
- char *thread_weight;
- struct HyPool *monitor_tracing_pool;
- struct HyPool *thread_tracing_pool;
- } HyThreadLibrary;
-#define HYTHREAD_LIB_FLAG_JLMHST_ENABLED 0x10000
-#define HYTHREAD_LIB_FLAG_JLM_ENABLED 0x4000
-#define HYTHREAD_LIB_FLAG_JLM_ENABLED_ALL 0x1C000
-#define HYTHREAD_LIB_FLAG_JLM_HAS_BEEN_ENABLED 0x20000
-#define HYTHREAD_LIB_FLAG_JLMTS_ENABLED 0x8000
- typedef struct HySemaphore
- {
- OSSEMAPHORE sem;
- } HySemaphore;
-#define STACK_DEFAULT_SIZE 0x8000
-#define FREE_TAG ((UDATA)-1)
- typedef struct HyThreadMonitorPool *hythread_monitor_pool_t;
- typedef struct HyThreadLibrary *hythread_library_t;
-#if defined(__cplusplus)
-}
-#endif
-#endif /* THRTYPES_H */
Index: trunk/modules/portlib/src/main/native/thread/unix/x86/thrhelp.s
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/x86/thrhelp.s (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/x86/thrhelp.s (working copy)
@@ -1,123 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-eq_hy_null = 0
-eq_HyThreadMonitor_pinCount = 28
-eq_pointer_size = 4
-eqS_current_stack_depth = 16
-eqS_hythread_monitor_pin = 16
-eqS_hythread_monitor_unpin = 16
-eqSR_current_stack_depth = 4
-eqSR_hythread_monitor_pin = 4
-eqSR_hythread_monitor_unpin = 4
-eqSRS_current_stack_depth = 16
-eqSRS_hythread_monitor_pin = 16
-eqSRS_hythread_monitor_unpin = 16
-eqSS_current_stack_depth = 64
-eqSS_hythread_monitor_pin = 64
-eqSS_hythread_monitor_unpin = 64
- #CODE32 SEGMENT FLAT PUBLIC 'CODE'
- #assume cs:flat,ds:flat,ss:flat
- #CODE32 ends
- #CODE32 SEGMENT FLAT PUBLIC 'CODE'
- #assume cs:flat,ds:flat,ss:flat
- .globl hythread_monitor_pin
- .type hythread_monitor_pin,@function
- .globl current_stack_depth
- .type current_stack_depth,@function
- .globl hythread_monitor_unpin
- .type hythread_monitor_unpin,@function
-
- .text
- .align 4
-current_stack_depth:
- push %ebp
- mov %esp, %ebp
- push %esi
- push %edi
- push %ebx
- sub $64, %esp
- movl %ebp, %ebx
- jmp .L2
-.L1:
- movl %ecx, %ebx
-.L2:
- movl (%ebx), %ecx
- testl %ecx, %ecx ## setFlags: true
- jnz .L1
- subl %ebp, %ebx
- movl %ebx, %ecx
- movl %ebx, %eax ## RegReg opt
- add $64, %esp
- pop %ebx
- pop %edi
- pop %esi
- pop %ebp
- ret
-END_current_stack_depth:
- .size current_stack_depth,END_current_stack_depth - current_stack_depth
-
-## Prototype: void hythread_monitor_pin( hythread_monitor_t monitor, hythread_t osThread);
-## Defined in: #THREAD Args: 2
-
- .text
- .align 4
-hythread_monitor_pin:
- push %ebp
- mov %esp, %ebp
- push %esi
- push %edi
- push %ebx
- sub $64, %esp
- movl (eqSRS_hythread_monitor_pin+0+8+eqSS_hythread_monitor_pin)(%esp), %ebx
- movl (eqSRS_hythread_monitor_pin+0+4+eqSS_hythread_monitor_pin)(%esp), %ebx
- lock
- incl eq_HyThreadMonitor_pinCount(%ebx) ## (Converted add 1 to inc)
- add $64, %esp
- pop %ebx
- pop %edi
- pop %esi
- pop %ebp
- ret
-END_hythread_monitor_pin:
- .size hythread_monitor_pin,END_hythread_monitor_pin - hythread_monitor_pin
-
-## Prototype: void hythread_monitor_unpin( hythread_monitor_t monitor, hythread_t osThread);
-## Defined in: #THREAD Args: 2
-
- .text
- .align 4
-hythread_monitor_unpin:
- push %ebp
- mov %esp, %ebp
- push %esi
- push %edi
- push %ebx
- sub $64, %esp
- movl (eqSS_hythread_monitor_unpin+0+8+eqSRS_hythread_monitor_unpin)(%esp), %ebx
- movl (eqSS_hythread_monitor_unpin+0+eqSRS_hythread_monitor_unpin+4)(%esp), %ebx
- lock
- decl eq_HyThreadMonitor_pinCount(%ebx) ## (Converted subtract 1 to dec)
- add $64, %esp
- pop %ebx
- pop %edi
- pop %esi
- pop %ebp
- ret
-END_hythread_monitor_unpin:
- .size hythread_monitor_unpin,END_hythread_monitor_unpin - hythread_monitor_unpin
-
- #CODE32 ends
- # end of file
Index: trunk/modules/portlib/src/main/native/thread/unix/x86/thrspinlock.s
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/x86/thrspinlock.s (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/x86/thrspinlock.s (working copy)
@@ -1,132 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-eq_HyThreadAbstractMonitor_spinCount1 = 48
-eq_HyThreadAbstractMonitor_spinCount2 = 52
-eq_HyThreadAbstractMonitor_spinCount3 = 56
-eq_HyThreadAbstractMonitor_spinlockState = 40
-eq_pointer_size = 4
-eqS_hythread_spinlock_acquire = 18
-eqS_hythread_spinlock_swapState = 16
-eqSR_hythread_spinlock_acquire = 4
-eqSR_hythread_spinlock_swapState = 4
-eqSRS_hythread_spinlock_acquire = 16
-eqSRS_hythread_spinlock_swapState = 16
-eqSS_hythread_spinlock_acquire = 72
-eqSS_hythread_spinlock_swapState = 64
-HYTHREAD_MONITOR_SPINLOCK_OWNED = 1
-HYTHREAD_MONITOR_SPINLOCK_UNOWNED = 0
- #CODE32 SEGMENT FLAT PUBLIC 'CODE'
- #assume cs:flat,ds:flat,ss:flat
- #CODE32 ends
- #CODE32 SEGMENT FLAT PUBLIC 'CODE'
- #assume cs:flat,ds:flat,ss:flat
- .globl hythread_yield # an extern
- .globl hythread_spinlock_acquire
- .type hythread_spinlock_acquire,@function
- .globl hythread_spinlock_swapState
- .type hythread_spinlock_swapState,@function
-## Prototype: IDATA hythread_spinlock_acquire(hythread_t self, hythread_monitor_t monitor);
-## Defined in: #THREAD Args: 2
-
- .text
- .align 4
-hythread_spinlock_acquire:
- push %ebp
- mov %esp, %ebp
- push %esi
- push %edi
- push %ebx
- sub $72, %esp
- movl (eqSS_hythread_spinlock_acquire+0+eqSRS_hythread_spinlock_acquire+8)(%esp), %edx
- movl eq_HyThreadAbstractMonitor_spinCount3(%edx), %ecx
-.L2:
- movl eq_HyThreadAbstractMonitor_spinCount2(%edx), %ebx
-.L3:
-## Try to cmpxchg 0 into the target field (-1 indicates free)
- cmpl $HYTHREAD_MONITOR_SPINLOCK_UNOWNED, eq_HyThreadAbstractMonitor_spinlockState(%edx) ## setFlags: true
- jne .L10
- xor %eax, %eax
- movl $HYTHREAD_MONITOR_SPINLOCK_OWNED, %esi
- lock
- cmpxchgl %esi, eq_HyThreadAbstractMonitor_spinlockState(%edx)
- testl %eax, %eax ## setFlags: true
- jnz .L10
- xor %ebx, %ebx
- jmp .L1
-.L10:
- .word 37107 ## PAUSE
-## begin tight loop
- movl eq_HyThreadAbstractMonitor_spinCount1(%edx), %eax
-.L11:
-## inside tight loop
- decl %eax ## setFlags: true(Converted subtract 1 to dec)
- jnz .L11
-## end tight loop
- decl %ebx ## setFlags: true(Converted subtract 1 to dec)
- jnz .L3
- movl %ecx, 64(%esp) ## save VMtemp3_1_3_(HyThreadAbstractMonitor->spinCount3)
- movl %edx, 68(%esp) ## save VMtemp3_1_2_(struct HyThreadAbstractMonitor*) in_HyVMThreadSpinlocks>>#hythread_spinlock_acquire
- call hythread_yield
- movl 64(%esp), %ecx ## load VMtemp3_1_3_(HyThreadAbstractMonitor->spinCount3)
- decl %ecx ## setFlags: true(Converted subtract 1 to dec)
- movl 68(%esp), %edx ## load VMtemp3_1_2_(struct HyThreadAbstractMonitor*) in_HyVMThreadSpinlocks>>#hythread_spinlock_acquire
- jnz .L2
- movl $-1, %ebx
-.L1:
- movl %ebx, %eax
- add $72, %esp
- pop %ebx
- pop %edi
- pop %esi
- pop %ebp
- ret
-END_hythread_spinlock_acquire:
- .size hythread_spinlock_acquire,END_hythread_spinlock_acquire - hythread_spinlock_acquire
-
-## Prototype: UDATA hythread_spinlock_swapState(hythread_monitor_t monitor, UDATA newState);
-## Defined in: #THREAD Args: 2
-
- .text
- .align 4
-hythread_spinlock_swapState:
- push %ebp
- mov %esp, %ebp
- push %esi
- push %edi
- push %ebx
- sub $64, %esp
- movl (eqSS_hythread_spinlock_swapState+0+eqSRS_hythread_spinlock_swapState+4)(%esp), %ebx
- movl (eqSS_hythread_spinlock_swapState+0+eqSRS_hythread_spinlock_swapState+8)(%esp), %ecx
-## If we are writing in UNOWNED, we are exiting the critical section, therefore
-## have to finish up any writes
- testl %ecx, %ecx ## setFlags: true
- ## memory barrier (no code necessary for write barriers)
- xchgl %ecx, eq_HyThreadAbstractMonitor_spinlockState(%ebx)
-## if we entered the critical section, (i.e. we swapped out UNOWNED) then
-## we have to issue a readBarrier
- testl %ecx, %ecx ## setFlags: true
- movl %ecx, %eax
- add $64, %esp
- pop %ebx
- pop %edi
- pop %esi
- pop %ebp
- ret
-END_hythread_spinlock_swapState:
- .size hythread_spinlock_swapState,END_hythread_spinlock_swapState - hythread_spinlock_swapState
-
- #CODE32 ends
- # end of file
Index: trunk/modules/portlib/src/main/native/thread/unix/x86_64/thrhelp.s
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/x86_64/thrhelp.s (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/x86_64/thrhelp.s (working copy)
@@ -1,123 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-eq_hy_null = 0
-eq_HyThreadMonitor_pinCount = 28
-eq_pointer_size = 4
-eqS_current_stack_depth = 16
-eqS_hythread_monitor_pin = 16
-eqS_hythread_monitor_unpin = 16
-eqSR_current_stack_depth = 4
-eqSR_hythread_monitor_pin = 4
-eqSR_hythread_monitor_unpin = 4
-eqSRS_current_stack_depth = 16
-eqSRS_hythread_monitor_pin = 16
-eqSRS_hythread_monitor_unpin = 16
-eqSS_current_stack_depth = 64
-eqSS_hythread_monitor_pin = 64
-eqSS_hythread_monitor_unpin = 64
- #CODE32 SEGMENT FLAT PUBLIC 'CODE'
- #assume cs:flat,ds:flat,ss:flat
- #CODE32 ends
- #CODE32 SEGMENT FLAT PUBLIC 'CODE'
- #assume cs:flat,ds:flat,ss:flat
- .globl hythread_monitor_pin
- .type hythread_monitor_pin,@function
- .globl current_stack_depth
- .type current_stack_depth,@function
- .globl hythread_monitor_unpin
- .type hythread_monitor_unpin,@function
-
- .text
- .align 8
-current_stack_depth:
- push %rbp
- mov %rsp, %rbp
- push %rsi
- push %rdi
- push %rbx
- sub $64, %rsp
- mov %rbp, %rbx
- jmp .L2
-.L1:
- mov %rcx, %rbx
-.L2:
- mov (%rbx), %rcx
- test %rcx, %rcx ## setFlags: true
- jnz .L1
- sub %rbp, %rbx
- mov %rbx, %rcx
- mov %rbx, %rax ## RegReg opt
- add $64, %rsp
- pop %rbx
- pop %rdi
- pop %rsi
- pop %rbp
- ret
-END_current_stack_depth:
- .size current_stack_depth,END_current_stack_depth - current_stack_depth
-
-## Prototype: void hythread_monitor_pin( hythread_monitor_t monitor, hythread_t osThread);
-## Defined in: #THREAD Args: 2
-
- .text
- .align 8
-hythread_monitor_pin:
- push %rbp
- mov %rsp, %rbp
- push %rsi
- push %rdi
- push %rbx
- sub $64, %rsp
- mov (eqSRS_hythread_monitor_pin+0+8+eqSS_hythread_monitor_pin)(%rsp), %rbx
- mov (eqSRS_hythread_monitor_pin+0+4+eqSS_hythread_monitor_pin)(%rsp), %rbx
- lock
- incl eq_HyThreadMonitor_pinCount(%rbx) ## (Converted add 1 to inc)
- add $64, %rsp
- pop %rbx
- pop %rdi
- pop %rsi
- pop %rbp
- ret
-END_hythread_monitor_pin:
- .size hythread_monitor_pin,END_hythread_monitor_pin - hythread_monitor_pin
-
-## Prototype: void hythread_monitor_unpin( hythread_monitor_t monitor, hythread_t osThread);
-## Defined in: #THREAD Args: 2
-
- .text
- .align 8
-hythread_monitor_unpin:
- push %rbp
- mov %rsp, %rbp
- push %rsi
- push %rdi
- push %rbx
- sub $64, %rsp
- mov (eqSS_hythread_monitor_unpin+0+8+eqSRS_hythread_monitor_unpin)(%rsp), %rbx
- mov (eqSS_hythread_monitor_unpin+0+eqSRS_hythread_monitor_unpin+4)(%rsp), %rbx
- lock
- decl eq_HyThreadMonitor_pinCount(%rbx) ## (Converted subtract 1 to dec)
- add $64, %rsp
- pop %rbx
- pop %rdi
- pop %rsi
- pop %rbp
- ret
-END_hythread_monitor_unpin:
- .size hythread_monitor_unpin,END_hythread_monitor_unpin - hythread_monitor_unpin
-
- #CODE32 ends
- # end of file
Index: trunk/modules/portlib/src/main/native/thread/unix/x86_64/thrspinlock.s
===================================================================
--- trunk/modules/portlib/src/main/native/thread/unix/x86_64/thrspinlock.s (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/unix/x86_64/thrspinlock.s (working copy)
@@ -1,132 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-eq_HyThreadAbstractMonitor_spinCount1 = 48
-eq_HyThreadAbstractMonitor_spinCount2 = 52
-eq_HyThreadAbstractMonitor_spinCount3 = 56
-eq_HyThreadAbstractMonitor_spinlockState = 40
-eq_pointer_size = 4
-eqS_hythread_spinlock_acquire = 18
-eqS_hythread_spinlock_swapState = 16
-eqSR_hythread_spinlock_acquire = 4
-eqSR_hythread_spinlock_swapState = 4
-eqSRS_hythread_spinlock_acquire = 16
-eqSRS_hythread_spinlock_swapState = 16
-eqSS_hythread_spinlock_acquire = 72
-eqSS_hythread_spinlock_swapState = 64
-HYTHREAD_MONITOR_SPINLOCK_OWNED = 1
-HYTHREAD_MONITOR_SPINLOCK_UNOWNED = 0
- #CODE32 SEGMENT FLAT PUBLIC 'CODE'
- #assume cs:flat,ds:flat,ss:flat
- #CODE32 ends
- #CODE32 SEGMENT FLAT PUBLIC 'CODE'
- #assume cs:flat,ds:flat,ss:flat
- .globl hythread_yield # an extern
- .globl hythread_spinlock_acquire
- .type hythread_spinlock_acquire,@function
- .globl hythread_spinlock_swapState
- .type hythread_spinlock_swapState,@function
-## Prototype: IDATA hythread_spinlock_acquire(hythread_t self, hythread_monitor_t monitor);
-## Defined in: #THREAD Args: 2
-
- .text
- .align 8
-hythread_spinlock_acquire:
- push %rbp
- mov %rsp, %rbp
- push %rsi
- push %rdi
- push %rbx
- sub $72, %rsp
- mov (eqSS_hythread_spinlock_acquire+0+eqSRS_hythread_spinlock_acquire+8)(%rsp), %rdx
- mov eq_HyThreadAbstractMonitor_spinCount3(%rdx), %rcx
-.L2:
- mov eq_HyThreadAbstractMonitor_spinCount2(%rdx), %rbx
-.L3:
-## Try to cmpxchg 0 into the target field (-1 indicates free)
- cmpl $HYTHREAD_MONITOR_SPINLOCK_UNOWNED, eq_HyThreadAbstractMonitor_spinlockState(%rdx) ## setFlags: true
- jne .L10
- xor %rax, %rax
- mov $HYTHREAD_MONITOR_SPINLOCK_OWNED, %rsi
- lock
- cmpxchg %rsi, eq_HyThreadAbstractMonitor_spinlockState(%rdx)
- test %rax, %rax ## setFlags: true
- jnz .L10
- xor %rbx, %rbx
- jmp .L1
-.L10:
- .word 37107 ## PAUSE
-## begin tight loop
- mov eq_HyThreadAbstractMonitor_spinCount1(%rdx), %rax
-.L11:
-## inside tight loop
- dec %rax ## setFlags: true(Converted subtract 1 to dec)
- jnz .L11
-## end tight loop
- dec %rbx ## setFlags: true(Converted subtract 1 to dec)
- jnz .L3
- mov %rcx, 64(%rsp) ## save VMtemp3_1_3_(HyThreadAbstractMonitor->spinCount3)
- mov %rdx, 68(%rsp) ## save VMtemp3_1_2_(struct HyThreadAbstractMonitor*) in_HyVMThreadSpinlocks>>#hythread_spinlock_acquire
- call hythread_yield@PLT
- mov 64(%rsp), %rcx ## load VMtemp3_1_3_(HyThreadAbstractMonitor->spinCount3)
- dec %rcx ## setFlags: true(Converted subtract 1 to dec)
- mov 68(%rsp), %rdx ## load VMtemp3_1_2_(struct HyThreadAbstractMonitor*) in_HyVMThreadSpinlocks>>#hythread_spinlock_acquire
- jnz .L2
- mov $-1, %rbx
-.L1:
- mov %rbx, %rax
- add $72, %rsp
- pop %rbx
- pop %rdi
- pop %rsi
- pop %rbp
- ret
-END_hythread_spinlock_acquire:
- .size hythread_spinlock_acquire,END_hythread_spinlock_acquire - hythread_spinlock_acquire
-
-## Prototype: UDATA hythread_spinlock_swapState(hythread_monitor_t monitor, UDATA newState);
-## Defined in: #THREAD Args: 2
-
- .text
- .align 8
-hythread_spinlock_swapState:
- push %rbp
- mov %rsp, %rbp
- push %rsi
- push %rdi
- push %rbx
- sub $64, %rsp
- mov (eqSS_hythread_spinlock_swapState+0+eqSRS_hythread_spinlock_swapState+4)(%rsp), %rbx
- mov (eqSS_hythread_spinlock_swapState+0+eqSRS_hythread_spinlock_swapState+8)(%rsp), %rcx
-## If we are writing in UNOWNED, we are exiting the critical section, therefore
-## have to finish up any writes
- test %rcx, %rcx ## setFlags: true
- ## memory barrier (no code necessary for write barriers)
- xchg %rcx, eq_HyThreadAbstractMonitor_spinlockState(%rbx)
-## if we entered the critical section, (i.e. we swapped out UNOWNED) then
-## we have to issue a readBarrier
- test %rcx, %rcx ## setFlags: true
- mov %rcx, %rax
- add $64, %rsp
- pop %rbx
- pop %rdi
- pop %rsi
- pop %rbp
- ret
-END_hythread_spinlock_swapState:
- .size hythread_spinlock_swapState,END_hythread_spinlock_swapState - hythread_spinlock_swapState
-
- #CODE32 ends
- # end of file
Index: trunk/modules/portlib/src/main/native/thread/windows/hythr.def
===================================================================
--- trunk/modules/portlib/src/main/native/thread/windows/hythr.def (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/windows/hythr.def (working copy)
@@ -5,80 +5,11 @@
.text EXECUTE READ
EXPORTS
- hythread_attach
- hythread_create
- hythread_cancel
- hythread_interrupt
- hythread_clear_interrupted
- hythread_interrupted
- hythread_priority_interrupt
- hythread_clear_priority_interrupted
- hythread_priority_interrupted
- hythread_monitor_destroy
- hythread_monitor_enter
- hythread_monitor_get_name
- hythread_monitor_enter_using_threadId
- hythread_monitor_try_enter
- hythread_monitor_try_enter_using_threadId
- hythread_monitor_exit
- hythread_monitor_exit_using_threadId
- hythread_monitor_init
- hythread_monitor_init_with_name
- hythread_monitor_notify
- hythread_monitor_notify_all
- hythread_monitor_wait
- hythread_monitor_wait_timed
- hythread_monitor_wait_interruptable
- hythread_monitor_num_waiting
- hythread_resume
- hythread_self
- hythread_set_priority
- hythread_get_priority
- hythread_sleep
- hythread_sleep_interruptable
- hythread_suspend
- hythread_tls_alloc
- hythread_tls_alloc_with_finalizer
- hythread_tls_free
- hythread_tls_get
- hythread_tls_set
- hythread_yield
- hythread_exit
- hythread_detach
- hythread_global
- hythread_get_flags
- hythread_monitor_walk
- hythread_lib_lock
- hythread_lib_unlock
- hythread_rwmutex_init
- hythread_rwmutex_destroy
- hythread_rwmutex_enter_read
- hythread_rwmutex_exit_read
- hythread_rwmutex_enter_write
- hythread_rwmutex_exit_write
- hythread_park
- hythread_unpark
- hythread_monitor_lock
- hythread_monitor_unlock
- hythread_monitor_pin
- hythread_monitor_unpin
- hythread_lib_get_flags
- hythread_lib_set_flags
- hythread_lib_clear_flags
- hythread_jlm_monitor_init
- hythread_jlm_thread_init
- hythread_jlm_gc_lock_init
- hythread_jlm_get_gc_lock_tracing
- hythread_monitor_get_tracing
- hythread_get_user_time
- hythread_get_cpu_time
- hythread_get_handle
- hythread_get_stack_size
- hythread_get_os_priority
- hythread_get_stack_usage
- hythread_enable_stack_usage
- hysem_init
- hysem_post
- hysem_wait
- hysem_destroy
-
+ hythread_create_library
+ hythread_init_library
+ hythread_shutdown_library
+ hythread_startup_library
+ hythread_allocate_library
+ hythread_getSize
+ hythread_getVersion
+ hythread_isCompatible
Index: trunk/modules/portlib/src/main/native/thread/windows/makefile
===================================================================
--- trunk/modules/portlib/src/main/native/thread/windows/makefile (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/windows/makefile (working copy)
@@ -24,9 +24,7 @@
LIBNAME=$(LIBPATH)$(LIBBASE).lib
BUILDFILES = \
- $(SHAREDSUB)thread_copyright.obj thrhelp.obj thrspinlock.obj $(SHAREDSUB)hythread.obj \
- $(SHAREDSUB)hythreadinspect.obj $(SHAREDSUB)rwmutex.obj thrdsup.obj \
- $(SHAREDSUB)thrprof.obj
+ $(SHAREDSUB)hythread.obj
# TOFIX $(LIBBASE).def should be a dependency on all libs
VIRTFILES = $(LIBBASE).res
@@ -33,8 +31,6 @@
HYCFLAGS = $(HYCFLAGS) /I$(SHAREDSUB)
HYLDFLAGS = $(HYLDFLAGS) -def:$(LIBBASE).def
-MDLLIBFILES = $(LIBPATH)hypool.lib $(LIBPATH)hycommon.lib
-
DLLBASE=0x11500000
COMMENT=/comment:"Thread support library. (c) Copyright 1993, 2005 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/portlib/src/main/native/thread/windows/rasthrsup.h
===================================================================
--- trunk/modules/portlib/src/main/native/thread/windows/rasthrsup.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/windows/rasthrsup.h (working copy)
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if !defined(rasthrsup_h)
-#define rasthrsup_h
-
-/* windows.h defined UDATA. Ignore its definition */
-#define UDATA UDATA_win32_
-#include
-#undef UDATA /* this is safe because our UDATA is a typedef, not a macro */
-#include
-
-/* RAS_THREAD_ID */
-#define RAS_THREAD_ID() GetCurrentThreadId()
-
-#endif /* rasthrsup_h */
Index: trunk/modules/portlib/src/main/native/thread/windows/thrdsup.c
===================================================================
--- trunk/modules/portlib/src/main/native/thread/windows/thrdsup.c (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/windows/thrdsup.c (working copy)
@@ -1,231 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * @file
- * @ingroup Thread
- */
-
-#include
-#include
-#include "hycomp.h"
-#include "hymutex.h"
-
-#define CDEV_CURRENT_FUNCTION ostypes
-/* ostypes */
-
-typedef HANDLE OSTHREAD;
-typedef DWORD TLSKEY;
-typedef HANDLE COND;
-
-#define WRAPPER_TYPE void _cdecl
-
-typedef void *WRAPPER_ARG;
-
-#define WRAPPER_RETURN() return
-
-typedef HANDLE OSSEMAPHORE;
-#undef CDEV_CURRENT_FUNCTION
-
-#include "thrtypes.h"
-#include "thrdsup.h"
-
-const int priority_map[] = HY_PRIORITY_MAP;
-
-/* Unused ID variable. */
-DWORD unusedThreadID;
-
-HyThreadLibrary default_library;
-
-extern void VMCALL hythread_init (HyThreadLibrary * lib);
-extern void VMCALL hythread_shutdown (void);
-extern void fixupLocks386 (void);
-
-#define CDEV_CURRENT_FUNCTION _prototypes_private
-static BOOL WINAPI yield PROTOTYPE ((void));
-#if (!defined(HYVM_STATIC_LINKAGE))
-BOOL APIENTRY DllMain
-PROTOTYPE ((HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved));
-#endif /* !HYVM_STATIC_LINKAGE */
-
-#undef CDEV_CURRENT_FUNCTION
-
-BOOL (WINAPI * f_yield) (void);
-#define CDEV_CURRENT_FUNCTION yield
-static BOOL WINAPI
-yield (void)
-{
- Sleep (1);
- return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION DllMain
-#if (!defined(HYVM_STATIC_LINKAGE))
-/*
- * Initialize OS-specific threading helpers.
- *
- * @param hModule handle to module being loaded
- * @param ul_reason_for_call reason why DllMain being called
- * @param lpReserved reserved
- * @return TRUE on success, FALSE on failure.
- */
-BOOL APIENTRY
-DllMain (HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
-{
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- {
- hythread_library_t lib = GLOBAL_DATA (default_library);
- hythread_init (lib);
- if (lib->initStatus == 1)
- {
- OSVERSIONINFO versionInfo;
- fixupLocks386 ();
- /* SwitchToThread is not implemented on Win98 */
- versionInfo.dwOSVersionInfoSize = sizeof (versionInfo);
- if (GetVersionEx (&versionInfo))
- {
- if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
- {
- HMODULE kernel32 = GetModuleHandle ("kernel32");
- if (kernel32 != NULL)
- {
- f_yield =
- (BOOL (WINAPI *) (void)) GetProcAddress (kernel32,
- "SwitchToThread");
- }
- }
- }
- if (f_yield == NULL)
- f_yield = yield;
- }
- return lib->initStatus == 1;
- }
- case DLL_PROCESS_DETACH:
- hythread_shutdown ();
- }
- return TRUE;
-}
-#endif /* !HYVM_STATIC_LINKAGE */
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION init_thread_library
-#if (defined(HYVM_STATIC_LINKAGE))
-/**
- * Perform OS-specific initializations for the threading library.
- *
- * @return 0 on success or non-zero value on failure.
- */
-IDATA
-init_thread_library (void)
-{
- hythread_library_t lib = GLOBAL_DATA (default_library);
- if (lib->initStatus == 0)
- {
- HANDLE mutex = CreateMutex (NULL, TRUE, "hythread_init_mutex");
- if (mutex == NULL)
- return -1;
- if (lib->initStatus == 0)
- {
- hythread_init (lib);
- if (lib->initStatus == 1)
- {
- atexit (hythread_shutdown);
- }
- }
- ReleaseMutex (mutex);
- CloseHandle (mutex);
- if (lib->initStatus == 1)
- {
- OSVERSIONINFO versionInfo;
- fixupLocks386 ();
- /* SwitchToThread is not implemented on Win98 */
- versionInfo.dwOSVersionInfoSize = sizeof (versionInfo);
- if (GetVersionEx (&versionInfo))
- {
- if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
- {
- HMODULE kernel32 = GetModuleHandle ("kernel32");
- if (kernel32 != NULL)
- {
- f_yield =
- (BOOL (WINAPI *) (void)) GetProcAddress (kernel32,
- "SwitchToThread");
- }
- }
- }
- if (f_yield == NULL)
- f_yield = yield;
- }
- }
- return lib->initStatus != 1;
-}
-#endif /* HYVM_STATIC_LINKAGE */
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION initialize_thread_priority
-/**
- * Initialize a thread's priority.
- *
- * Here the threading library priority value is converted to the appropriate
- * OS-specific value.
- *
- * @param[in] thread a thread
- * @return none
- */
-void
-initialize_thread_priority (hythread_t thread)
-{
- IDATA priority, i;
-
- thread->priority = HYTHREAD_PRIORITY_NORMAL;
-
- if (priority_map[HYTHREAD_PRIORITY_MIN] ==
- priority_map[HYTHREAD_PRIORITY_MAX])
- return;
-
- priority = GetThreadPriority (thread->handle);
-
- /* are priorities mapped backwards? (WinCE does this.) */
- if (THREAD_PRIORITY_IDLE > THREAD_PRIORITY_TIME_CRITICAL)
- {
- for (i = HYTHREAD_PRIORITY_MAX; i >= HYTHREAD_PRIORITY_MIN; i--)
- {
- if (priority <= priority_map[i])
- {
- thread->priority = i;
- return;
- }
- }
- }
- else
- {
- for (i = HYTHREAD_PRIORITY_MIN; i <= HYTHREAD_PRIORITY_MAX; i++)
- {
- if (priority <= priority_map[i])
- {
- thread->priority = i;
- return;
- }
- }
- }
-}
-
-#undef CDEV_CURRENT_FUNCTION
Index: trunk/modules/portlib/src/main/native/thread/windows/thrdsup.h
===================================================================
--- trunk/modules/portlib/src/main/native/thread/windows/thrdsup.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/windows/thrdsup.h (working copy)
@@ -1,152 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if !defined(thrdsup_h)
-#define thrdsup_h
-
-/* windows.h defined UDATA. Ignore its definition */
-#define UDATA UDATA_win32_
-#include
-#undef UDATA /* this is safe because our UDATA is a typedef, not a macro */
-#include
-#include "hymutex.h"
-
-/* ostypes */
-typedef HANDLE OSTHREAD;
-typedef DWORD TLSKEY;
-typedef HANDLE COND;
-
-#define WRAPPER_TYPE void _cdecl
-
-typedef void *WRAPPER_ARG;
-#define WRAPPER_RETURN() return
-typedef HANDLE OSSEMAPHORE;
-
-#include "hycomp.h"
-/* this file might be included from a directory other than thread. Use a pseudo-absolute path to make
- * sure that we find thrtypes.h in the right place. Only IBMC needs this.
- */
-#include "thrtypes.h"
-void initialize_thread_priority PROTOTYPE ((hythread_t thread));
-IDATA init_thread_library PROTOTYPE ((void));
-extern const int priority_map[];
-extern struct HyThreadLibrary default_library;
-extern BOOL (WINAPI * f_yield) (void);
-
-/* Unused ID variable. */
-extern DWORD unusedThreadID;
-/* COND_DESTROY */
-#define COND_DESTROY(cond) CloseHandle(cond)
-/* TLS_GET */
-#define TLS_GET(key) (TlsGetValue(key))
-/* TLS_ALLOC */
-#define TLS_ALLOC(key) ((key = TlsAlloc()) == 0xFFFFFFFF)
-/* TLS_SET */
-#define TLS_SET(key, value) (TlsSetValue(key, value))
-/* THREAD_SELF */
-#define THREAD_SELF() (GetCurrentThread())
-/* THREAD_YIELD */
-
-#define _WIN32_WINNT 0x0400
-#define THREAD_YIELD() (f_yield())
-
-/* THREAD_CREATE */
-
-#define THREAD_CREATE(thread, stacksize, priority, entrypoint, entryarg) \
- (((thread)->handle = (HANDLE)_beginthread((entrypoint), (stacksize), (entryarg))) != (HANDLE)(-1) && \
- hythread_set_priority((thread), (priority)) == 0)
-
-/* COND_NOTIFY_ALL */
-#define COND_NOTIFY_ALL(cond) SetEvent(cond)
-/* COND_WAIT_IF_TIMEDOUT */
-/* NOTE: the calling thread must already own mutex */
-#define ADJUST_TIMEOUT(millis, nanos) (((nanos) && ((millis) != ((IDATA) (((UDATA)-1) >> 1)))) ? ((millis) + 1) : (millis))
-#define COND_WAIT_IF_TIMEDOUT(cond, mutex, millis, nanos) \
- do { \
- DWORD starttime_ = GetTickCount(); \
- IDATA initialtimeout_, timeout_, rc_; \
- initialtimeout_ = timeout_ = ADJUST_TIMEOUT(millis, nanos); \
- while (1) { \
- ResetEvent((cond)); \
- MUTEX_EXIT(mutex); \
- rc_ = WaitForSingleObject((cond), timeout_); \
- MUTEX_ENTER(mutex); \
- if (rc_ == WAIT_TIMEOUT)
-
-#define COND_WAIT_TIMED_LOOP() \
- timeout_ = initialtimeout_ - (GetTickCount() - starttime_); \
- if (timeout_ < 0) { timeout_ = 0; } \
- } } while(0)
-
-/* COND_WAIT */
-/* NOTE: the calling thread must already own mutex */
-#define COND_WAIT(cond, mutex) \
- do { \
- ResetEvent((cond)); \
- MUTEX_EXIT(mutex); \
- WaitForSingleObject((cond), INFINITE); \
- MUTEX_ENTER(mutex);
-
-#define COND_WAIT_LOOP() } while(1)
-
-/* COND_INIT */
-#define COND_INIT(cond) ((cond = CreateEvent(NULL, TRUE, FALSE, NULL)) != NULL)
-
-/* TLS_DESTROY */
-#define TLS_DESTROY(key) (TlsFree(key))
-
-/* THREAD_CANCEL */
-#define THREAD_CANCEL(thread) (TerminateThread(thread, (DWORD)-1)&&WaitForSingleObject(thread,INFINITE))
-
-/* THREAD_EXIT */
-#define THREAD_EXIT() _endthread()
-
-/* THREAD_DETACH */
-#define THREAD_DETACH(thread) /* no need to do anything */
-
-/* THREAD_SET_PRIORITY */
-#define THREAD_SET_PRIORITY(thread, priority) (!SetThreadPriority((thread), (priority)))
-
-/* SEM_CREATE */
-/* Arbitrary maximum count */
-#define SEM_CREATE(inval) CreateSemaphore(NULL,inval,2028,NULL)
-
-/* SEM_INIT */
-#define SEM_INIT(sm,pshrd,inval) (sm != NULL) ? 0: -1
-
-/* SEM_DESTROY */
-#define SEM_DESTROY(sm) CloseHandle(sm)
-
-/* SEM_FREE */
-#define SEM_FREE(s)
-
-/* SEM_POST */
-#define SEM_POST(sm) (ReleaseSemaphore((sm),1,NULL) ? 0 : -1)
-
-/* SEM_WAIT */
-#define SEM_WAIT(sm) ((WaitForSingleObject((sm), INFINITE) == WAIT_FAILED) ? -1 : 0)
-
-/* SEM_TRYWAIT */
-#define SEM_TRYWAIT(sm) WaitForSingleObject(sm, 0)
-
-/* SEM_GETVALUE */
-#define SEM_GETVALUE(sm)
-#if !defined(HYVM_STATIC_LINKAGE)
-#define init_thread_library() (0)
-#endif
-
-#endif /* thrdsup_h */
Index: trunk/modules/portlib/src/main/native/thread/windows/thrhelp.asm
===================================================================
--- trunk/modules/portlib/src/main/native/thread/windows/thrhelp.asm (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/windows/thrhelp.asm (working copy)
@@ -1,106 +0,0 @@
-; Licensed to the Apache Software Foundation (ASF) under one or more
-; contributor license agreements. See the NOTICE file distributed with
-; this work for additional information regarding copyright ownership.
-; The ASF licenses this file to You under the Apache License, Version 2.0
-; (the "License"); you may not use this file except in compliance with
-; the License. You may obtain a copy of the License at
-;
-; http://www.apache.org/licenses/LICENSE-2.0
-;
-; Unless required by applicable law or agreed to in writing, software
-; distributed under the License is distributed on an "AS IS" BASIS,
-; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-; See the License for the specific language governing permissions and
-; limitations under the License.
-
- .586p
- assume cs:flat,ds:flat,ss:flat
- .xmm
-eq_hy_null equ 0
-eq_HyThreadMonitor_pinCount equ 28
-eq_pointer_size equ 4
-eqS_current_stack_depth equ 16
-eqS_hythread_monitor_pin equ 16
-eqS_hythread_monitor_unpin equ 16
-eqSR_current_stack_depth equ 2
-eqSR_hythread_monitor_pin equ 2
-eqSR_hythread_monitor_unpin equ 2
-eqSRS_current_stack_depth equ 8
-eqSRS_hythread_monitor_pin equ 8
-eqSRS_hythread_monitor_unpin equ 8
-eqSS_current_stack_depth equ 64
-eqSS_hythread_monitor_pin equ 64
-eqSS_hythread_monitor_unpin equ 64
- CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
- CONST ends
- _TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
- public hythread_monitor_pin
- public current_stack_depth
- public hythread_monitor_unpin
- align 16
-current_stack_depth PROC NEAR
- ; localStackUse = 16
- push EBP
- mov EBP,ESP
- push EBX
- sub ESP,64
- mov EBX,EBP
- jmp short L2
-L1:
- mov EBX,ECX
-L2:
- mov ECX,dword ptr [EBX]
- test ECX,ECX ; setFlags: true
- jnz short L1
- sub EBX,EBP
- mov ECX,EBX
- mov EAX,EBX ; RegReg opt
- add ESP,64
- pop EBX
- pop EBP
- ret
-current_stack_depth ENDP
-; Prototype: void hythread_monitor_pin( hythread_monitor_t monitor, hythread_t osThread);
-; Defined in: #THREAD Args: 2
- align 16
-hythread_monitor_pin PROC NEAR
- ; localStackUse = 16
- push EBP
- mov EBP,ESP
- push EBX
- sub ESP,64
- mov EBX,dword ptr (eqSRS_hythread_monitor_pin+0+8+eqSS_hythread_monitor_pin)[ESP]
- mov EBX,dword ptr (eqSRS_hythread_monitor_pin+0+4+eqSS_hythread_monitor_pin)[ESP]
-lockFixup3:
-CONST$_LOCKFIXUPS_B SEGMENT DWORD USE32 PUBLIC 'CONST'
- dd offset flat:lockFixup3
-CONST$_LOCKFIXUPS_B ends
- lock inc dword ptr eq_HyThreadMonitor_pinCount[EBX] ; (Converted add 1 to inc)
- add ESP,64
- pop EBX
- pop EBP
- ret
-hythread_monitor_pin ENDP
-; Prototype: void hythread_monitor_unpin( hythread_monitor_t monitor, hythread_t osThread);
-; Defined in: #THREAD Args: 2
- align 16
-hythread_monitor_unpin PROC NEAR
- ; localStackUse = 16
- push EBP
- mov EBP,ESP
- push EBX
- sub ESP,64
- mov EBX,dword ptr (eqSS_hythread_monitor_unpin+0+8+eqSRS_hythread_monitor_unpin)[ESP]
- mov EBX,dword ptr (eqSS_hythread_monitor_unpin+0+eqSRS_hythread_monitor_unpin+4)[ESP]
-lockFixup4:
-CONST$_LOCKFIXUPS_B SEGMENT DWORD USE32 PUBLIC 'CONST'
- dd offset flat:lockFixup4
-CONST$_LOCKFIXUPS_B ends
- lock dec dword ptr eq_HyThreadMonitor_pinCount[EBX] ; (Converted subtract 1 to dec)
- add ESP,64
- pop EBX
- pop EBP
- ret
-hythread_monitor_unpin ENDP
- _TEXT ends
- end
Index: trunk/modules/portlib/src/main/native/thread/windows/thrspinlock.asm
===================================================================
--- trunk/modules/portlib/src/main/native/thread/windows/thrspinlock.asm (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/windows/thrspinlock.asm (working copy)
@@ -1,122 +0,0 @@
-; Licensed to the Apache Software Foundation (ASF) under one or more
-; contributor license agreements. See the NOTICE file distributed with
-; this work for additional information regarding copyright ownership.
-; The ASF licenses this file to You under the Apache License, Version 2.0
-; (the "License"); you may not use this file except in compliance with
-; the License. You may obtain a copy of the License at
-;
-; http://www.apache.org/licenses/LICENSE-2.0
-;
-; Unless required by applicable law or agreed to in writing, software
-; distributed under the License is distributed on an "AS IS" BASIS,
-; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-; See the License for the specific language governing permissions and
-; limitations under the License.
-
- .586p
- assume cs:flat,ds:flat,ss:flat
- .xmm
-eq_HyThreadAbstractMonitor_spinCount1 equ 48
-eq_HyThreadAbstractMonitor_spinCount2 equ 52
-eq_HyThreadAbstractMonitor_spinCount3 equ 56
-eq_HyThreadAbstractMonitor_spinlockState equ 40
-eq_pointer_size equ 4
-eqS_hythread_spinlock_acquire equ 18
-eqS_hythread_spinlock_swapState equ 16
-eqSR_hythread_spinlock_acquire equ 3
-eqSR_hythread_spinlock_swapState equ 2
-eqSRS_hythread_spinlock_acquire equ 12
-eqSRS_hythread_spinlock_swapState equ 8
-eqSS_hythread_spinlock_acquire equ 72
-eqSS_hythread_spinlock_swapState equ 64
-HYTHREAD_MONITOR_SPINLOCK_OWNED equ 1
-HYTHREAD_MONITOR_SPINLOCK_UNOWNED equ 0
- CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
- CONST ends
- _TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
- extrn hythread_yield:near
- public hythread_spinlock_acquire
- public hythread_spinlock_swapState
-; Prototype: IDATA hythread_spinlock_acquire(hythread_t self, hythread_monitor_t monitor);
-; Defined in: #THREAD Args: 2
- align 16
-hythread_spinlock_acquire PROC NEAR
- ; localStackUse = 18
- push EBP
- mov EBP,ESP
- push EBX
- push ESI
- sub ESP,72
- mov EDX,dword ptr (eqSS_hythread_spinlock_acquire+0+eqSRS_hythread_spinlock_acquire+8)[ESP]
- mov ECX,dword ptr eq_HyThreadAbstractMonitor_spinCount3[EDX]
-L2:
- mov EBX,dword ptr eq_HyThreadAbstractMonitor_spinCount2[EDX]
-L3:
-; Try to cmpxchg 0 into the target field (-1 indicates free)
- cmp dword ptr eq_HyThreadAbstractMonitor_spinlockState[EDX],HYTHREAD_MONITOR_SPINLOCK_UNOWNED ; setFlags: true
- jne short L10
- xor EAX,EAX
- mov ESI,HYTHREAD_MONITOR_SPINLOCK_OWNED
-lockFixup12:
-CONST$_LOCKFIXUPS_B SEGMENT DWORD USE32 PUBLIC 'CONST'
- dd offset flat:lockFixup12
-CONST$_LOCKFIXUPS_B ends
- lock cmpxchg dword ptr eq_HyThreadAbstractMonitor_spinlockState[EDX],ESI
- test EAX,EAX ; setFlags: true
- jnz short L10
- xor EBX,EBX
- jmp short L1
-L10:
- dw 37107 ; PAUSE
-; begin tight loop
- mov EAX,dword ptr eq_HyThreadAbstractMonitor_spinCount1[EDX]
-L11:
-; inside tight loop
- dec EAX ; setFlags: true(Converted subtract 1 to dec)
- jnz short L11
-; end tight loop
- dec EBX ; setFlags: true(Converted subtract 1 to dec)
- jnz short L3
- mov dword ptr 64[ESP],ECX ; save VMtemp3_1_3_(HyThreadAbstractMonitor->spinCount3)
- mov dword ptr 68[ESP],EDX ; save VMtemp3_1_2_(struct HyThreadAbstractMonitor*) in_HyVMThreadSpinlocks>>#hythread_spinlock_acquire
- call hythread_yield
- mov ECX,dword ptr 64[ESP] ; load VMtemp3_1_3_(HyThreadAbstractMonitor->spinCount3)
- dec ECX ; setFlags: true(Converted subtract 1 to dec)
- mov EDX,dword ptr 68[ESP] ; load VMtemp3_1_2_(struct HyThreadAbstractMonitor*) in_HyVMThreadSpinlocks>>#hythread_spinlock_acquire
- jnz short L2
- mov EBX,-1
-L1:
- mov EAX,EBX
- add ESP,72
- pop ESI
- pop EBX
- pop EBP
- ret
-hythread_spinlock_acquire ENDP
-; Prototype: UDATA hythread_spinlock_swapState(hythread_monitor_t monitor, UDATA newState);
-; Defined in: #THREAD Args: 2
- align 16
-hythread_spinlock_swapState PROC NEAR
- ; localStackUse = 16
- push EBP
- mov EBP,ESP
- push EBX
- sub ESP,64
- mov EBX,dword ptr (eqSS_hythread_spinlock_swapState+0+eqSRS_hythread_spinlock_swapState+4)[ESP]
- mov ECX,dword ptr (eqSS_hythread_spinlock_swapState+0+eqSRS_hythread_spinlock_swapState+8)[ESP]
-; If we are writing in UNOWNED, we are exiting the critical section, therefore
-; have to finish up any writes
- test ECX,ECX ; setFlags: true
- ; memory barrier (no code necessary for write barriers)
- xchg dword ptr eq_HyThreadAbstractMonitor_spinlockState[EBX],ECX
-; if we entered the critical section, (i.e. we swapped out UNOWNED) then
-; we have to issue a readBarrier
- test ECX,ECX ; setFlags: true
- mov EAX,ECX
- add ESP,64
- pop EBX
- pop EBP
- ret
-hythread_spinlock_swapState ENDP
- _TEXT ends
- end
Index: trunk/modules/portlib/src/main/native/thread/windows/thrtypes.h
===================================================================
--- trunk/modules/portlib/src/main/native/thread/windows/thrtypes.h (revision 501409)
+++ trunk/modules/portlib/src/main/native/thread/windows/thrtypes.h (working copy)
@@ -1,131 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if !defined(THRTYPES_H)
-#define THRTYPES_H
-
-#if defined(__cplusplus)
-extern "C"
-{
-#endif
-
-#include "hythread.h"
- typedef struct HyThread
- {
- struct HyThreadLibrary *library;
- UDATA attachcount;
- UDATA priority;
- struct HyThreadMonitor *monitor;
- struct HyThread *next;
- void *tls[128];
- hythread_entrypoint_t entrypoint;
- void *entryarg;
- UDATA flags;
- UDATA tid;
- struct HyThread *interrupter;
- OSTHREAD handle;
- COND condition;
- MUTEX mutex;
- UDATA stacksize;
- UDATA *tos;
- } HyThread;
-
-
- typedef struct HyThreadMonitor
- {
- UDATA count;
- struct HyThread *owner;
- struct HyThread *waiting;
- UDATA flags;
- UDATA userData;
- struct HyThreadMonitorTracing *tracing;
- char *name;
- UDATA pinCount;
- UDATA antiDeflationCount;
- UDATA proDeflationCount;
- UDATA spinlockState;
- UDATA lockingWord;
- UDATA spinCount1;
- UDATA spinCount2;
- UDATA spinCount3;
- struct HyThread *blocking;
- MUTEX mutex;
- } HyThreadMonitor;
-
-
- typedef struct HyThreadMonitorPool
- {
- struct HyThreadMonitorPool *next;
- struct HyThreadMonitor *next_free;
- struct HyThreadMonitor entries[64];
- } HyThreadMonitorPool;
-
-#define MONITOR_POOL_SIZE 64
-
-
- typedef struct HyThreadGlobal
- {
- struct HyThreadGlobal *next;
- char *name;
- UDATA data;
- } HyThreadGlobal;
-
-
- typedef struct HyThreadLibrary
- {
- UDATA spinlock;
- struct HyThreadMonitorPool *monitor_pool;
- struct HyPool *thread_pool;
- UDATA threadCount;
- UDATA stack_usage;
- IDATA initStatus;
- UDATA flags;
- struct HyThreadMonitorTracing *gc_lock_tracing;
- struct HyThreadGlobal *globals;
- struct HyPool *global_pool;
- MUTEX global_mutex;
- TLSKEY self_ptr;
- MUTEX monitor_mutex;
- MUTEX tls_mutex;
- hythread_tls_finalizer_t tls_finalizers[128];
- char *thread_weight;
- struct HyPool *monitor_tracing_pool;
- struct HyPool *thread_tracing_pool;
- } HyThreadLibrary;
-
-#define HYTHREAD_LIB_FLAG_JLMHST_ENABLED 0x10000
-#define HYTHREAD_LIB_FLAG_JLM_ENABLED 0x4000
-#define HYTHREAD_LIB_FLAG_JLM_ENABLED_ALL 0x1C000
-#define HYTHREAD_LIB_FLAG_JLM_HAS_BEEN_ENABLED 0x20000
-#define HYTHREAD_LIB_FLAG_JLMTS_ENABLED 0x8000
-
- typedef struct HySemaphore
- {
- OSSEMAPHORE sem;
- } HySemaphore;
-
-#define STACK_DEFAULT_SIZE 0x8000
-#define FREE_TAG ((UDATA)-1)
-
- typedef struct HyThreadMonitorPool *hythread_monitor_pool_t;
- typedef struct HyThreadLibrary *hythread_library_t;
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* THRTYPES_H */
Index: trunk/modules/portlib/src/test/native/hytime/shared/hytime.c
===================================================================
--- trunk/modules/portlib/src/test/native/hytime/shared/hytime.c (revision 501409)
+++ trunk/modules/portlib/src/test/native/hytime/shared/hytime.c (working copy)
@@ -25,6 +25,7 @@
{
HyPortLibrary hyportLibrary;
HyPortLibraryVersion portLibraryVersion;
+ HyThreadLibrary hyThreadLibrary = 0; // RON guanranteed to crash!
UDATA msec, usec;
I_64 millis;
U_64 hires, hires2, freq, delta;
@@ -33,7 +34,7 @@
HYPORT_SET_VERSION (&portLibraryVersion, HYPORT_CAPABILITY_MASK);
if (0 != hyport_init_library (&hyportLibrary, &portLibraryVersion,
- sizeof (HyPortLibrary)))
+ sizeof (HyPortLibrary), hyThreadLibrary))
{
fprintf(stderr, "portlib init failed\n");
return 1;
Index: trunk/modules/portlib/src/test/native/init/shared/init.c
===================================================================
--- trunk/modules/portlib/src/test/native/init/shared/init.c (revision 501409)
+++ trunk/modules/portlib/src/test/native/init/shared/init.c (working copy)
@@ -24,6 +24,7 @@
{
HyPortLibrary hyportLibrary;
HyPortLibraryVersion portLibraryVersion;
+ HyThreadLibrary hyThreadLibrary = 0; // RON guanranteed to crash!
printf("init:\n");
@@ -29,7 +30,7 @@
HYPORT_SET_VERSION (&portLibraryVersion, HYPORT_CAPABILITY_MASK);
if (0 != hyport_init_library (&hyportLibrary, &portLibraryVersion,
- sizeof (HyPortLibrary)))
+ sizeof (HyPortLibrary), hythreadLibrary))
{
fprintf(stderr, "portlib init failed\n");
return 1;
Index: trunk/modules/prefs/src/main/native/prefs/windows/makefile
===================================================================
--- trunk/modules/prefs/src/main/native/prefs/windows/makefile (revision 501409)
+++ trunk/modules/prefs/src/main/native/prefs/windows/makefile (working copy)
@@ -33,8 +33,8 @@
MDLLIBFILES = \
$(LIBPATH)hycommon.lib $(LIBPATH)hysig.lib $(LIBPATH)hyzip.lib \
- $(LIBPATH)hyzlib.lib $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib \
- $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib
+ $(LIBPATH)hyzlib.lib $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib \
+ $(LIBPATH)vmi.lib
DLLBASE=0x13300000
COMMENT=/comment:"Preferences component native code. (c) Copyright 1993, 2005 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/print/src/main/native/print/windows/makefile
===================================================================
--- trunk/modules/print/src/main/native/print/windows/makefile (revision 501409)
+++ trunk/modules/print/src/main/native/print/windows/makefile (working copy)
@@ -37,7 +37,7 @@
MDLLIBFILES = #\
# $(LIBPATH)hysig.lib $(LIBPATH)hycommon.lib $(LIBPATH)hypool.lib \
-# $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib $(JPEG_DIR)libjpeg.lib
+# $(LIBPATH)vmi.lib $(JPEG_DIR)libjpeg.lib
DLLBASE=0x13300000
COMMENT=/comment:"Print native code. (c) Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable."
Index: trunk/modules/text/src/main/native/text/unix/makefile
===================================================================
--- trunk/modules/text/src/main/native/text/unix/makefile (revision 501409)
+++ trunk/modules/text/src/main/native/text/unix/makefile (working copy)
@@ -27,7 +27,7 @@
MDLLIBFILES = \
$(DLLPATH)libicuuc.so.34 \
$(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so $(LIBPATH)libhycommon.a \
- $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(DLLPATH)libhythr.so $(LIBPATH)libvmi.so
+ $(LIBPATH)libhypool.a $(LIBPATH)libhyfdlibm.a $(LIBPATH)libvmi.so
DLLNAME = ../libhytext.so
Index: trunk/modules/text/src/main/native/text/windows/makefile
===================================================================
--- trunk/modules/text/src/main/native/text/windows/makefile (revision 501409)
+++ trunk/modules/text/src/main/native/text/windows/makefile (working copy)
@@ -30,7 +30,7 @@
MDLLIBFILES = \
$(LIBPATH)hysig.lib $(LIBPATH)hycommon.lib $(LIBPATH)hypool.lib $(LIBPATH)hyfdlibm.lib \
- $(LIBPATH)hythr.lib $(LIBPATH)vmi.lib ..\..\icu4c\unicode\icuuc.lib
+ $(LIBPATH)vmi.lib ..\..\icu4c\unicode\icuuc.lib
DLLBASE=0x13300000
COMMENT=/comment:"Text component native code. (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable."