2 // win32-threads.h - Defines for using Win32 threads.
4 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software
7 This file is part of libgcj.
9 This software is copyrighted work licensed under the terms of the
10 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
13 #ifndef __JV_WIN32_THREADS__
14 #define __JV_WIN32_THREADS__
24 // ev[0] (signal) is a Win32 auto-reset event for _Jv_CondNotify
25 // ev[1] (broadcast) is a Win32 manual-reset event for _Jv_CondNotifyAll
28 // Number of threads waiting on this condition variable
31 // Protects access to the blocked_count variable
32 CRITICAL_SECTION count_mutex
;
34 } _Jv_ConditionVariable_t
;
38 // The thread-id of the owner thread if any, 0 otherwise
41 // Track nested mutex acquisitions by the same thread
44 // The actual Windows construct used to implement this mutex
51 int flags
; // Flags are defined in implementation.
52 HANDLE handle
; // Actual handle to the thread
53 java::lang::Thread
*thread_obj
;
56 typedef DWORD _Jv_ThreadId_t
;
61 return GetCurrentThreadId();
64 typedef void _Jv_ThreadStartFunc (java::lang::Thread
*);
67 // Condition variables.
70 int _Jv_CondWait (_Jv_ConditionVariable_t
*cv
, _Jv_Mutex_t
*mu
, jlong millis
, jint nanos
);
71 void _Jv_CondInit (_Jv_ConditionVariable_t
*cv
);
72 void _Jv_CondDestroy (_Jv_ConditionVariable_t
*cv
);
73 int _Jv_CondNotify (_Jv_ConditionVariable_t
*cv
, _Jv_Mutex_t
*);
74 int _Jv_CondNotifyAll (_Jv_ConditionVariable_t
*cv
, _Jv_Mutex_t
*);
78 // We use CRITICAL_SECTIONs instead of CreateMutex() for better performance
81 inline void _Jv_MutexInit (_Jv_Mutex_t
*mu
)
85 InitializeCriticalSection (&(mu
->cs
));
88 #define _Jv_HaveMutexDestroy
89 inline void _Jv_MutexDestroy (_Jv_Mutex_t
*mu
)
93 DeleteCriticalSection (&(mu
->cs
));
97 inline int _Jv_MutexUnlock (_Jv_Mutex_t
*mu
)
99 if (mu
->owner
== GetCurrentThreadId ( ))
102 if (mu
->refcount
== 0)
104 LeaveCriticalSection (&(mu
->cs
));
111 inline int _Jv_MutexLock (_Jv_Mutex_t
*mu
)
113 EnterCriticalSection (&(mu
->cs
));
114 mu
->owner
= GetCurrentThreadId ( );
120 // Thread creation and manipulation.
123 void _Jv_InitThreads (void);
124 _Jv_Thread_t
*_Jv_ThreadInitData (java::lang::Thread
*thread
);
125 void _Jv_ThreadDestroyData (_Jv_Thread_t
*data
);
127 inline java::lang::Thread
* _Jv_ThreadCurrent (void)
129 extern DWORD _Jv_ThreadKey
;
130 return (java::lang::Thread
*) TlsGetValue(_Jv_ThreadKey
);
133 inline _Jv_Thread_t
*_Jv_ThreadCurrentData(void)
135 extern DWORD _Jv_ThreadDataKey
;
136 return (_Jv_Thread_t
*) TlsGetValue(_Jv_ThreadDataKey
);
139 inline void _Jv_ThreadYield (void)
144 void _Jv_ThreadRegister (_Jv_Thread_t
*data
);
145 void _Jv_ThreadUnRegister ();
147 void _Jv_ThreadSetPriority (_Jv_Thread_t
*data
, jint prio
);
148 void _Jv_ThreadStart (java::lang::Thread
*thread
, _Jv_Thread_t
*data
,
149 _Jv_ThreadStartFunc
*meth
);
150 void _Jv_ThreadWait (void);
151 void _Jv_ThreadInterrupt (_Jv_Thread_t
*data
);
153 // Remove defines from <windows.h> that conflict with various things in libgcj code
165 #endif /* __JV_WIN32_THREADS__ */