| 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 |
|
|---|
| 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;
|
|---|
| 34 |
|
|---|
| 35 | #if (defined (USE_ITHREADS) || defined (USE_5005THREADS)) && defined(MPK_ON)
|
|---|
| 36 | #ifdef __cplusplus
|
|---|
| 37 | extern "C"
|
|---|
| 38 | {
|
|---|
| 39 | #endif
|
|---|
| 40 | #include <mpktypes.h>
|
|---|
| 41 | #include <mpkapis.h>
|
|---|
| 42 | #define kSUCCESS (0)
|
|---|
| 43 | #define ERROR_INVALID_MUTEX (0x1010)
|
|---|
| 44 |
|
|---|
| 45 | #ifdef __cplusplus
|
|---|
| 46 | }
|
|---|
| 47 | #endif
|
|---|
| 48 | #undef WORD
|
|---|
| 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
|
|---|
| 54 | //machine - sgp
|
|---|
| 55 | typedef MUTEX perl_mutex;
|
|---|
| 56 | # define MUTEX_INIT(m) \
|
|---|
| 57 | STMT_START { \
|
|---|
| 58 | /*if ((*(m) = kMutexAlloc("NetWarePerlMutex")) == NULL) */\
|
|---|
| 59 | /*Perl_croak_nocontext("panic: MUTEX_ALLOC"); */\
|
|---|
| 60 | /*ConsolePrintf("Mutex Init %d\n",*(m)); */\
|
|---|
| 61 | } STMT_END
|
|---|
| 62 |
|
|---|
| 63 | # define MUTEX_LOCK(m) \
|
|---|
| 64 | STMT_START { \
|
|---|
| 65 | /*ConsolePrintf("Mutex lock %d\n",*(m)); */\
|
|---|
| 66 | /*if (kMutexLock(*(m)) == ERROR_INVALID_MUTEX) */\
|
|---|
| 67 | /*Perl_croak_nocontext("panic: MUTEX_LOCK"); */\
|
|---|
| 68 | } STMT_END
|
|---|
| 69 |
|
|---|
| 70 | # define MUTEX_UNLOCK(m) \
|
|---|
| 71 | STMT_START { \
|
|---|
| 72 | /*ConsolePrintf("Mutex unlock %d\n",*(m)); */\
|
|---|
| 73 | /*if (kMutexUnlock(*(m)) != kSUCCESS) \
|
|---|
| 74 | Perl_croak_nocontext("panic: MUTEX_UNLOCK"); */\
|
|---|
| 75 | } STMT_END
|
|---|
| 76 |
|
|---|
| 77 | # define MUTEX_DESTROY(m) \
|
|---|
| 78 | STMT_START { \
|
|---|
| 79 | /*ConsolePrintf("Mutex Destroy %d\n",*(m)); */\
|
|---|
| 80 | /*if (kMutexWaitCount(*(m)) == 0 ) */\
|
|---|
| 81 | /*{ */\
|
|---|
| 82 | /*PERL_SET_INTERP(NULL); *//*newly added CHKSGP???*/ \
|
|---|
| 83 | /*if (kMutexFree(*(m)) != kSUCCESS) */ \
|
|---|
| 84 | /*Perl_croak_nocontext("panic: MUTEX_FREE"); */\
|
|---|
| 85 | /*} */\
|
|---|
| 86 | } STMT_END
|
|---|
| 87 |
|
|---|
| 88 | #else
|
|---|
| 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)
|
|---|
| 94 | #endif
|
|---|
| 95 |
|
|---|
| 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
|
|---|
| 99 | */
|
|---|
| 100 | //For now let us just see when this happens -sgp.
|
|---|
| 101 | #define COND_INIT(c) \
|
|---|
| 102 | STMT_START { \
|
|---|
| 103 | /*ConsolePrintf("In COND_INIT\n"); */\
|
|---|
| 104 | } STMT_END
|
|---|
| 105 |
|
|---|
| 106 | /* (c)->waiters = 0; \
|
|---|
| 107 | (c)->sem = OpenLocalSemaphore (0); \
|
|---|
| 108 | if ((c)->sem == NULL) \
|
|---|
| 109 | Perl_croak_nocontext("panic: COND_INIT (%ld)",errno); \*/
|
|---|
| 110 |
|
|---|
| 111 | #define COND_SIGNAL(c) \
|
|---|
| 112 | STMT_START { \
|
|---|
| 113 | /*ConsolePrintf("In COND_SIGNAL\n"); */\
|
|---|
| 114 | } STMT_END
|
|---|
| 115 | /*if ((c)->waiters > 0 && \
|
|---|
| 116 | SignalLocalSemaphore((c)->sem) != 0) \
|
|---|
| 117 | Perl_croak_nocontext("panic: COND_SIGNAL (%ld)",errno); \*/
|
|---|
| 118 |
|
|---|
| 119 | #define COND_BROADCAST(c) \
|
|---|
| 120 | STMT_START { \
|
|---|
| 121 | /*ConsolePrintf("In COND_BROADCAST\n"); */\
|
|---|
| 122 | } STMT_END
|
|---|
| 123 |
|
|---|
| 124 | /*if ((c)->waiters > 0 ) { \
|
|---|
| 125 | int count; \
|
|---|
| 126 | for(count=0; count<(c)->waiters; count++) { \
|
|---|
| 127 | if(SignalLocalSemaphore((c)->sem) != 0) \
|
|---|
| 128 | Perl_croak_nocontext("panic: COND_BROADCAST (%ld)",GetLastError());\
|
|---|
| 129 | } \
|
|---|
| 130 | } \*/
|
|---|
| 131 | #define COND_WAIT(c, m) \
|
|---|
| 132 | STMT_START { \
|
|---|
| 133 | /*ConsolePrintf("In COND_WAIT\n"); */\
|
|---|
| 134 | } STMT_END
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 | #define COND_DESTROY(c) \
|
|---|
| 138 | STMT_START { \
|
|---|
| 139 | /*ConsolePrintf("In COND_DESTROY\n"); */\
|
|---|
| 140 | } STMT_END
|
|---|
| 141 |
|
|---|
| 142 | /* (c)->waiters = 0; \
|
|---|
| 143 | if (CloseLocalSemaphore((c)->sem) != 0) \
|
|---|
| 144 | Perl_croak_nocontext("panic: COND_DESTROY (%ld)",errno); \*/
|
|---|
| 145 |
|
|---|
| 146 | #if 0
|
|---|
| 147 | #define DETACH(t) \
|
|---|
| 148 | STMT_START { \
|
|---|
| 149 | if (CloseHandle((t)->self) == 0) { \
|
|---|
| 150 | MUTEX_UNLOCK(&(t)->mutex); \
|
|---|
| 151 | Perl_croak_nocontext("panic: DETACH"); \
|
|---|
| 152 | } \
|
|---|
| 153 | } STMT_END
|
|---|
| 154 | #endif //#if 0
|
|---|
| 155 |
|
|---|
| 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
|
|---|
| 161 | #else
|
|---|
| 162 | #define PERL_GET_CONTEXT Perl_get_context()
|
|---|
| 163 | #define PERL_SET_CONTEXT(t) Perl_set_context(t)
|
|---|
| 164 | #endif
|
|---|
| 165 |
|
|---|
| 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))
|
|---|
| 169 |
|
|---|
| 170 | #define INIT_THREADS NOOP
|
|---|
| 171 |
|
|---|
| 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 \
|
|---|
| 175 | STMT_START { \
|
|---|
| 176 | fnInitializeThreadCtx(); \
|
|---|
| 177 | } STMT_END
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 | #endif /* _NW5THREAD_H */
|
|---|
| 181 |
|
|---|