summaryrefslogtreecommitdiff
path: root/NetWare/nw5thread.h
blob: 6bdba245b5dd29c553d38c4a6558adfcaaf07b7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

/*
 * Copyright © 2001 Novell, Inc. All Rights Reserved.
 *
 * You may distribute under the terms of either the GNU General Public
 * License or the Artistic License, as specified in the README file.
 *
 */

/*
 * FILENAME		:	nw5thread.h
 * DESCRIPTION	:	Thread related functions.
 * Author		:	SGP
 * Date			:	January 2001.
 *
 */



#ifndef _NW5THREAD_H
#define _NW5THREAD_H


#include <nwthread.h>

#include "netware.h"

typedef long perl_key;

// The line below is just a definition to avoid compilation error.
// It is not being used anywhere.
// Ananth, 3 Sept 2001
typedef struct nw_cond { long waiters; unsigned int sem; } perl_cond;

#if defined (USE_ITHREADS) && defined(MPK_ON)
#ifdef __cplusplus
extern "C"
{
#endif
	#include <mpktypes.h>
	#include <mpkapis.h>
	#define kSUCCESS	(0)
	#define ERROR_INVALID_MUTEX  (0x1010)

#ifdef __cplusplus
}
#endif
#undef WORD
//On NetWare, since the NLM will be resident, only once the MUTEX_INIT gets called and
//this will be freed when the script terminates.  But when a new script is executed,
//then MUTEX_LOCK will fail since it is already freed.  Even if this problem is fixed
//by not freeing the mutex when script terminates but when the NLM unloads, there will
//still be problems when multiple scripts are running simultaneously in a multi-processor
//machine - sgp
typedef MUTEX perl_mutex;
#  define MUTEX_INIT(m) \
    STMT_START {						\
	/*if ((*(m) = kMutexAlloc("NetWarePerlMutex")) == NULL)	*/\
	    /*Perl_croak_nocontext("panic: MUTEX_ALLOC");		*/\
	/*ConsolePrintf("Mutex Init %d\n",*(m));	*/\
    } STMT_END

#  define MUTEX_LOCK(m) \
    STMT_START {						\
	/*ConsolePrintf("Mutex lock %d\n",*(m));	*/\
	/*if (kMutexLock(*(m)) == ERROR_INVALID_MUTEX)	*/\
	    /*Perl_croak_nocontext("panic: MUTEX_LOCK");		*/\
    } STMT_END

#  define MUTEX_UNLOCK(m) \
    STMT_START {						\
	/*ConsolePrintf("Mutex unlock %d\n",*(m));	*/\
	/*if (kMutexUnlock(*(m)) != kSUCCESS)				\
	    Perl_croak_nocontext("panic: MUTEX_UNLOCK");	*/\
    } STMT_END

#  define MUTEX_DESTROY(m) \
    STMT_START {						\
	/*ConsolePrintf("Mutex Destroy %d\n",*(m));	*/\
	/*if (kMutexWaitCount(*(m)) == 0 )	*/\
	/*{	*/\
		/*PERL_SET_INTERP(NULL); *//*newly added CHKSGP???*/	\
		/*if (kMutexFree(*(m)) != kSUCCESS)			*/	\
			/*Perl_croak_nocontext("panic: MUTEX_FREE");	*/\
	/*}	*/\
    } STMT_END

#else
typedef unsigned long perl_mutex;
#  define MUTEX_INIT(m)
#  define MUTEX_LOCK(m)
#  define MUTEX_UNLOCK(m)
#  define MUTEX_DESTROY(m)
#endif

/* These macros assume that the mutex associated with the condition
 * will always be held before COND_{SIGNAL,BROADCAST,WAIT,DESTROY},
 * so there's no separate mutex protecting access to (c)->waiters
 */
//For now let us just see when this happens -sgp.
#define COND_INIT(c) \
    STMT_START {						\
	/*ConsolePrintf("In COND_INIT\n");	*/\
    } STMT_END

/*	(c)->waiters = 0;					\
	(c)->sem = OpenLocalSemaphore (0);	\
	if ((c)->sem == NULL)					\
	    Perl_croak_nocontext("panic: COND_INIT (%ld)",errno);	\*/

#define COND_SIGNAL(c) \
    STMT_START {						\
	/*ConsolePrintf("In COND_SIGNAL\n");	*/\
    } STMT_END
/*if ((c)->waiters > 0 &&					\
	    SignalLocalSemaphore((c)->sem) != 0)		\
	    Perl_croak_nocontext("panic: COND_SIGNAL (%ld)",errno);	\*/

#define COND_BROADCAST(c) \
    STMT_START {						\
	/*ConsolePrintf("In COND_BROADCAST\n");	*/\
    } STMT_END

	/*if ((c)->waiters > 0 ) {					\
		int count;	\
		for(count=0; count<(c)->waiters; count++) {	\
			if(SignalLocalSemaphore((c)->sem) != 0)	\
				Perl_croak_nocontext("panic: COND_BROADCAST (%ld)",GetLastError());\
		}	\
	}	\*/
#define COND_WAIT(c, m) \
    STMT_START {						\
	/*ConsolePrintf("In COND_WAIT\n");	*/\
    } STMT_END


#define COND_DESTROY(c) \
    STMT_START {						\
	/*ConsolePrintf("In COND_DESTROY\n");	*/\
    } STMT_END

/*		(c)->waiters = 0;					\
	if (CloseLocalSemaphore((c)->sem) != 0)				\
	    Perl_croak_nocontext("panic: COND_DESTROY (%ld)",errno);	\*/

#if 0
#define DETACH(t) \
    STMT_START {						\
	if (CloseHandle((t)->self) == 0) {			\
	    MUTEX_UNLOCK(&(t)->mutex);				\
	    Perl_croak_nocontext("panic: DETACH");		\
	}							\
    } STMT_END
#endif	//#if 0

//Following has to be defined CHKSGP
#if defined(PERLDLL) && defined(USE_DECLSPEC_THREAD) && (!defined(__BORLANDC__) || defined(_DLL))
extern __declspec(thread) void *PL_current_context;
#define PERL_SET_CONTEXT(t)   		(PL_current_context = t)
#define PERL_GET_CONTEXT		PL_current_context
#else
#define PERL_GET_CONTEXT		Perl_get_context()
#define PERL_SET_CONTEXT(t)		Perl_set_context(t)
#endif

//Check the following, will be used in Thread extension - CHKSGP
#define THREAD_RET_TYPE	unsigned __stdcall
#define THREAD_RET_CAST(p)	((unsigned)(p))

#define INIT_THREADS		NOOP

//Ideally this should have been PL_thr_key = fnInitializeThreadCtx();
//See the comment at the end of file nw5thread.c as to why PL_thr_key is not assigned - sgp
#define ALLOC_THREAD_KEY \
    STMT_START {							\
	fnInitializeThreadCtx();			\
    } STMT_END


#endif /* _NW5THREAD_H */