summaryrefslogtreecommitdiff
path: root/pr/src/md/windows/ntthread.c
diff options
context:
space:
mode:
Diffstat (limited to 'pr/src/md/windows/ntthread.c')
-rw-r--r--pr/src/md/windows/ntthread.c163
1 files changed, 83 insertions, 80 deletions
diff --git a/pr/src/md/windows/ntthread.c b/pr/src/md/windows/ntthread.c
index 6dd01fb9..395a80dc 100644
--- a/pr/src/md/windows/ntthread.c
+++ b/pr/src/md/windows/ntthread.c
@@ -109,8 +109,8 @@ _PR_MD_EARLY_INIT()
if (hModule) {
sSetThreadDescription =
(SETTHREADDESCRIPTION) GetProcAddress(
- hModule,
- "SetThreadDescription");
+ hModule,
+ "SetThreadDescription");
}
}
@@ -147,13 +147,13 @@ _PR_MD_INIT_THREAD(PRThread *thread)
** the pseudo handle via DuplicateHandle(...)
*/
DuplicateHandle(
- GetCurrentProcess(), /* Process of source handle */
- GetCurrentThread(), /* Pseudo Handle to dup */
- GetCurrentProcess(), /* Process of handle */
- &(thread->md.handle), /* resulting handle */
- 0L, /* access flags */
- FALSE, /* Inheritable */
- DUPLICATE_SAME_ACCESS); /* Options */
+ GetCurrentProcess(), /* Process of source handle */
+ GetCurrentThread(), /* Pseudo Handle to dup */
+ GetCurrentProcess(), /* Process of handle */
+ &(thread->md.handle), /* resulting handle */
+ 0L, /* access flags */
+ FALSE, /* Inheritable */
+ DUPLICATE_SAME_ACCESS); /* Options */
}
/* Create the blocking IO semaphore */
@@ -161,13 +161,13 @@ _PR_MD_INIT_THREAD(PRThread *thread)
if (thread->md.blocked_sema == NULL) {
return PR_FAILURE;
}
- if (_native_threads_only) {
- /* Create the blocking IO semaphore */
- thread->md.thr_event = CreateEvent(NULL, TRUE, FALSE, NULL);
- if (thread->md.thr_event == NULL) {
- return PR_FAILURE;
- }
- }
+ if (_native_threads_only) {
+ /* Create the blocking IO semaphore */
+ thread->md.thr_event = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (thread->md.thr_event == NULL) {
+ return PR_FAILURE;
+ }
+ }
}
return PR_SUCCESS;
@@ -183,21 +183,21 @@ pr_root(void *arg)
PRStatus
_PR_MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+ void (*start)(void *),
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
thread->md.start = start;
thread->md.handle = (HANDLE) _beginthreadex(
- NULL,
- thread->stack->stackSize,
- pr_root,
- (void *)thread,
- CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION,
- &(thread->id));
+ NULL,
+ thread->stack->stackSize,
+ pr_root,
+ (void *)thread,
+ CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION,
+ &(thread->id));
if(!thread->md.handle) {
PRErrorCode prerror;
thread->md.fiber_last_error = GetLastError();
@@ -228,8 +228,9 @@ _PR_MD_CREATE_THREAD(PRThread *thread,
}
/* Activate the thread */
- if ( ResumeThread( thread->md.handle ) != -1)
+ if ( ResumeThread( thread->md.handle ) != -1) {
return PR_SUCCESS;
+ }
PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
return PR_FAILURE;
@@ -284,8 +285,8 @@ _PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
rv = SetThreadPriority(thread->handle, nativePri);
PR_ASSERT(rv);
if (!rv) {
- PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("PR_SetThreadPriority: can't set thread priority\n"));
+ PR_LOG(_pr_thread_lm, PR_LOG_MIN,
+ ("PR_SetThreadPriority: can't set thread priority\n"));
}
return;
}
@@ -295,10 +296,10 @@ const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
- DWORD dwType; // Must be 0x1000.
- LPCSTR szName; // Pointer to name (in user addr space).
- DWORD dwThreadID; // Thread ID (-1=caller thread).
- DWORD dwFlags; // Reserved for future use, must be zero.
+ DWORD dwType; // Must be 0x1000.
+ LPCSTR szName; // Pointer to name (in user addr space).
+ DWORD dwThreadID; // Thread ID (-1=caller thread).
+ DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
@@ -306,32 +307,33 @@ void
_PR_MD_SET_CURRENT_THREAD_NAME(const char *name)
{
#ifdef _MSC_VER
- THREADNAME_INFO info;
+ THREADNAME_INFO info;
#endif
- if (sSetThreadDescription) {
- WCHAR wideName[MAX_PATH];
- if (MultiByteToWideChar(CP_ACP, 0, name, -1, wideName, MAX_PATH)) {
- sSetThreadDescription(GetCurrentThread(), wideName);
- }
- }
+ if (sSetThreadDescription) {
+ WCHAR wideName[MAX_PATH];
+ if (MultiByteToWideChar(CP_ACP, 0, name, -1, wideName, MAX_PATH)) {
+ sSetThreadDescription(GetCurrentThread(), wideName);
+ }
+ }
#ifdef _MSC_VER
- if (!IsDebuggerPresent())
- return;
-
- info.dwType = 0x1000;
- info.szName = (char*) name;
- info.dwThreadID = -1;
- info.dwFlags = 0;
-
- __try {
- RaiseException(MS_VC_EXCEPTION,
- 0,
- sizeof(info) / sizeof(ULONG_PTR),
- (ULONG_PTR*)&info);
- } __except(EXCEPTION_CONTINUE_EXECUTION) {
- }
+ if (!IsDebuggerPresent()) {
+ return;
+ }
+
+ info.dwType = 0x1000;
+ info.szName = (char*) name;
+ info.dwThreadID = -1;
+ info.dwFlags = 0;
+
+ __try {
+ RaiseException(MS_VC_EXCEPTION,
+ 0,
+ sizeof(info) / sizeof(ULONG_PTR),
+ (ULONG_PTR*)&info);
+ } __except(EXCEPTION_CONTINUE_EXECUTION) {
+ }
#endif
}
@@ -353,13 +355,13 @@ _PR_MD_CLEAN_THREAD(PRThread *thread)
PR_ASSERT(rv);
thread->md.blocked_sema = 0;
}
- if (_native_threads_only) {
- if (thread->md.thr_event) {
- rv = CloseHandle(thread->md.thr_event);
- PR_ASSERT(rv);
- thread->md.thr_event = 0;
- }
- }
+ if (_native_threads_only) {
+ if (thread->md.thr_event) {
+ rv = CloseHandle(thread->md.thr_event);
+ PR_ASSERT(rv);
+ thread->md.thr_event = 0;
+ }
+ }
if (thread->md.handle) {
rv = CloseHandle(thread->md.handle);
@@ -399,13 +401,13 @@ _PR_MD_EXIT_THREAD(PRThread *thread)
thread->md.blocked_sema = 0;
}
- if (_native_threads_only) {
- if (thread->md.thr_event) {
- rv = CloseHandle(thread->md.thr_event);
- PR_ASSERT(rv);
- thread->md.thr_event = 0;
- }
- }
+ if (_native_threads_only) {
+ if (thread->md.thr_event) {
+ rv = CloseHandle(thread->md.thr_event);
+ PR_ASSERT(rv);
+ thread->md.thr_event = 0;
+ }
+ }
if (thread->md.handle) {
rv = CloseHandle(thread->md.handle);
@@ -469,9 +471,10 @@ _PR_MD_INIT_CONTEXT(PRThread *thread, char *top, void (*start) (void), PRBool *s
{
thread->md.fiber_fn = (void (*)(void *))start;
thread->md.fiber_id = CreateFiber(thread->md.fiber_stacksize,
- (LPFIBER_START_ROUTINE)_pr_fiber_mainline, NULL);
- if (thread->md.fiber_id != 0)
+ (LPFIBER_START_ROUTINE)_pr_fiber_mainline, NULL);
+ if (thread->md.fiber_id != 0) {
*status = PR_TRUE;
+ }
else {
DWORD oserror = GetLastError();
PRErrorCode prerror;
@@ -573,15 +576,15 @@ _PR_MD_RESUME_THREAD(PRThread *thread)
PRThread*
_MD_CURRENT_THREAD(void)
{
-PRThread *thread;
+ PRThread *thread;
- thread = _MD_GET_ATTACHED_THREAD();
+ thread = _MD_GET_ATTACHED_THREAD();
- if (NULL == thread) {
- thread = _PRI_AttachThread(
- PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
- }
- PR_ASSERT(thread != NULL);
- return thread;
+ if (NULL == thread) {
+ thread = _PRI_AttachThread(
+ PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
+ }
+ PR_ASSERT(thread != NULL);
+ return thread;
}