Skip to content

Commit 60ffd0e

Browse files
Restore HEAD of TSRM to what it was two days ago.
1 parent 926bd5c commit 60ffd0e

File tree

10 files changed

+289
-214
lines changed

10 files changed

+289
-214
lines changed

TSRM/TSRM.c

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ TSRM_API void tsrm_shutdown(void)
158158

159159
next_p = p->next;
160160
for (j=0; j<id_count; j++) {
161+
if (resource_types_table && resource_types_table[j].dtor) {
162+
resource_types_table[j].dtor(p->storage[j], &p->storage);
163+
}
161164
free(p->storage[j]);
162165
}
163166
free(p->storage);
@@ -290,6 +293,15 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
290293
int hash_value;
291294
tsrm_tls_entry *thread_resources;
292295

296+
#ifdef NETWARE
297+
/* The below if loop is added for NetWare to fix an abend while unloading PHP
298+
* when an Apache unload command is issued on the system console.
299+
* While exiting from PHP, at the end for some reason, this function is called
300+
* with tsrm_tls_table = NULL. When this happened, the server abends when
301+
* tsrm_tls_table is accessed since it is NULL.
302+
*/
303+
if(tsrm_tls_table) {
304+
#endif
293305
if (!th_id) {
294306
#if defined(PTHREADS)
295307
/* Fast path for looking up the resources for the current
@@ -352,6 +364,9 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
352364
* changes to the structure as we read it.
353365
*/
354366
TSRM_SAFE_RETURN_RSRC(thread_resources->storage, id, thread_resources->count);
367+
#ifdef NETWARE
368+
} /* if(tsrm_tls_table) */
369+
#endif
355370
}
356371

357372

@@ -419,7 +434,12 @@ TSRM_API THREAD_T tsrm_thread_id(void)
419434
#ifdef TSRM_WIN32
420435
return GetCurrentThreadId();
421436
#elif defined(NETWARE)
422-
return NXThreadGetId();
437+
/* There seems to be some problem with the LibC call: NXThreadGetId().
438+
* Due to this, the PHPMyAdmin application is abending in PHP calls.
439+
* Used the call, kCurrentThread instead and it works fine.
440+
*/
441+
/* return NXThreadGetId(); */
442+
return kCurrentThread();
423443
#elif defined(GNUPTH)
424444
return pth_self();
425445
#elif defined(PTHREADS)
@@ -441,16 +461,23 @@ TSRM_API MUTEX_T tsrm_mutex_alloc(void)
441461
{
442462
MUTEX_T mutexp;
443463
#ifdef NETWARE
444-
long flags = 0; /* Don't require NX_MUTEX_RECURSIVE, I guess */
464+
#ifndef USE_MPK
465+
/* To use the Recursive Mutex Locking of LibC */
466+
long flags = NX_MUTEX_RECURSIVE;
445467
NXHierarchy_t order = 0;
446468
NX_LOCK_INFO_ALLOC (lockInfo, "PHP-TSRM", 0);
447-
#endif
469+
#endif
470+
#endif
448471

449472
#ifdef TSRM_WIN32
450473
mutexp = malloc(sizeof(CRITICAL_SECTION));
451474
InitializeCriticalSection(mutexp);
452475
#elif defined(NETWARE)
453-
mutexp = NXMutexAlloc(flags, order, &lockInfo); /* return value ignored for now */
476+
#ifdef USE_MPK
477+
mutexp = kMutexAlloc((BYTE*)"PHP-TSRM");
478+
#else
479+
mutexp = NXMutexAlloc(flags, order, &lockInfo);
480+
#endif
454481
#elif defined(GNUPTH)
455482
mutexp = (MUTEX_T) malloc(sizeof(*mutexp));
456483
pth_mutex_init(mutexp);
@@ -481,8 +508,13 @@ TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
481508
if (mutexp) {
482509
#ifdef TSRM_WIN32
483510
DeleteCriticalSection(mutexp);
511+
free(mutexp);
484512
#elif defined(NETWARE)
513+
#ifdef USE_MPK
514+
kMutexFree(mutexp);
515+
#else
485516
NXMutexFree(mutexp);
517+
#endif
486518
#elif defined(GNUPTH)
487519
free(mutexp);
488520
#elif defined(PTHREADS)
@@ -513,7 +545,11 @@ TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
513545
EnterCriticalSection(mutexp);
514546
return 1;
515547
#elif defined(NETWARE)
548+
#ifdef USE_MPK
549+
return kMutexLock(mutexp);
550+
#else
516551
return NXLock(mutexp);
552+
#endif
517553
#elif defined(GNUPTH)
518554
return pth_mutex_acquire(mutexp, 0, NULL);
519555
#elif defined(PTHREADS)
@@ -540,7 +576,11 @@ TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp)
540576
LeaveCriticalSection(mutexp);
541577
return 1;
542578
#elif defined(NETWARE)
579+
#ifdef USE_MPK
580+
return kMutexUnlock(mutexp);
581+
#else
543582
return NXUnlock(mutexp);
583+
#endif
544584
#elif defined(GNUPTH)
545585
return pth_mutex_release(mutexp);
546586
#elif defined(PTHREADS)

TSRM/TSRM.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,17 @@
3737
#ifdef ZTS
3838

3939
#ifdef TSRM_WIN32
40+
# ifndef TSRM_INCLUDE_FULL_WINDOWS_HEADERS
41+
# define WIN32_LEAN_AND_MEAN
42+
# endif
4043
# include <windows.h>
4144
#elif defined(NETWARE)
4245
# include <nks/thread.h>
46+
#ifdef USE_MPK
47+
# include <mpklib4php.h>
48+
#else
4349
# include <nks/synch.h>
50+
#endif
4451
#elif defined(GNUPTH)
4552
# include <pth.h>
4653
#elif defined(PTHREADS)
@@ -60,7 +67,11 @@ typedef int ts_rsrc_id;
6067
# define MUTEX_T CRITICAL_SECTION *
6168
#elif defined(NETWARE)
6269
# define THREAD_T NXThreadId_t
70+
#ifdef USE_MPK
71+
# define MUTEX_T MUTEX
72+
#else
6373
# define MUTEX_T NXMutex_t *
74+
#endif
6475
#elif defined(GNUPTH)
6576
# define THREAD_T pth_t
6677
# define MUTEX_T pth_mutex_t *
@@ -138,6 +149,8 @@ TSRM_API void *tsrm_set_new_thread_end_handler(tsrm_thread_end_func_t new_thread
138149
#define TSRM_UNSHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)-1)
139150

140151
#define TSRMLS_FETCH() void ***tsrm_ls = (void ***) ts_resource_ex(0, NULL)
152+
#define TSRMLS_FETCH_FROM_CTX(ctx) void ***tsrm_ls = (void ***) ctx
153+
#define TSRMLS_SET_CTX(ctx) (void ***) ctx = tsrm_ls
141154
#define TSRMG(id, type, element) (((type) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)
142155
#define TSRMLS_D void ***tsrm_ls
143156
#define TSRMLS_DC , TSRMLS_D
@@ -151,6 +164,8 @@ TSRM_API void *tsrm_set_new_thread_end_handler(tsrm_thread_end_func_t new_thread
151164
#else /* non ZTS */
152165

153166
#define TSRMLS_FETCH()
167+
#define TSRMLS_FETCH_FROM_CTX(ctx)
168+
#define TSRMLS_SET_CTX(ctx)
154169
#define TSRMLS_D void
155170
#define TSRMLS_DC
156171
#define TSRMLS_C

TSRM/tsrm_config.nw.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#define HAVE_UTIME 1
55

6-
/* Though we have alloca(), this seems to be causing some problem with the stack pointer -- hence not using it */
7-
/* #define HAVE_ALLOCA 1 */
6+
/* Though we have alloca(), this seems to be causing some problem
7+
* with the stack pointer. Hence not using it
8+
*/
9+
/*#define HAVE_ALLOCA 1*/
810

911
#endif

TSRM/tsrm_config_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#pragma alloca
2626
# else
2727
# ifndef alloca /* predefined by HP cc +Olibcalls */
28+
# ifndef NETWARE
2829
char *alloca ();
30+
# endif
2931
# endif
3032
# endif
3133
# endif

0 commit comments

Comments
 (0)