From f7d30133221896638f7bf4f66c504255c4b14f48 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Thu, 2 Jan 2020 21:01:38 +0100 Subject: Issue #1338 - Part 1: Update NSPR to 4.24 --- nsprpub/pr/tests/foreign.c | 291 ++++++++++++++++++++------------------------- 1 file changed, 130 insertions(+), 161 deletions(-) (limited to 'nsprpub/pr/tests/foreign.c') diff --git a/nsprpub/pr/tests/foreign.c b/nsprpub/pr/tests/foreign.c index cfb2e56ef..a711b7580 100644 --- a/nsprpub/pr/tests/foreign.c +++ b/nsprpub/pr/tests/foreign.c @@ -13,7 +13,7 @@ ** in. ** ** The goal: try to survive. -** +** */ #include "prcvar.h" @@ -48,9 +48,9 @@ static PRFileDesc *output; static int _debug_on = 0; -#define DEFAULT_THREAD_COUNT 10 +#define DEFAULT_THREAD_COUNT 10 -#define DPRINTF(arg) if (_debug_on) PR_fprintf arg +#define DPRINTF(arg) if (_debug_on) PR_fprintf arg #if defined(_PR_PTHREADS) #include @@ -65,19 +65,6 @@ static void *pthread_start(void *arg) } /* pthread_start */ #endif /* defined(_PR_PTHREADS) */ -#if defined(IRIX) && !defined(_PR_PTHREADS) -#include -#include -static void sproc_start(void *arg, PRSize size) -{ - StartObject *so = (StartObject*)arg; - StartFn start = so->start; - void *data = so->arg; - PR_Free(so); - start(data); -} /* sproc_start */ -#endif /* defined(IRIX) && !defined(_PR_PTHREADS) */ - #if defined(WIN32) #include #include /* for _beginthreadex() */ @@ -99,16 +86,16 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg) switch (thread_provider) { - case thread_nspr: + case thread_nspr: { PRThread *thread = PR_CreateThread( - PR_USER_THREAD, start, arg, - PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, - PR_UNJOINABLE_THREAD, 0); + PR_USER_THREAD, start, arg, + PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, + PR_UNJOINABLE_THREAD, 0); rv = (NULL == thread) ? PR_FAILURE : PR_SUCCESS; } break; - case thread_pthread: + case thread_pthread: #if defined(_PR_PTHREADS) { int rv; @@ -139,41 +126,27 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg) break; #endif /* defined(_PR_PTHREADS) */ - case thread_sproc: -#if defined(IRIX) && !defined(_PR_PTHREADS) - { - PRInt32 pid; - StartObject *start_object; - start_object = PR_NEW(StartObject); - PR_ASSERT(NULL != start_object); - start_object->start = start; - start_object->arg = arg; - pid = sprocsp( - sproc_start, PR_SALL, start_object, NULL, 64 * 1024); - rv = (0 < pid) ? PR_SUCCESS : PR_FAILURE; - } -#else - PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); - rv = PR_FAILURE; -#endif /* defined(IRIX) && !defined(_PR_PTHREADS) */ - break; - case thread_win32: + case thread_sproc: + PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); + rv = PR_FAILURE; + break; + case thread_win32: #if defined(WIN32) { void *th; - PRUintn id; + PRUintn id; StartObject *start_object; start_object = PR_NEW(StartObject); PR_ASSERT(NULL != start_object); start_object->start = start; start_object->arg = arg; th = (void*)_beginthreadex( - NULL, /* LPSECURITY_ATTRIBUTES - pointer to thread security attributes */ - 0U, /* DWORD - initial thread stack size, in bytes */ - windows_start, /* LPTHREAD_START_ROUTINE - pointer to thread function */ - start_object, /* LPVOID - argument for new thread */ - STACK_SIZE_PARAM_IS_A_RESERVATION, /*DWORD dwCreationFlags - creation flags */ - &id /* LPDWORD - pointer to returned thread identifier */ ); + NULL, /* LPSECURITY_ATTRIBUTES - pointer to thread security attributes */ + 0U, /* DWORD - initial thread stack size, in bytes */ + windows_start, /* LPTHREAD_START_ROUTINE - pointer to thread function */ + start_object, /* LPVOID - argument for new thread */ + STACK_SIZE_PARAM_IS_A_RESERVATION, /*DWORD dwCreationFlags - creation flags */ + &id /* LPDWORD - pointer to returned thread identifier */ ); rv = (NULL == th) ? PR_FAILURE : PR_SUCCESS; } @@ -182,9 +155,9 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg) rv = PR_FAILURE; #endif break; - default: - PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); - rv = PR_FAILURE; + default: + PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); + rv = PR_FAILURE; } return rv; } /* NSPRPUB_TESTS_CreateThread */ @@ -204,139 +177,135 @@ static void OneShot(void *arg) PRFileDesc *pair[2]; PRIntn test = (PRIntn)arg; - for (test = 0; test < 12; ++test) { + for (test = 0; test < 12; ++test) { - switch (test) - { - case 0: - lock = PR_NewLock(); - DPRINTF((output,"Thread[0x%x] called PR_NewLock\n", - PR_GetCurrentThread())); - PR_DestroyLock(lock); - break; - - case 1: - (void)PR_SecondsToInterval(1); - DPRINTF((output,"Thread[0x%x] called PR_SecondsToInterval\n", - PR_GetCurrentThread())); - break; - - case 2: (void)PR_CreateThread( - PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL, - PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0); - DPRINTF((output,"Thread[0x%x] called PR_CreateThread\n", - PR_GetCurrentThread())); - break; - - case 3: - fd = PR_Open("foreign.tmp", PR_CREATE_FILE | PR_RDWR, 0666); - DPRINTF((output,"Thread[0x%x] called PR_Open\n", - PR_GetCurrentThread())); - PR_Close(fd); - break; - - case 4: - fd = PR_NewUDPSocket(); - DPRINTF((output,"Thread[0x%x] called PR_NewUDPSocket\n", - PR_GetCurrentThread())); - PR_Close(fd); - break; - - case 5: - fd = PR_NewTCPSocket(); - DPRINTF((output,"Thread[0x%x] called PR_NewTCPSocket\n", - PR_GetCurrentThread())); - PR_Close(fd); - break; - - case 6: -#ifdef SYMBIAN -#define TEMP_DIR "c:\\data\\" -#else + switch (test) + { + case 0: + lock = PR_NewLock(); + DPRINTF((output,"Thread[0x%x] called PR_NewLock\n", + PR_GetCurrentThread())); + PR_DestroyLock(lock); + break; + + case 1: + (void)PR_SecondsToInterval(1); + DPRINTF((output,"Thread[0x%x] called PR_SecondsToInterval\n", + PR_GetCurrentThread())); + break; + + case 2: (void)PR_CreateThread( + PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL, + PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0); + DPRINTF((output,"Thread[0x%x] called PR_CreateThread\n", + PR_GetCurrentThread())); + break; + + case 3: + fd = PR_Open("foreign.tmp", PR_CREATE_FILE | PR_RDWR, 0666); + DPRINTF((output,"Thread[0x%x] called PR_Open\n", + PR_GetCurrentThread())); + PR_Close(fd); + break; + + case 4: + fd = PR_NewUDPSocket(); + DPRINTF((output,"Thread[0x%x] called PR_NewUDPSocket\n", + PR_GetCurrentThread())); + PR_Close(fd); + break; + + case 5: + fd = PR_NewTCPSocket(); + DPRINTF((output,"Thread[0x%x] called PR_NewTCPSocket\n", + PR_GetCurrentThread())); + PR_Close(fd); + break; + + case 6: #define TEMP_DIR "/tmp/" -#endif - dir = PR_OpenDir(TEMP_DIR); - DPRINTF((output,"Thread[0x%x] called PR_OpenDir\n", - PR_GetCurrentThread())); - PR_CloseDir(dir); - break; - - case 7: - (void)PR_NewThreadPrivateIndex(&pdkey, NULL); - DPRINTF((output,"Thread[0x%x] called PR_NewThreadPrivateIndex\n", - PR_GetCurrentThread())); - break; - - case 8: - (void)PR_GetEnv("PATH"); - DPRINTF((output,"Thread[0x%x] called PR_GetEnv\n", - PR_GetCurrentThread())); - break; - - case 9: - (void)PR_NewTCPSocketPair(pair); - DPRINTF((output,"Thread[0x%x] called PR_NewTCPSocketPair\n", - PR_GetCurrentThread())); - PR_Close(pair[0]); - PR_Close(pair[1]); - break; - - case 10: - PR_SetConcurrency(2); - DPRINTF((output,"Thread[0x%x] called PR_SetConcurrency\n", - PR_GetCurrentThread())); - break; - - case 11: - PR_SetThreadPriority(PR_GetCurrentThread(), PR_PRIORITY_HIGH); - DPRINTF((output,"Thread[0x%x] called PR_SetThreadPriority\n", - PR_GetCurrentThread())); - break; - - default: - break; - } /* switch() */ - } + dir = PR_OpenDir(TEMP_DIR); + DPRINTF((output,"Thread[0x%x] called PR_OpenDir\n", + PR_GetCurrentThread())); + PR_CloseDir(dir); + break; + + case 7: + (void)PR_NewThreadPrivateIndex(&pdkey, NULL); + DPRINTF((output,"Thread[0x%x] called PR_NewThreadPrivateIndex\n", + PR_GetCurrentThread())); + break; + + case 8: + (void)PR_GetEnv("PATH"); + DPRINTF((output,"Thread[0x%x] called PR_GetEnv\n", + PR_GetCurrentThread())); + break; + + case 9: + (void)PR_NewTCPSocketPair(pair); + DPRINTF((output,"Thread[0x%x] called PR_NewTCPSocketPair\n", + PR_GetCurrentThread())); + PR_Close(pair[0]); + PR_Close(pair[1]); + break; + + case 10: + PR_SetConcurrency(2); + DPRINTF((output,"Thread[0x%x] called PR_SetConcurrency\n", + PR_GetCurrentThread())); + break; + + case 11: + PR_SetThreadPriority(PR_GetCurrentThread(), PR_PRIORITY_HIGH); + DPRINTF((output,"Thread[0x%x] called PR_SetThreadPriority\n", + PR_GetCurrentThread())); + break; + + default: + break; + } /* switch() */ + } } /* OneShot */ int main(int argc, char **argv) { PRStatus rv; - PRInt32 thread_cnt = DEFAULT_THREAD_COUNT; - PLOptStatus os; - PLOptState *opt = PL_CreateOptState(argc, argv, "dt:"); + PRInt32 thread_cnt = DEFAULT_THREAD_COUNT; + PLOptStatus os; + PLOptState *opt = PL_CreateOptState(argc, argv, "dt:"); #if defined(WIN32) - thread_provider = thread_win32; + thread_provider = thread_win32; #elif defined(_PR_PTHREADS) - thread_provider = thread_pthread; -#elif defined(IRIX) - thread_provider = thread_sproc; + thread_provider = thread_pthread; #else thread_provider = thread_nspr; #endif - while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) + while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) { - if (PL_OPT_BAD == os) continue; + if (PL_OPT_BAD == os) { + continue; + } switch (opt->option) { - case 'd': /* debug mode */ - _debug_on = 1; - break; - case 't': /* thread count */ - thread_cnt = atoi(opt->value); - break; - default: - break; + case 'd': /* debug mode */ + _debug_on = 1; + break; + case 't': /* thread count */ + thread_cnt = atoi(opt->value); + break; + default: + break; } } - PL_DestroyOptState(opt); + PL_DestroyOptState(opt); - PR_SetConcurrency(2); + PR_SetConcurrency(2); - output = PR_GetSpecialFD(PR_StandardOutput); + output = PR_GetSpecialFD(PR_StandardOutput); while (thread_cnt-- > 0) { -- cgit v1.2.3