Commit | Line | Data |
---|---|---|
2986a63f JH |
1 | |
2 | /* | |
3 | * Copyright © 2001 Novell, Inc. All Rights Reserved. | |
4 | * | |
5 | * You may distribute under the terms of either the GNU General Public | |
6 | * License or the Artistic License, as specified in the README file. | |
7 | * | |
8 | */ | |
9 | ||
10 | /* | |
11 | * FILENAME : nw5thread.h | |
12 | * DESCRIPTION : Thread related functions. | |
13 | * Author : SGP | |
14 | * Date : January 2001. | |
15 | * | |
16 | */ | |
17 | ||
18 | ||
19 | ||
20 | #ifndef _NW5THREAD_H | |
21 | #define _NW5THREAD_H | |
22 | ||
23 | ||
24 | #include <nwthread.h> | |
25 | ||
26 | #include "netware.h" | |
27 | ||
28 | typedef long perl_key; | |
29 | ||
4d1ff10f | 30 | #if (defined (USE_ITHREADS) || defined (USE_5005THREADS)) && defined(MPK_ON) |
2986a63f JH |
31 | #ifdef __cplusplus |
32 | extern "C" | |
33 | { | |
34 | #endif | |
35 | #include <mpktypes.h> | |
36 | #include <mpkapis.h> | |
37 | #define kSUCCESS (0) | |
38 | #define ERROR_INVALID_MUTEX (0x1010) | |
39 | ||
40 | #ifdef __cplusplus | |
41 | } | |
42 | #endif | |
43 | #undef WORD | |
44 | //On NetWare, since the NLM will be resident, only once the MUTEX_INIT gets called and | |
45 | //this will be freed when the script terminates. But when a new script is executed, | |
46 | //then MUTEX_LOCK will fail since it is already freed. Even if this problem is fixed | |
47 | //by not freeing the mutex when script terminates but when the NLM unloads, there will | |
48 | //still be problems when multiple scripts are running simultaneously in a multi-processor | |
49 | //machine - sgp | |
50 | typedef MUTEX perl_mutex; | |
51 | # define MUTEX_INIT(m) \ | |
52 | STMT_START { \ | |
53 | /*if ((*(m) = kMutexAlloc("NetWarePerlMutex")) == NULL) */\ | |
54 | /*Perl_croak_nocontext("panic: MUTEX_ALLOC"); */\ | |
55 | /*ConsolePrintf("Mutex Init %d\n",*(m)); */\ | |
56 | } STMT_END | |
57 | ||
58 | # define MUTEX_LOCK(m) \ | |
59 | STMT_START { \ | |
60 | /*ConsolePrintf("Mutex lock %d\n",*(m)); */\ | |
61 | /*if (kMutexLock(*(m)) == ERROR_INVALID_MUTEX) */\ | |
62 | /*Perl_croak_nocontext("panic: MUTEX_LOCK"); */\ | |
63 | } STMT_END | |
64 | ||
65 | # define MUTEX_UNLOCK(m) \ | |
66 | STMT_START { \ | |
67 | /*ConsolePrintf("Mutex unlock %d\n",*(m)); */\ | |
68 | /*if (kMutexUnlock(*(m)) != kSUCCESS) \ | |
69 | Perl_croak_nocontext("panic: MUTEX_UNLOCK"); */\ | |
70 | } STMT_END | |
71 | ||
72 | # define MUTEX_DESTROY(m) \ | |
73 | STMT_START { \ | |
74 | /*ConsolePrintf("Mutex Destroy %d\n",*(m)); */\ | |
75 | /*if (kMutexWaitCount(*(m)) == 0 ) */\ | |
76 | /*{ */\ | |
77 | /*PERL_SET_INTERP(NULL); *//*newly added CHKSGP???*/ \ | |
78 | /*if (kMutexFree(*(m)) != kSUCCESS) */ \ | |
79 | /*Perl_croak_nocontext("panic: MUTEX_FREE"); */\ | |
80 | /*} */\ | |
81 | } STMT_END | |
82 | ||
83 | #else | |
84 | typedef unsigned long perl_mutex; | |
85 | # define MUTEX_INIT(m) | |
86 | # define MUTEX_LOCK(m) | |
87 | # define MUTEX_UNLOCK(m) | |
88 | # define MUTEX_DESTROY(m) | |
89 | #endif | |
90 | ||
91 | /* These macros assume that the mutex associated with the condition | |
92 | * will always be held before COND_{SIGNAL,BROADCAST,WAIT,DESTROY}, | |
93 | * so there's no separate mutex protecting access to (c)->waiters | |
94 | */ | |
95 | //For now let us just see when this happens -sgp. | |
96 | #define COND_INIT(c) \ | |
97 | STMT_START { \ | |
98 | ConsolePrintf("In COND_INIT\n"); \ | |
99 | } STMT_END | |
100 | ||
101 | /* (c)->waiters = 0; \ | |
102 | (c)->sem = OpenLocalSemaphore (0); \ | |
103 | if ((c)->sem == NULL) \ | |
104 | Perl_croak_nocontext("panic: COND_INIT (%ld)",errno); \*/ | |
105 | ||
106 | #define COND_SIGNAL(c) \ | |
107 | STMT_START { \ | |
108 | ConsolePrintf("In COND_SIGNAL\n"); \ | |
109 | } STMT_END | |
110 | /*if ((c)->waiters > 0 && \ | |
111 | SignalLocalSemaphore((c)->sem) != 0) \ | |
112 | Perl_croak_nocontext("panic: COND_SIGNAL (%ld)",errno); \*/ | |
113 | ||
114 | #define COND_BROADCAST(c) \ | |
115 | STMT_START { \ | |
116 | ConsolePrintf("In COND_BROADCAST\n"); \ | |
117 | } STMT_END | |
118 | ||
119 | /*if ((c)->waiters > 0 ) { \ | |
120 | int count; \ | |
121 | for(count=0; count<(c)->waiters; count++) { \ | |
122 | if(SignalLocalSemaphore((c)->sem) != 0) \ | |
123 | Perl_croak_nocontext("panic: COND_BROADCAST (%ld)",GetLastError());\ | |
124 | } \ | |
125 | } \*/ | |
126 | #define COND_WAIT(c, m) \ | |
127 | STMT_START { \ | |
128 | ConsolePrintf("In COND_WAIT\n"); \ | |
129 | } STMT_END | |
130 | ||
131 | ||
132 | #define COND_DESTROY(c) \ | |
133 | STMT_START { \ | |
134 | ConsolePrintf("In COND_DESTROY\n"); \ | |
135 | } STMT_END | |
136 | ||
137 | /* (c)->waiters = 0; \ | |
138 | if (CloseLocalSemaphore((c)->sem) != 0) \ | |
139 | Perl_croak_nocontext("panic: COND_DESTROY (%ld)",errno); \*/ | |
140 | ||
141 | #if 0 | |
142 | #define DETACH(t) \ | |
143 | STMT_START { \ | |
144 | if (CloseHandle((t)->self) == 0) { \ | |
145 | MUTEX_UNLOCK(&(t)->mutex); \ | |
146 | Perl_croak_nocontext("panic: DETACH"); \ | |
147 | } \ | |
148 | } STMT_END | |
149 | #endif //#if 0 | |
150 | ||
151 | //Following has to be defined CHKSGP | |
152 | #if defined(PERLDLL) && defined(USE_DECLSPEC_THREAD) && (!defined(__BORLANDC__) || defined(_DLL)) | |
153 | extern __declspec(thread) void *PL_current_context; | |
154 | #define PERL_SET_CONTEXT(t) (PL_current_context = t) | |
155 | #define PERL_GET_CONTEXT PL_current_context | |
156 | #else | |
157 | #define PERL_GET_CONTEXT Perl_get_context() | |
158 | #define PERL_SET_CONTEXT(t) Perl_set_context(t) | |
159 | #endif | |
160 | ||
161 | //Check the following, will be used in Thread extension - CHKSGP | |
162 | #define THREAD_RET_TYPE unsigned __stdcall | |
163 | #define THREAD_RET_CAST(p) ((unsigned)(p)) | |
164 | ||
165 | #define INIT_THREADS NOOP | |
166 | ||
167 | //Ideally this should have been PL_thr_key = fnInitializeThreadCtx(); | |
168 | //See the comment at the end of file nw5thread.c as to why PL_thr_key is not assigned - sgp | |
169 | #define ALLOC_THREAD_KEY \ | |
170 | STMT_START { \ | |
171 | fnInitializeThreadCtx(); \ | |
172 | } STMT_END | |
173 | ||
174 | ||
175 | #endif /* _NW5THREAD_H */ | |
176 |