3 * Copyright © 2001 Novell, Inc. All Rights Reserved.
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.
11 * FILENAME : nw5thread.h
12 * DESCRIPTION : Thread related functions.
14 * Date : January 2001.
28 typedef long perl_key;
30 #if (defined (USE_ITHREADS) || defined (USE_THREADS)) && defined(MPK_ON)
38 #define ERROR_INVALID_MUTEX (0x1010)
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
50 typedef MUTEX perl_mutex;
51 # define MUTEX_INIT(m) \
53 /*if ((*(m) = kMutexAlloc("NetWarePerlMutex")) == NULL) */\
54 /*Perl_croak_nocontext("panic: MUTEX_ALLOC"); */\
55 /*ConsolePrintf("Mutex Init %d\n",*(m)); */\
58 # define MUTEX_LOCK(m) \
60 /*ConsolePrintf("Mutex lock %d\n",*(m)); */\
61 /*if (kMutexLock(*(m)) == ERROR_INVALID_MUTEX) */\
62 /*Perl_croak_nocontext("panic: MUTEX_LOCK"); */\
65 # define MUTEX_UNLOCK(m) \
67 /*ConsolePrintf("Mutex unlock %d\n",*(m)); */\
68 /*if (kMutexUnlock(*(m)) != kSUCCESS) \
69 Perl_croak_nocontext("panic: MUTEX_UNLOCK"); */\
72 # define MUTEX_DESTROY(m) \
74 /*ConsolePrintf("Mutex Destroy %d\n",*(m)); */\
75 /*if (kMutexWaitCount(*(m)) == 0 ) */\
77 /*PERL_SET_INTERP(NULL); *//*newly added CHKSGP???*/ \
78 /*if (kMutexFree(*(m)) != kSUCCESS) */ \
79 /*Perl_croak_nocontext("panic: MUTEX_FREE"); */\
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)
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
95 //For now let us just see when this happens -sgp.
96 #define COND_INIT(c) \
98 ConsolePrintf("In COND_INIT\n"); \
101 /* (c)->waiters = 0; \
102 (c)->sem = OpenLocalSemaphore (0); \
103 if ((c)->sem == NULL) \
104 Perl_croak_nocontext("panic: COND_INIT (%ld)",errno); \*/
106 #define COND_SIGNAL(c) \
108 ConsolePrintf("In COND_SIGNAL\n"); \
110 /*if ((c)->waiters > 0 && \
111 SignalLocalSemaphore((c)->sem) != 0) \
112 Perl_croak_nocontext("panic: COND_SIGNAL (%ld)",errno); \*/
114 #define COND_BROADCAST(c) \
116 ConsolePrintf("In COND_BROADCAST\n"); \
119 /*if ((c)->waiters > 0 ) { \
121 for(count=0; count<(c)->waiters; count++) { \
122 if(SignalLocalSemaphore((c)->sem) != 0) \
123 Perl_croak_nocontext("panic: COND_BROADCAST (%ld)",GetLastError());\
126 #define COND_WAIT(c, m) \
128 ConsolePrintf("In COND_WAIT\n"); \
132 #define COND_DESTROY(c) \
134 ConsolePrintf("In COND_DESTROY\n"); \
137 /* (c)->waiters = 0; \
138 if (CloseLocalSemaphore((c)->sem) != 0) \
139 Perl_croak_nocontext("panic: COND_DESTROY (%ld)",errno); \*/
144 if (CloseHandle((t)->self) == 0) { \
145 MUTEX_UNLOCK(&(t)->mutex); \
146 Perl_croak_nocontext("panic: DETACH"); \
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
157 #define PERL_GET_CONTEXT Perl_get_context()
158 #define PERL_SET_CONTEXT(t) Perl_set_context(t)
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))
165 #define INIT_THREADS NOOP
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 \
171 fnInitializeThreadCtx(); \
175 #endif /* _NW5THREAD_H */