summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAditya Mandaleeka <adityam@microsoft.com>2015-10-22 23:49:43 -0700
committerAditya Mandaleeka <adityam@microsoft.com>2015-10-26 17:38:36 -0700
commit483c6e304be6270e1b0be6b9620463c78b8bd44c (patch)
treeaa918d4e1c742e2fd08687478d551b414283df9a
parent67737a56452fd69533bf61006db91c3b3a416a55 (diff)
downloadcoreclr-483c6e304be6270e1b0be6b9620463c78b8bd44c.tar.gz
coreclr-483c6e304be6270e1b0be6b9620463c78b8bd44c.tar.bz2
coreclr-483c6e304be6270e1b0be6b9620463c78b8bd44c.zip
Remove Enter/LeaveUnsafeRegion
-rw-r--r--src/pal/src/cruntime/filecrt.cpp29
-rw-r--r--src/pal/src/cruntime/malloc.cpp8
-rw-r--r--src/pal/src/cruntime/misc.cpp2
-rw-r--r--src/pal/src/cruntime/printfcpp.cpp25
-rw-r--r--src/pal/src/file/find.cpp2
-rw-r--r--src/pal/src/include/pal/threadsusp.hpp4
-rw-r--r--src/pal/src/memory/heap.cpp9
-rw-r--r--src/pal/src/misc/identity.cpp3
-rw-r--r--src/pal/src/sync/cs.cpp93
-rw-r--r--src/pal/src/thread/threadsusp.cpp62
10 files changed, 20 insertions, 217 deletions
diff --git a/src/pal/src/cruntime/filecrt.cpp b/src/pal/src/cruntime/filecrt.cpp
index 9c35178301..f7cc20f592 100644
--- a/src/pal/src/cruntime/filecrt.cpp
+++ b/src/pal/src/cruntime/filecrt.cpp
@@ -183,9 +183,7 @@ CorUnix::InternalFflush(
)
{
int nRet = 0;
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
nRet = fflush(stream);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
return nRet;
}
@@ -242,9 +240,7 @@ CorUnix::InternalGetcwd(
if (szBuf == NULL)
{
// malloc is used to allocate space to store the pathname when szBuf is NULL.
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
szBufCopy = (char *)getcwd(szBuf, nSize);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
}
else
{
@@ -297,13 +293,11 @@ CorUnix::InternalMkstemp(
)
{
int nRet = -1;
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
#if MKSTEMP64_IS_USED_INSTEAD_OF_MKSTEMP
nRet = mkstemp64(szNameTemplate);
#else
nRet = mkstemp(szNameTemplate);
#endif
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
return nRet;
}
@@ -384,13 +378,11 @@ CorUnix::InternalOpen(
va_end(ap);
}
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
#if OPEN64_IS_USED_INSTEAD_OF_OPEN
nRet = open64(szPath, nFlags, mode);
#else
nRet = open(szPath, nFlags, mode);
#endif
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
return nRet;
}
@@ -437,10 +429,8 @@ CorUnix::InternalUnlink(
)
{
int nRet = -1;
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
nRet = unlink(szPath);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
- return nRet;
+ return nRet;
}
@@ -465,14 +455,12 @@ CorUnix::InternalDeleteFile(
)
{
int nRet = -1;
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
#if defined(__APPLE__) && defined(SYS_delete)
nRet = syscall(SYS_delete, szPath);
#else
nRet = unlink(szPath);
#endif // defined(__APPLE__) && defined(SYS_delete)
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
- return nRet;
+ return nRet;
}
@@ -524,9 +512,7 @@ CorUnix::InternalRename(
)
{
int nRet = -1;
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
nRet = rename(szOldName, szNewName);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
return nRet;
}
@@ -618,9 +604,7 @@ CorUnix::InternalFgets(
do
{
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
retval = fgets(sz, nSize, f);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
if (NULL==retval)
{
if (feof(f))
@@ -651,7 +635,7 @@ CorUnix::InternalFgets(
}
}
} while(NULL == retval);
-
+
return retval;
}
@@ -687,7 +671,7 @@ PAL_fwrite(
_ASSERTE(pf != NULL);
nWrittenBytes = InternalFwrite(InternalGetCurrentThread(), pvBuffer, nSize, nCount, pf->bsdFilePtr, &pf->PALferrorCode);
-
+
LOGEXIT( "fwrite returning size_t %d\n", nWrittenBytes );
PERF_EXIT(fwrite);
return nWrittenBytes;
@@ -730,9 +714,7 @@ CorUnix::InternalFwrite(
clearerr(f);
#endif
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
nWrittenBytes = fwrite(pvBuffer, nSize, nCount, f);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
// Make sure no error ocurred.
if ( nWrittenBytes < nCount )
@@ -808,9 +790,6 @@ CorUnix::InternalFseek(
int nRet = -1;
_ASSERTE(f != NULL);
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
nRet = fseek(f, lOffset, nWhence);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
return nRet;
}
-
diff --git a/src/pal/src/cruntime/malloc.cpp b/src/pal/src/cruntime/malloc.cpp
index 36587dbd81..665a027374 100644
--- a/src/pal/src/cruntime/malloc.cpp
+++ b/src/pal/src/cruntime/malloc.cpp
@@ -65,9 +65,7 @@ CorUnix::InternalRealloc(
}
else
{
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
pvMem = realloc(pvMemblock, szSize);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
}
LOGEXIT("realloc returns void * %p\n", pvMem);
@@ -90,9 +88,7 @@ CorUnix::InternalFree(
void *pvMem
)
{
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
free(pvMem);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
}
void *
@@ -111,7 +107,6 @@ CorUnix::InternalMalloc(
)
{
void *pvMem;
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
if (szSize == 0)
{
@@ -120,7 +115,6 @@ CorUnix::InternalMalloc(
}
pvMem = (void*)malloc(szSize);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
return pvMem;
}
@@ -140,8 +134,6 @@ CorUnix::InternalStrdup(
)
{
char *pszStrCopy;
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
pszStrCopy = strdup(c_szStr);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
return pszStrCopy;
}
diff --git a/src/pal/src/cruntime/misc.cpp b/src/pal/src/cruntime/misc.cpp
index fa8504f726..6451dd4898 100644
--- a/src/pal/src/cruntime/misc.cpp
+++ b/src/pal/src/cruntime/misc.cpp
@@ -63,9 +63,7 @@ namespace CorUnix
)
{
int nRet;
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
nRet = rand();
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
return nRet;
}
}
diff --git a/src/pal/src/cruntime/printfcpp.cpp b/src/pal/src/cruntime/printfcpp.cpp
index 8adf3470c2..cd66ad20fd 100644
--- a/src/pal/src/cruntime/printfcpp.cpp
+++ b/src/pal/src/cruntime/printfcpp.cpp
@@ -985,7 +985,7 @@ static INT Internal_AddPaddingVfwprintf(CPalThread *pthrCurrent, PAL_FILE *strea
Length += Padding;
}
- int iLen = (Length+1);
+ int iLen = (Length+1);
Out = (LPWSTR) InternalMalloc(pthrCurrent, iLen * sizeof(WCHAR));
if (!Out)
{
@@ -1146,18 +1146,14 @@ int CorUnix::InternalVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const
int NativeVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Format, va_list ap)
{
int retVal = 0;
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
retVal = vsnprintf(Buffer, Count, Format, ap);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
return retVal;
}
int NativeVfprintf(CPalThread *pthrCurrent, FILE *filePtr, const char *format, va_list ap)
{
int retVal = 0;
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
retVal = vfprintf(filePtr, format, ap);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
return retVal;
}
@@ -1296,7 +1292,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for
}
InternalFree(pthrCurrent, WorkingWStr);
LOGEXIT("wcsncpy_s failed!\n");
- PERF_EXIT(vfwprintf);
+ PERF_EXIT(vfwprintf);
va_end(ap);
return (-1);
}
@@ -1325,7 +1321,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for
}
InternalFree(pthrCurrent, WorkingWStr);
LOGEXIT("vfwprintf returns int -1\n");
- PERF_EXIT(vfwprintf);
+ PERF_EXIT(vfwprintf);
va_end(ap);
return (-1);
}
@@ -1433,7 +1429,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for
ERROR("InternalMalloc failed\n");
LOGEXIT("vfwprintf returns int -1\n");
PERF_EXIT(vfwprintf);
- pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY);
va_end(ap);
return -1;
}
@@ -1461,7 +1457,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for
ERROR("InternalMalloc failed\n");
LOGEXIT("vfwprintf returns int -1\n");
PERF_EXIT(vfwprintf);
- pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY);
va_end(ap);
return -1;
}
@@ -1486,7 +1482,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for
ERROR("InternalMalloc failed\n");
LOGEXIT("vfwprintf returns int -1\n");
PERF_EXIT(vfwprintf);
- pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY);
va_end(ap);
return -1;
}
@@ -1511,7 +1507,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for
InternalFree(pthrCurrent, TempSprintfStrPtr);
}
LOGEXIT("vfwprintf returns int -1\n");
- PERF_EXIT(vfwprintf);
+ PERF_EXIT(vfwprintf);
va_end(ap);
return -1;
}
@@ -1526,7 +1522,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for
if(TempSprintfStrPtr)
{
InternalFree(pthrCurrent, TempSprintfStrPtr);
- }
+ }
va_end(ap);
return -1;
}
@@ -1583,7 +1579,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for
++written;
}
}
-
+
LOGEXIT("vfwprintf returns int %d\n", written);
PERF_EXIT(vfwprintf);
va_end(ap);
@@ -2017,7 +2013,7 @@ int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR
}
InternalFree(pthrCurrent, WorkingWStr);
LOGEXIT("wcsncpy_s failed!\n");
- PERF_EXIT(wvsnprintf);
+ PERF_EXIT(wvsnprintf);
va_end(ap);
return (-1);
}
@@ -2563,4 +2559,3 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format,
PERF_EXIT(vfprintf);
return written;
}
-
diff --git a/src/pal/src/file/find.cpp b/src/pal/src/file/find.cpp
index 18c3c7f038..64735a1792 100644
--- a/src/pal/src/file/find.cpp
+++ b/src/pal/src/file/find.cpp
@@ -88,9 +88,7 @@ namespace CorUnix
)
{
int nRet = -1;
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
nRet = glob(szPattern, nFlags, pnErrFunc, pgGlob);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
return nRet;
}
}
diff --git a/src/pal/src/include/pal/threadsusp.hpp b/src/pal/src/include/pal/threadsusp.hpp
index bab5ec94bb..dcf5166b7c 100644
--- a/src/pal/src/include/pal/threadsusp.hpp
+++ b/src/pal/src/include/pal/threadsusp.hpp
@@ -535,10 +535,6 @@ namespace CorUnix
DWORD *pdwSuspendCount
);
- VOID LeaveUnsafeRegion();
-
- VOID EnterUnsafeRegion();
-
#if !HAVE_MACH_EXCEPTIONS || USE_SIGNALS_FOR_THREAD_SUSPENSION
static
VOID InitializeSignalSets();
diff --git a/src/pal/src/memory/heap.cpp b/src/pal/src/memory/heap.cpp
index c2f316d0e7..ff1f2a2133 100644
--- a/src/pal/src/memory/heap.cpp
+++ b/src/pal/src/memory/heap.cpp
@@ -236,10 +236,7 @@ HeapAlloc(
#ifdef __APPLE__
// This is patterned off of InternalMalloc in malloc.cpp.
{
- CPalThread *pthrCurrent = InternalGetCurrentThread();
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
pMem = (BYTE *)malloc_zone_malloc((malloc_zone_t *)hHeap, numberOfBytes);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
}
#else // __APPLE__
pMem = (BYTE *) PAL_malloc(numberOfBytes);
@@ -318,10 +315,7 @@ HeapFree(
#ifdef __APPLE__
// This is patterned off of InternalFree in malloc.cpp.
{
- CPalThread *pthrCurrent = InternalGetCurrentThread();
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
malloc_zone_free((malloc_zone_t *)hHeap, lpMem);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
}
#else // __APPLE__
PAL_free (lpMem);
@@ -393,10 +387,7 @@ HeapReAlloc(
#ifdef __APPLE__
// This is patterned off of InternalRealloc in malloc.cpp.
{
- CPalThread *pthrCurrent = InternalGetCurrentThread();
- pthrCurrent->suspensionInfo.EnterUnsafeRegion();
pMem = (BYTE *) malloc_zone_realloc((malloc_zone_t *)hHeap, lpmem, numberOfBytes);
- pthrCurrent->suspensionInfo.LeaveUnsafeRegion();
}
#else // __APPLE__
pMem = (BYTE *) PAL_realloc(lpmem, numberOfBytes);
diff --git a/src/pal/src/misc/identity.cpp b/src/pal/src/misc/identity.cpp
index 245484a7e7..6be3c9d8ac 100644
--- a/src/pal/src/misc/identity.cpp
+++ b/src/pal/src/misc/identity.cpp
@@ -403,7 +403,6 @@ CorUnix::InternalGetpwuid_r(
{
int iError = 0;
- pPalThread->suspensionInfo.EnterUnsafeRegion();
iError = getpwuid_r(uid, pPasswd, pchBuffer, nBufSize, ppResult);
#if GETPWUID_R_SETS_ERRNO
@@ -413,8 +412,6 @@ CorUnix::InternalGetpwuid_r(
}
#endif // GETPWUID_R_SETS_ERRNO
- pPalThread->suspensionInfo.LeaveUnsafeRegion();
return iError;
}
#endif // HAVE_GETPWUID_R
-
diff --git a/src/pal/src/sync/cs.cpp b/src/pal/src/sync/cs.cpp
index 1ac6570966..4f2cae4eff 100644
--- a/src/pal/src/sync/cs.cpp
+++ b/src/pal/src/sync/cs.cpp
@@ -734,19 +734,6 @@ namespace CorUnix
goto IECS_exit;
}
- if (pPalCriticalSection->fInternal && NULL != pThread)
- {
- CS_TRACE("EnterUnsafeRegion()\n");
- // Acquiring an internal critical section: mark the current
- // thread as unsafe for suspension
- //
- // Note that InternalEnterCriticalSection marks the thread as unsafe
- // for suspension only at the first acquisition of a CS, and not when
- // recursively reacquiring an already owned CS.
-
- pThread->suspensionInfo.EnterUnsafeRegion();
- }
-
// Set bits to change and waiter increment for an incoming thread
lBitsToChange = PALCS_LOCK_BIT;
lWaitInc = PALCS_LOCK_WAITER_INC;
@@ -917,22 +904,22 @@ namespace CorUnix
"{%d, %d, %d} ==>\n", pPalCriticalSection,
PALCS_GETWCOUNT(lVal), PALCS_GETAWBIT(lVal), PALCS_GETLBIT(lVal),
PALCS_GETWCOUNT(lNewVal), PALCS_GETAWBIT(lNewVal), PALCS_GETLBIT(lNewVal));
-
+
lNewVal = InterlockedCompareExchange(&pPalCriticalSection->LockCount,
lNewVal, lVal);
-
+
CS_TRACE("[LCS-UN %p] ==> %s\n", pPalCriticalSection,
(lNewVal == lVal) ? "OK" : "NO");
-
+
if (lNewVal == lVal)
{
- goto ILCS_cs_released;
+ goto ILCS_cs_exit;
}
}
else
{
// There is at least one waiter, we need to wake it up
-
+
#ifdef PALCS_TRANSFER_OWNERSHIP_ON_RELEASE
// Fair lock case: passing ownership on to the first waiter.
// Here we need only to decrement the waiters count. CS will
@@ -977,7 +964,7 @@ namespace CorUnix
sched_yield();
#endif // PALCS_TRANSFER_OWNERSHIP_ON_RELEASE
- goto ILCS_cs_released;
+ goto ILCS_cs_exit;
}
}
@@ -993,20 +980,6 @@ namespace CorUnix
lVal = lNewVal;
}
- ILCS_cs_released:
- if (pPalCriticalSection->fInternal && NULL != pThread)
- {
- // Releasing internal critical section: mark the current thread
- // back to safe for suspension.
- //
- // Note that InternalLeaveCriticalSection marks the thread as safe
- // for suspension only at the final release of the CS, and not
- // when releasing for the M-th time a CS recursively acquired N
- // times, with N > M.
-
- pThread->suspensionInfo.LeaveUnsafeRegion();
- }
-
ILCS_cs_exit:
return;
}
@@ -1033,13 +1006,6 @@ namespace CorUnix
threadId = ObtainCurrentThreadId(pThread);
- if (pPalCriticalSection->fInternal && NULL != pThread)
- {
- // Acquiring an internal critical section: mark the current
- // thread as unsafe for suspension.
- pThread->suspensionInfo.EnterUnsafeRegion();
- }
-
lNewVal = InterlockedCompareExchange (&pPalCriticalSection->LockCount,
(LONG)PALCS_LOCK_BIT,
(LONG)PALCS_LOCK_INIT);
@@ -1059,25 +1025,6 @@ namespace CorUnix
goto ITECS_exit;
}
- if (pPalCriticalSection->fInternal && NULL != pThread)
- {
- // InternalEnterCriticalSection's (and InternalLeaveCriticalSection's)
- // logic requires to mark the thread as unsafe for suspension (and
- // back to safe) only at the first acquisition of a CS (and at the
- // final release), and not when recursively reacquiring an already
- // owned CS.
- // InternalTryEnterCriticalSection needs to match the same logic.
- // The thread has already been marked as unsafe above, before trying
- // lo lock the CS. If that had succeeded and it was the first
- // acquisition, the current thread would have jumped to ITECS_exit
- // from within the previous 'if' block.
- // Therefore, if control reaches this point, whether the thread
- // failed to acquire the CS or it was already owning it and it is
- // just re-entering it. In both the case the previous unsafe marking
- // needs to be undone here.
- pThread->suspensionInfo.LeaveUnsafeRegion();
- }
-
// check if the current thread already owns the criticalSection
if ((lNewVal & PALCS_LOCK_BIT) &&
(pPalCriticalSection->OwningThread == threadId))
@@ -1558,14 +1505,6 @@ namespace CorUnix
return;
}
- if (pPalCriticalSection->fInternal && NULL != pThread)
- {
- // Acquiring an internal critical section: mark the current
- // thread as unsafe for suspension (it may already be
- // marked as unsafe by a previous call)
- pThread->suspensionInfo.EnterUnsafeRegion();
- }
-
iRet = pthread_mutex_lock(&pPalCriticalSection->csndNativeData.mutex);
_ASSERTE(0 == iRet);
@@ -1614,16 +1553,6 @@ namespace CorUnix
iRet = pthread_mutex_unlock(&pPalCriticalSection->csndNativeData.mutex);
_ASSERTE(0 == iRet);
-
- if (pPalCriticalSection->fInternal && NULL != pThread)
- {
- // Releasing internal critical section: mark the current thread
- // back to safe for suspension. N.B.: after this call the state
- // may still be unsafe if EnterUnsafeRegion has been called more
- // times (e.g. the thread owns more internal CSs)
- pThread->suspensionInfo.LeaveUnsafeRegion();
- }
-
}
/*++
@@ -1660,11 +1589,6 @@ namespace CorUnix
goto ITECS_exit;
}
- if (pPalCriticalSection->fInternal && NULL != pThread)
- {
- pThread->suspensionInfo.EnterUnsafeRegion();
- }
-
fRet = (0 == pthread_mutex_trylock(&pPalCriticalSection->csndNativeData.mutex));
if (fRet)
@@ -1672,14 +1596,9 @@ namespace CorUnix
pPalCriticalSection->OwningThread = threadId;
pPalCriticalSection->RecursionCount = 1;
}
- else if (pPalCriticalSection->fInternal && NULL != pThread)
- {
- pThread->suspensionInfo.LeaveUnsafeRegion();
- }
ITECS_exit:
return fRet;
}
#endif // MUTEX_BASED_CSS || _DEBUG
}
-
diff --git a/src/pal/src/thread/threadsusp.cpp b/src/pal/src/thread/threadsusp.cpp
index 0474b6e97b..4c0cf3226f 100644
--- a/src/pal/src/thread/threadsusp.cpp
+++ b/src/pal/src/thread/threadsusp.cpp
@@ -1223,68 +1223,6 @@ CThreadSuspensionInfo::WaitOnResumeSemaphore()
}
#endif // USE_POSIX_SEMAPHORES
}
-
-/*++
-Function:
- LeaveUnsafeRegion
-
-LeaveUnsafeRegion decrements a thread's unsafe region count.
-Once the count is zero, the calling thread checks if there
-is a suspension pending on it. If so, it will post on its
-suspension semaphore and wait for the suspending thread to
-suspend it. LeaveUnsafeRegion should only be called after
-the thread called EnterUnsafeRegion.
---*/
-VOID
-CThreadSuspensionInfo::LeaveUnsafeRegion()
-{
- if (PALIsThreadDataInitialized())
- {
- _ASSERT_MSG(GetUnsafeRegionCount() > 0, "When entering LeaveUnsafeRegion, a thread's unsafe region count should always be greater than zero.\n");
-
- // Predecrement the unsafe region count
- DecrUnsafeRegionCount();
- if (GetUnsafeRegionCount() == 0)
- {
- if (GetSuspPending())
- {
-#if USE_SIGNALS_FOR_THREAD_SUSPENSION
- pthread_sigmask(SIG_BLOCK, &smWaitmask, &this->m_smOrigmask);
- PostOnSuspendSemaphore();
- sigsuspend(&smContmask);
- // Set the signal mask that came before this sigsuspend.
- pthread_sigmask(SIG_SETMASK, &this->m_smOrigmask, NULL);
-#else // USE_SIGNALS_FOR_THREAD_SUSPENSION
- PostOnSuspendSemaphore();
- while (GetSuspPending())
- {
- sched_yield();
- }
-#endif // USE_SIGNALS_FOR_THREAD_SUSPENSION
- }
- }
- }
-}
-
-/*++
-Function:
- EnterUnsafeRegion
-
-EnterUnsafeRegion increments a thread's unsafe region count.
-When a thread's unsafe region count is greater than zero,
-it cannot be suspended. Thus, this function must be used
-very carefully since thread suspension is required during
-PAL cleanup. LeaveUnsafeRegion is used to decrement a thread's
-suspension count.
---*/
-VOID
-CThreadSuspensionInfo::EnterUnsafeRegion()
-{
- if (PALIsThreadDataInitialized())
- {
- IncrUnsafeRegionCount();
- }
-}
#if !HAVE_MACH_EXCEPTIONS || USE_SIGNALS_FOR_THREAD_SUSPENSION
/*++