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 // The line below is just a definition to avoid compilation error.
31 // It is not being used anywhere.
32 // Ananth, 3 Sept 2001
33 typedef struct nw_cond { long waiters; unsigned int sem; } perl_cond;
35 #if defined (USE_ITHREADS) && defined(MPK_ON)
43 #define ERROR_INVALID_MUTEX (0x1010)
49 //On NetWare, since the NLM will be resident, only once the MUTEX_INIT gets called and
50 //this will be freed when the script terminates. But when a new script is executed,
51 //then MUTEX_LOCK will fail since it is already freed. Even if this problem is fixed
52 //by not freeing the mutex when script terminates but when the NLM unloads, there will
53 //still be problems when multiple scripts are running simultaneously in a multi-processor
55 typedef MUTEX perl_mutex;
56 # define MUTEX_INIT(m) \
58 /*if ((*(m) = kMutexAlloc("NetWarePerlMutex")) == NULL) */\
59 /*Perl_croak_nocontext("panic: MUTEX_ALLOC"); */\
60 /*ConsolePrintf("Mutex Init %d\n",*(m)); */\
63 # define MUTEX_LOCK(m) \
65 /*ConsolePrintf("Mutex lock %d\n",*(m)); */\
66 /*if (kMutexLock(*(m)) == ERROR_INVALID_MUTEX) */\
67 /*Perl_croak_nocontext("panic: MUTEX_LOCK"); */\
70 # define MUTEX_UNLOCK(m) \
72 /*ConsolePrintf("Mutex unlock %d\n",*(m)); */\
73 /*if (kMutexUnlock(*(m)) != kSUCCESS) \
74 Perl_croak_nocontext("panic: MUTEX_UNLOCK"); */\
77 # define MUTEX_DESTROY(m) \
79 /*ConsolePrintf("Mutex Destroy %d\n",*(m)); */\
80 /*if (kMutexWaitCount(*(m)) == 0 ) */\
82 /*PERL_SET_INTERP(NULL); *//*newly added CHKSGP???*/ \
83 /*if (kMutexFree(*(m)) != kSUCCESS) */ \
84 /*Perl_croak_nocontext("panic: MUTEX_FREE"); */\
89 typedef unsigned long perl_mutex;
90 # define MUTEX_INIT(m)
91 # define MUTEX_LOCK(m)
92 # define MUTEX_UNLOCK(m)
93 # define MUTEX_DESTROY(m)
96 /* These macros assume that the mutex associated with the condition
97 * will always be held before COND_{SIGNAL,BROADCAST,WAIT,DESTROY},
98 * so there's no separate mutex protecting access to (c)->waiters
100 //For now let us just see when this happens -sgp.
101 #define COND_INIT(c) \
103 /*ConsolePrintf("In COND_INIT\n"); */\
106 /* (c)->waiters = 0; \
107 (c)->sem = OpenLocalSemaphore (0); \
108 if ((c)->sem == NULL) \
109 Perl_croak_nocontext("panic: COND_INIT (%ld)",errno); \*/
111 #define COND_SIGNAL(c) \
113 /*ConsolePrintf("In COND_SIGNAL\n"); */\
115 /*if ((c)->waiters > 0 && \
116 SignalLocalSemaphore((c)->sem) != 0) \
117 Perl_croak_nocontext("panic: COND_SIGNAL (%ld)",errno); \*/
119 #define COND_BROADCAST(c) \
121 /*ConsolePrintf("In COND_BROADCAST\n"); */\
124 /*if ((c)->waiters > 0 ) { \
126 for(count=0; count<(c)->waiters; count++) { \
127 if(SignalLocalSemaphore((c)->sem) != 0) \
128 Perl_croak_nocontext("panic: COND_BROADCAST (%ld)",GetLastError());\
131 #define COND_WAIT(c, m) \
133 /*ConsolePrintf("In COND_WAIT\n"); */\
137 #define COND_DESTROY(c) \
139 /*ConsolePrintf("In COND_DESTROY\n"); */\
142 /* (c)->waiters = 0; \
143 if (CloseLocalSemaphore((c)->sem) != 0) \
144 Perl_croak_nocontext("panic: COND_DESTROY (%ld)",errno); \*/
149 if (CloseHandle((t)->self) == 0) { \
150 MUTEX_UNLOCK(&(t)->mutex); \
151 Perl_croak_nocontext("panic: DETACH"); \
156 //Following has to be defined CHKSGP
157 #if defined(PERLDLL) && defined(USE_DECLSPEC_THREAD) && (!defined(__BORLANDC__) || defined(_DLL))
158 extern __declspec(thread) void *PL_current_context;
159 #define PERL_SET_CONTEXT(t) (PL_current_context = t)
160 #define PERL_GET_CONTEXT PL_current_context
162 #define PERL_GET_CONTEXT Perl_get_context()
163 #define PERL_SET_CONTEXT(t) Perl_set_context(t)
166 //Check the following, will be used in Thread extension - CHKSGP
167 #define THREAD_RET_TYPE unsigned __stdcall
168 #define THREAD_RET_CAST(p) ((unsigned)(p))
170 #define INIT_THREADS NOOP
172 //Ideally this should have been PL_thr_key = fnInitializeThreadCtx();
173 //See the comment at the end of file nw5thread.c as to why PL_thr_key is not assigned - sgp
174 #define ALLOC_THREAD_KEY \
176 fnInitializeThreadCtx(); \
180 #endif /* _NW5THREAD_H */