1 | // -*- c++ -*-
|
---|
2 | // win32-threads.h - Defines for using Win32 threads.
|
---|
3 |
|
---|
4 | /* Copyright (C) 1998, 1999, 2000 Free Software Foundation
|
---|
5 |
|
---|
6 | This file is part of libgcj.
|
---|
7 |
|
---|
8 | This software is copyrighted work licensed under the terms of the
|
---|
9 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
---|
10 | details. */
|
---|
11 |
|
---|
12 | #ifndef __JV_WIN32_THREADS__
|
---|
13 | #define __JV_WIN32_THREADS__
|
---|
14 |
|
---|
15 | #include <windows.h>
|
---|
16 |
|
---|
17 | //
|
---|
18 | // Typedefs.
|
---|
19 | //
|
---|
20 |
|
---|
21 | typedef struct _Jv_ConditionVariable_t {
|
---|
22 | HANDLE ev[2];
|
---|
23 | CRITICAL_SECTION count_mutex;
|
---|
24 | int blocked_count;
|
---|
25 | };
|
---|
26 |
|
---|
27 | typedef CRITICAL_SECTION _Jv_Mutex_t;
|
---|
28 |
|
---|
29 | typedef struct
|
---|
30 | {
|
---|
31 | int flags; // Flags are defined in implementation.
|
---|
32 | HANDLE handle; // Actual handle to the thread
|
---|
33 | java::lang::Thread *thread_obj;
|
---|
34 | } _Jv_Thread_t;
|
---|
35 |
|
---|
36 | typedef void _Jv_ThreadStartFunc (java::lang::Thread *);
|
---|
37 |
|
---|
38 | //
|
---|
39 | // Condition variables.
|
---|
40 | //
|
---|
41 |
|
---|
42 | int _Jv_CondWait (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu, jlong millis, jint nanos);
|
---|
43 | void _Jv_CondInit (_Jv_ConditionVariable_t *cv);
|
---|
44 | void _Jv_CondDestroy (_Jv_ConditionVariable_t *cv);
|
---|
45 | int _Jv_CondNotify (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *);
|
---|
46 | int _Jv_CondNotifyAll (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *);
|
---|
47 |
|
---|
48 | //
|
---|
49 | // Mutexes.
|
---|
50 | // We use CRITICAL_SECTIONs instead of CreateMutex() for better performance
|
---|
51 | //
|
---|
52 |
|
---|
53 | inline void _Jv_MutexInit (_Jv_Mutex_t *mu)
|
---|
54 | {
|
---|
55 | InitializeCriticalSection(mu);
|
---|
56 | }
|
---|
57 |
|
---|
58 | #define _Jv_HaveMutexDestroy
|
---|
59 | inline void _Jv_MutexDestroy (_Jv_Mutex_t *mu)
|
---|
60 | {
|
---|
61 | DeleteCriticalSection(mu);
|
---|
62 | mu = NULL;
|
---|
63 | }
|
---|
64 |
|
---|
65 | inline int _Jv_MutexUnlock (_Jv_Mutex_t *mu)
|
---|
66 | {
|
---|
67 | LeaveCriticalSection(mu);
|
---|
68 | return 0;
|
---|
69 | }
|
---|
70 |
|
---|
71 | inline int _Jv_MutexLock (_Jv_Mutex_t *mu)
|
---|
72 | {
|
---|
73 | EnterCriticalSection(mu);
|
---|
74 | return 0;
|
---|
75 | }
|
---|
76 |
|
---|
77 | //
|
---|
78 | // Thread creation and manipulation.
|
---|
79 | //
|
---|
80 |
|
---|
81 | void _Jv_InitThreads (void);
|
---|
82 | _Jv_Thread_t *_Jv_ThreadInitData (java::lang::Thread *thread);
|
---|
83 | void _Jv_ThreadDestroyData (_Jv_Thread_t *data);
|
---|
84 |
|
---|
85 | inline java::lang::Thread* _Jv_ThreadCurrent (void)
|
---|
86 | {
|
---|
87 | extern DWORD _Jv_ThreadKey;
|
---|
88 | return (java::lang::Thread *) TlsGetValue(_Jv_ThreadKey);
|
---|
89 | }
|
---|
90 |
|
---|
91 | inline _Jv_Thread_t *_Jv_ThreadCurrentData(void)
|
---|
92 | {
|
---|
93 | extern DWORD _Jv_ThreadDataKey;
|
---|
94 | return (_Jv_Thread_t *) TlsGetValue(_Jv_ThreadDataKey);
|
---|
95 | }
|
---|
96 |
|
---|
97 | inline void _Jv_ThreadYield (void)
|
---|
98 | {
|
---|
99 | // FIXME: win98 freezes hard (OS hang) when we use this --
|
---|
100 | // for now, we simply don't yield
|
---|
101 | // Sleep (0);
|
---|
102 | }
|
---|
103 |
|
---|
104 | void _Jv_ThreadRegister (_Jv_Thread_t *data);
|
---|
105 | void _Jv_ThreadUnRegister ();
|
---|
106 |
|
---|
107 | void _Jv_ThreadSetPriority (_Jv_Thread_t *data, jint prio);
|
---|
108 | void _Jv_ThreadStart (java::lang::Thread *thread, _Jv_Thread_t *data,
|
---|
109 | _Jv_ThreadStartFunc *meth);
|
---|
110 | void _Jv_ThreadWait (void);
|
---|
111 | void _Jv_ThreadInterrupt (_Jv_Thread_t *data);
|
---|
112 |
|
---|
113 | // Remove defines from <windows.h> that conflict with various things in libgcj code
|
---|
114 |
|
---|
115 | #undef TRUE
|
---|
116 | #undef FALSE
|
---|
117 | #undef MAX_PRIORITY
|
---|
118 | #undef MIN_PRIORITY
|
---|
119 | #undef min
|
---|
120 | #undef max
|
---|
121 | #undef interface
|
---|
122 | #undef STRICT
|
---|
123 | #undef VOID
|
---|
124 |
|
---|
125 | #endif /* __JV_WIN32_THREADS__ */
|
---|