Bug 1791179 - Fix mistaken conditional in StaticPrefs. r=dragana, a=RyanVM
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */#include"primpl.h"#include<process.h> /* for _beginthreadex() */#if defined(_MSC_VER) && _MSC_VER <= 1200/* * VC++ 6.0 doesn't have DWORD_PTR. */typedefDWORDDWORD_PTR;#endif /* _MSC_VER <= 1200 *//* --- globals ------------------------------------------------ */#ifdef _PR_USE_STATIC_TLS__declspec(thread)structPRThread*_pr_thread_last_run;__declspec(thread)structPRThread*_pr_currentThread;__declspec(thread)struct_PRCPU*_pr_currentCPU;#elseDWORD_pr_currentThreadIndex;DWORD_pr_lastThreadIndex;DWORD_pr_currentCPUIndex;#endifint_pr_intsOff=0;_PRInterruptTable_pr_interruptTable[]={{0}};typedefHRESULT(WINAPI*SETTHREADDESCRIPTION)(HANDLE,PCWSTR);staticSETTHREADDESCRIPTIONsSetThreadDescription=NULL;void_PR_MD_EARLY_INIT(){HMODULEhModule;#ifndef _PR_USE_STATIC_TLS_pr_currentThreadIndex=TlsAlloc();_pr_lastThreadIndex=TlsAlloc();_pr_currentCPUIndex=TlsAlloc();#endif#if defined(_WIN64) && defined(WIN95)_fd_waiting_for_overlapped_done_lock=PR_NewLock();#endif// SetThreadDescription is Windows 10 build 1607+hModule=GetModuleHandleW(L"kernel32.dll");if(hModule){sSetThreadDescription=(SETTHREADDESCRIPTION)GetProcAddress(hModule,"SetThreadDescription");}}void_PR_MD_CLEANUP_BEFORE_EXIT(void){_PR_NT_FreeSids();_PR_MD_CleanupSockets();WSACleanup();#ifndef _PR_USE_STATIC_TLSTlsFree(_pr_currentThreadIndex);TlsFree(_pr_lastThreadIndex);TlsFree(_pr_currentCPUIndex);#endif#if defined(_WIN64) && defined(WIN95)// For each iteration check if TFO overlapped IOs are down.if(_fd_waiting_for_overlapped_done_lock){PRIntervalTimedelay=PR_MillisecondsToInterval(1000);PRFileDescList*cur;do{CheckOverlappedPendingSocketsAreDone();PR_Lock(_fd_waiting_for_overlapped_done_lock);cur=_fd_waiting_for_overlapped_done;PR_Unlock(_fd_waiting_for_overlapped_done_lock);#if defined(DO_NOT_WAIT_FOR_CONNECT_OVERLAPPED_OPERATIONS)cur=NULL;#endifif(cur){PR_Sleep(delay);// wait another 1s.}}while(cur);PR_DestroyLock(_fd_waiting_for_overlapped_done_lock);}#endif}PRStatus_PR_MD_INIT_THREAD(PRThread*thread){if(thread->flags&(_PR_PRIMORDIAL|_PR_ATTACHED)){/* ** Warning: ** -------- ** NSPR requires a real handle to every thread. ** GetCurrentThread() returns a pseudo-handle which ** is not suitable for some thread operations (e.g., ** suspending). Therefore, get a real handle from ** the pseudo handle via DuplicateHandle(...) */BOOLok=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 */if(!ok){returnPR_FAILURE;}thread->id=GetCurrentThreadId();thread->md.id=thread->id;}/* Create the blocking IO semaphore */thread->md.blocked_sema=CreateSemaphore(NULL,0,1,NULL);if(thread->md.blocked_sema==NULL){returnPR_FAILURE;}else{returnPR_SUCCESS;}}staticunsigned__stdcallpr_root(void*arg){PRThread*thread=(PRThread*)arg;thread->md.start(thread);return0;}PRStatus_PR_MD_CREATE_THREAD(PRThread*thread,void(*start)(void*),PRThreadPrioritypriority,PRThreadScopescope,PRThreadStatestate,PRUint32stackSize){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));if(!thread->md.handle){returnPR_FAILURE;}thread->md.id=thread->id;/* * On windows, a thread is created with a thread priority of * THREAD_PRIORITY_NORMAL. */if(priority!=PR_PRIORITY_NORMAL){_PR_MD_SET_PRIORITY(&(thread->md),priority);}/* Activate the thread */if(ResumeThread(thread->md.handle)!=-1){returnPR_SUCCESS;}returnPR_FAILURE;}void_PR_MD_YIELD(void){/* Can NT really yield at all? */Sleep(0);}void_PR_MD_SET_PRIORITY(_MDThread*thread,PRThreadPrioritynewPri){intnativePri;BOOLrv;if(newPri<PR_PRIORITY_FIRST){newPri=PR_PRIORITY_FIRST;}elseif(newPri>PR_PRIORITY_LAST){newPri=PR_PRIORITY_LAST;}switch(newPri){casePR_PRIORITY_LOW:nativePri=THREAD_PRIORITY_BELOW_NORMAL;break;casePR_PRIORITY_NORMAL:nativePri=THREAD_PRIORITY_NORMAL;break;casePR_PRIORITY_HIGH:nativePri=THREAD_PRIORITY_ABOVE_NORMAL;break;casePR_PRIORITY_URGENT:nativePri=THREAD_PRIORITY_HIGHEST;}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"));}return;}constDWORDMS_VC_EXCEPTION=0x406D1388;#pragma pack(push,8)typedefstructtagTHREADNAME_INFO{DWORDdwType;// Must be 0x1000.LPCSTRszName;// Pointer to name (in user addr space).DWORDdwThreadID;// Thread ID (-1=caller thread).DWORDdwFlags;// Reserved for future use, must be zero.}THREADNAME_INFO;#pragma pack(pop)void_PR_MD_SET_CURRENT_THREAD_NAME(constchar*name){#ifdef _MSC_VERTHREADNAME_INFOinfo;#endifif(sSetThreadDescription){WCHARwideName[MAX_PATH];if(MultiByteToWideChar(CP_ACP,0,name,-1,wideName,MAX_PATH)){sSetThreadDescription(GetCurrentThread(),wideName);}}#ifdef _MSC_VERif(!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}void_PR_MD_CLEAN_THREAD(PRThread*thread){BOOLrv;if(thread->md.blocked_sema){rv=CloseHandle(thread->md.blocked_sema);PR_ASSERT(rv);thread->md.blocked_sema=0;}if(thread->md.handle){rv=CloseHandle(thread->md.handle);PR_ASSERT(rv);thread->md.handle=0;}}void_PR_MD_EXIT_THREAD(PRThread*thread){_PR_MD_CLEAN_THREAD(thread);_PR_MD_SET_CURRENT_THREAD(NULL);}void_PR_MD_EXIT(PRIntnstatus){_exit(status);}PRInt32_PR_MD_SETTHREADAFFINITYMASK(PRThread*thread,PRUint32mask){#ifdef WINCESetLastError(ERROR_CALL_NOT_IMPLEMENTED);return-1;#elseDWORD_PTRrv;rv=SetThreadAffinityMask(thread->md.handle,mask);returnrv?0:-1;#endif}PRInt32_PR_MD_GETTHREADAFFINITYMASK(PRThread*thread,PRUint32*mask){#ifdef WINCESetLastError(ERROR_CALL_NOT_IMPLEMENTED);return-1;#elseBOOLrv;DWORD_PTRprocess_mask;DWORD_PTRsystem_mask;rv=GetProcessAffinityMask(GetCurrentProcess(),&process_mask,&system_mask);if(rv){*mask=(PRUint32)process_mask;}returnrv?0:-1;#endif}void_PR_MD_SUSPEND_CPU(_PRCPU*cpu){_PR_MD_SUSPEND_THREAD(cpu->thread);}void_PR_MD_RESUME_CPU(_PRCPU*cpu){_PR_MD_RESUME_THREAD(cpu->thread);}void_PR_MD_SUSPEND_THREAD(PRThread*thread){if(_PR_IS_NATIVE_THREAD(thread)){DWORDpreviousSuspendCount;/* XXXMB - SuspendThread() is not a blocking call; how do we * know when the thread is *REALLY* suspended? */previousSuspendCount=SuspendThread(thread->md.handle);PR_ASSERT(previousSuspendCount==0);}}void_PR_MD_RESUME_THREAD(PRThread*thread){if(_PR_IS_NATIVE_THREAD(thread)){DWORDpreviousSuspendCount;previousSuspendCount=ResumeThread(thread->md.handle);PR_ASSERT(previousSuspendCount==1);}}PRThread*_MD_CURRENT_THREAD(void){PRThread*thread;thread=_MD_GET_ATTACHED_THREAD();if(NULL==thread){thread=_PRI_AttachThread(PR_USER_THREAD,PR_PRIORITY_NORMAL,NULL,0);}PR_ASSERT(thread!=NULL);returnthread;}