OSDN Git Service

2001-04-27 Martin Kahlert <martin.kahlert@infineon.com>
[pf3gnuchains/gcc-fork.git] / libjava / include / win32-threads.h
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 HANDLE _Jv_ConditionVariable_t;
22 typedef HANDLE _Jv_Mutex_t;
23
24 typedef struct
25 {
26   int flags;            // Flags are defined in implementation.
27   HANDLE handle;        // Actual handle to the thread
28 } _Jv_Thread_t;
29
30 typedef void _Jv_ThreadStartFunc (java::lang::Thread *);
31
32 //
33 // Condition variables.
34 //
35
36 inline void
37 _Jv_CondInit (_Jv_ConditionVariable_t *cv)
38 {
39   *cv = CreateEvent (NULL, 0, 0, NULL);
40 }
41
42 #define _Jv_HaveCondDestroy
43
44 inline void
45 _Jv_CondDestroy (_Jv_ConditionVariable_t *cv)
46 {
47   CloseHandle (*cv);
48   cv = NULL;
49 }
50
51 int _Jv_CondWait (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu,
52                   jlong millis, jint nanos);
53
54 inline int
55 _Jv_CondNotify (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *)
56 {
57   // FIXME: check for mutex ownership?
58   return PulseEvent (*cv) ? 0 : _JV_NOT_OWNER;        // FIXME?
59 }
60
61 inline int
62 _Jv_CondNotifyAll (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *)
63 {
64   // FIXME: check for mutex ownership?
65   return PulseEvent (*cv) ? 0 : _JV_NOT_OWNER;        // FIXME?
66 }
67
68 //
69 // Mutexes.
70 //
71
72 inline void
73 _Jv_MutexInit (_Jv_Mutex_t *mu)
74 {
75   *mu = CreateMutex (NULL, 0, NULL);
76 }
77
78 #define _Jv_HaveMutexDestroy
79
80 inline void
81 _Jv_MutexDestroy (_Jv_Mutex_t *mu)
82 {
83   CloseHandle (*mu);
84   mu = NULL;
85 }
86
87 int _Jv_MutexLock (_Jv_Mutex_t *mu);
88
89 inline int
90 _Jv_MutexUnlock (_Jv_Mutex_t *mu)
91 {
92   return ReleaseMutex(*mu) ? 0 : GetLastError();        // FIXME: Map error code?
93 }
94
95 //
96 // Thread creation and manipulation.
97 //
98
99 void _Jv_InitThreads (void);
100 _Jv_Thread_t *_Jv_ThreadInitData (java::lang::Thread *thread);
101 void _Jv_ThreadDestroyData (_Jv_Thread_t *data);
102
103 inline java::lang::Thread *
104 _Jv_ThreadCurrent (void)
105 {
106   extern DWORD _Jv_ThreadKey;
107   return (java::lang::Thread *) TlsGetValue(_Jv_ThreadKey);
108 }
109
110 inline _Jv_Thread_t *
111 _Jv_ThreadCurrentData (void)
112 {
113   extern DWORD _Jv_ThreadDataKey;
114   return (_Jv_Thread_t *) TlsGetValue(_Jv_ThreadDataKey);
115 }
116
117 inline void
118 _Jv_ThreadYield (void)
119 {
120   Sleep (0);
121 }
122
123 void _Jv_ThreadSetPriority (_Jv_Thread_t *data, jint prio);
124 void _Jv_ThreadStart (java::lang::Thread *thread, _Jv_Thread_t *data,
125                       _Jv_ThreadStartFunc *meth);
126 void _Jv_ThreadWait (void);
127 void _Jv_ThreadInterrupt (_Jv_Thread_t *data);
128
129 // Remove defines from <windows.h> that conflict with various things in libgcj code
130
131 #undef TRUE
132 #undef FALSE
133 #undef MAX_PRIORITY
134 #undef MIN_PRIORITY
135 #undef min
136 #undef max
137 #undef interface
138 #undef STRICT
139 #undef VOID
140
141 #endif /* __JV_WIN32_THREADS__ */