summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/src/md/windows
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
commitf7d30133221896638f7bf4f66c504255c4b14f48 (patch)
tree5f3e07a049f388a3a309a615b8884318f6668a98 /nsprpub/pr/src/md/windows
parent26b297510a11758727438df4669357a2a2bc42ce (diff)
downloadUXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.gz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.lz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.xz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.zip
Issue #1338 - Part 1: Update NSPR to 4.24
Diffstat (limited to 'nsprpub/pr/src/md/windows')
-rw-r--r--nsprpub/pr/src/md/windows/ntdllmn.c5
-rw-r--r--nsprpub/pr/src/md/windows/ntgc.c16
-rw-r--r--nsprpub/pr/src/md/windows/ntinrval.c6
-rw-r--r--nsprpub/pr/src/md/windows/ntio.c2066
-rw-r--r--nsprpub/pr/src/md/windows/ntmisc.c645
-rw-r--r--nsprpub/pr/src/md/windows/ntsec.c66
-rw-r--r--nsprpub/pr/src/md/windows/ntsem.c16
-rw-r--r--nsprpub/pr/src/md/windows/ntthread.c185
-rw-r--r--nsprpub/pr/src/md/windows/w32ipcsem.c20
-rw-r--r--nsprpub/pr/src/md/windows/w32poll.c58
-rw-r--r--nsprpub/pr/src/md/windows/w32rng.c15
-rw-r--r--nsprpub/pr/src/md/windows/w32shm.c139
-rw-r--r--nsprpub/pr/src/md/windows/w95cv.c30
-rw-r--r--nsprpub/pr/src/md/windows/w95dllmain.c5
-rw-r--r--nsprpub/pr/src/md/windows/w95io.c363
-rw-r--r--nsprpub/pr/src/md/windows/w95sock.c114
-rw-r--r--nsprpub/pr/src/md/windows/w95thred.c143
-rw-r--r--nsprpub/pr/src/md/windows/win32_errors.c6
18 files changed, 2081 insertions, 1817 deletions
diff --git a/nsprpub/pr/src/md/windows/ntdllmn.c b/nsprpub/pr/src/md/windows/ntdllmn.c
index 7dec0517d..e64b312d0 100644
--- a/nsprpub/pr/src/md/windows/ntdllmn.c
+++ b/nsprpub/pr/src/md/windows/ntdllmn.c
@@ -26,7 +26,7 @@ BOOL WINAPI DllMain(
DWORD fdwReason,
LPVOID lpvReserved)
{
-PRThread *me;
+ PRThread *me;
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
@@ -45,8 +45,9 @@ PRThread *me;
case DLL_THREAD_DETACH:
if (_pr_initialized) {
me = _MD_GET_ATTACHED_THREAD();
- if ((me != NULL) && (me->flags & _PR_ATTACHED))
+ if ((me != NULL) && (me->flags & _PR_ATTACHED)) {
_PRI_DetachThread();
+ }
}
break;
case DLL_PROCESS_DETACH:
diff --git a/nsprpub/pr/src/md/windows/ntgc.c b/nsprpub/pr/src/md/windows/ntgc.c
index 55ac92fb0..20ad8a81e 100644
--- a/nsprpub/pr/src/md/windows/ntgc.c
+++ b/nsprpub/pr/src/md/windows/ntgc.c
@@ -10,7 +10,7 @@
#include <windows.h>
#include "primpl.h"
-PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
+PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#if defined(_X86_)
CONTEXT context;
@@ -34,8 +34,8 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
} else {
/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
- * This code is extremely machine dependant and completely
- * undocumented by MS. Its only known to work experimentally.
+ * This code is extremely machine dependant and completely
+ * undocumented by MS. Its only known to work experimentally.
* Ready for a walk on the wild * side?
*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING */
@@ -47,7 +47,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
* Are your palms sweating yet?
*/
- /*
+ /*
** EAX is on the stack (ESP+0)
** EDX is on the stack (ESP+4)
** ECX is on the stack (ESP+8)
@@ -71,7 +71,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
}
/* This function is not used right now, but is left as a reference.
- * If you ever need to get the fiberID from the currently running fiber,
+ * If you ever need to get the fiberID from the currently running fiber,
* this is it.
*/
void *
@@ -81,15 +81,15 @@ GetMyFiberID()
void *fiberData;
/* A pointer to our tib entry is found at FS:[18]
- * At offset 10h is the fiberData pointer. The context of the
- * fiber is stored in there.
+ * At offset 10h is the fiberData pointer. The context of the
+ * fiber is stored in there.
*/
__asm {
mov EDX, FS:[18h]
mov EAX, DWORD PTR [EDX+10h]
mov [fiberData], EAX
}
-
+
return fiberData;
#else
PR_NOT_REACHED("not implemented");
diff --git a/nsprpub/pr/src/md/windows/ntinrval.c b/nsprpub/pr/src/md/windows/ntinrval.c
index 10aca11ba..a44780455 100644
--- a/nsprpub/pr/src/md/windows/ntinrval.c
+++ b/nsprpub/pr/src/md/windows/ntinrval.c
@@ -26,14 +26,14 @@ _PR_MD_INTERVAL_INIT()
HMODULE mmtimerlib = LoadLibraryW(L"mmtimer.dll"); /* XXX leaked! */
if (mmtimerlib) {
intervalFunc = (IntervalFuncType)GetProcAddress(mmtimerlib,
- "timeGetTime");
+ "timeGetTime");
} else {
intervalFunc = &GetTickCount;
}
#endif
}
-PRIntervalTime
+PRIntervalTime
_PR_MD_GET_INTERVAL()
{
/* milliseconds since system start */
@@ -44,7 +44,7 @@ _PR_MD_GET_INTERVAL()
#endif
}
-PRIntervalTime
+PRIntervalTime
_PR_MD_INTERVAL_PER_SEC()
{
return 1000;
diff --git a/nsprpub/pr/src/md/windows/ntio.c b/nsprpub/pr/src/md/windows/ntio.c
index aba53dc85..040bbd310 100644
--- a/nsprpub/pr/src/md/windows/ntio.c
+++ b/nsprpub/pr/src/md/windows/ntio.c
@@ -9,7 +9,7 @@
* For LOCAL_SCOPE threads, we're using NT fibers. For GLOBAL_SCOPE threads
* we're using NT-native threads.
*
- * When doing IO, we want to use completion ports for optimal performance
+ * When doing IO, we want to use completion ports for optimal performance
* with fibers. But if we use completion ports for all IO, it is difficult
* to project a blocking model with GLOBAL_SCOPE threads. To handle this
* we create an extra thread for completing IO for GLOBAL_SCOPE threads.
@@ -32,9 +32,9 @@ static PRThread *_pr_io_completion_thread;
#define RECYCLE_SIZE 512
static struct _MDLock _pr_recycle_lock;
static PRInt32 _pr_recycle_INET_array[RECYCLE_SIZE];
-static PRInt32 _pr_recycle_INET_tail = 0;
+static PRInt32 _pr_recycle_INET_tail = 0;
static PRInt32 _pr_recycle_INET6_array[RECYCLE_SIZE];
-static PRInt32 _pr_recycle_INET6_tail = 0;
+static PRInt32 _pr_recycle_INET6_tail = 0;
__declspec(thread) PRThread *_pr_io_restarted_io = NULL;
DWORD _pr_io_restartedIOIndex; /* The thread local storage slot for each
@@ -97,14 +97,14 @@ static PRInt32 _nt_nonblock_recvfrom(PRFileDesc *, char *, int, struct sockaddr
* An inheritable fd cannot be associated with an I/O completion port
* because the completion notification of async I/O initiated by the
* child process is still posted to the I/O completion port in the
- * parent process.
+ * parent process.
*/
#define _NT_USE_NB_IO(fd) \
((fd)->secret->nonblocking || (fd)->secret->inheritable == _PR_TRI_TRUE)
/*
* UDP support
- *
+ *
* UDP is supported on NT by the continuation thread mechanism.
* The code is borrowed from ptio.c in pthreads nspr, hence the
* PT and pt prefixes. This mechanism is in fact general and
@@ -134,12 +134,22 @@ struct pt_Continuation
/* The building of the continuation operation */
ContinuationFn function; /* what function to continue */
- union { SOCKET osfd; } arg1; /* #1 - the op's fd */
- union { void* buffer; } arg2; /* #2 - primary transfer buffer */
- union { PRIntn amount; } arg3; /* #3 - size of 'buffer' */
- union { PRIntn flags; } arg4; /* #4 - read/write flags */
- union { PRNetAddr *addr; } arg5; /* #5 - send/recv address */
-
+ union {
+ SOCKET osfd;
+ } arg1; /* #1 - the op's fd */
+ union {
+ void* buffer;
+ } arg2; /* #2 - primary transfer buffer */
+ union {
+ PRIntn amount;
+ } arg3; /* #3 - size of 'buffer' */
+ union {
+ PRIntn flags;
+ } arg4; /* #4 - read/write flags */
+ union {
+ PRNetAddr *addr;
+ } arg5; /* #5 - send/recv address */
+
PRIntervalTime timeout; /* representation of the timeout */
PRIntn event; /* flags for select()'s events */
@@ -149,7 +159,10 @@ struct pt_Continuation
** These function can either return an int return code or a pointer to
** some object.
*/
- union { PRIntn code; void *object; } result;
+ union {
+ PRIntn code;
+ void *object;
+ } result;
PRIntn syserrno; /* in case it failed, why (errno) */
pr_ContuationStatus status; /* the status of the operation */
@@ -184,7 +197,7 @@ static PRInt32 pt_SendTo(
PRInt32 amount, PRInt32 flags, const PRNetAddr *addr,
PRIntn addrlen, PRIntervalTime timeout);
static PRInt32 pt_RecvFrom(SOCKET osfd, void *buf, PRInt32 amount,
- PRInt32 flags, PRNetAddr *addr, PRIntn *addr_len, PRIntervalTime timeout);
+ PRInt32 flags, PRNetAddr *addr, PRIntn *addr_len, PRIntervalTime timeout);
/* The key returned from GetQueuedCompletionStatus() is used to determine what
@@ -215,10 +228,10 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
PR_ASSERT(deadThread->state == _PR_DEAD_STATE);
/* XXXMB - cleanup to do here? */
- if ( !_PR_IS_NATIVE_THREAD(deadThread) ){
+ if ( !_PR_IS_NATIVE_THREAD(deadThread) ) {
/* Spinlock while user thread is still running.
* There is no way to use a condition variable here. The thread
- * is dead, and we have to wait until we switch off the dead
+ * is dead, and we have to wait until we switch off the dead
* thread before we can kill the fiber completely.
*/
while ( deadThread->no_sched)
@@ -227,8 +240,9 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
DeleteFiber(deadThread->md.fiber_id);
}
memset(deadThread, 0xa, sizeof(PRThread)); /* debugging */
- if (!deadThread->threadAllocatedOnStack)
+ if (!deadThread->threadAllocatedOnStack) {
PR_DELETE(deadThread);
+ }
_nt_idleCount--;
}
_MD_UNLOCK(&_nt_idleLock);
@@ -238,18 +252,19 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
#if 0
timeout = INFINITE;
#else
- /*
- * temporary hack to poll the runq every 5 seconds because of bug in
- * native threads creating user threads and not poking the right cpu.
- *
- * A local thread that was interrupted is bound to its current
- * cpu but there is no easy way for the interrupter to poke the
- * right cpu. This is a hack to poll the runq every 5 seconds.
- */
+ /*
+ * temporary hack to poll the runq every 5 seconds because of bug in
+ * native threads creating user threads and not poking the right cpu.
+ *
+ * A local thread that was interrupted is bound to its current
+ * cpu but there is no easy way for the interrupter to poke the
+ * right cpu. This is a hack to poll the runq every 5 seconds.
+ */
timeout = 5000;
#endif
- else
+ else {
timeout = PR_IntervalToMilliseconds(ticks);
+ }
/*
* The idea of looping here is to complete as many IOs as possible before
@@ -257,11 +272,11 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
*/
while(1) {
rv = GetQueuedCompletionStatus(
- _pr_completion_port,
- &bytes,
- &key,
- &olp,
- timeout);
+ _pr_completion_port,
+ &bytes,
+ &key,
+ &olp,
+ timeout);
if (rv == 0 && olp == NULL) {
/* Error in GetQueuedCompetionStatus */
if (GetLastError() != WAIT_TIMEOUT) {
@@ -273,8 +288,9 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
}
}
- if (olp == NULL)
+ if (olp == NULL) {
return 0;
+ }
mdOlp = (_MDOverlapped *)olp;
@@ -288,8 +304,8 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
PR_ASSERT(desc != NULL);
mwstatus = rv ? PR_MW_SUCCESS : PR_MW_FAILURE;
if (InterlockedCompareExchange((PVOID *)&desc->outcome,
- (PVOID)mwstatus, (PVOID)PR_MW_PENDING)
- == (PVOID)PR_MW_PENDING) {
+ (PVOID)mwstatus, (PVOID)PR_MW_PENDING)
+ == (PVOID)PR_MW_PENDING) {
if (mwstatus == PR_MW_SUCCESS) {
desc->bytesRecv = bytes;
} else {
@@ -344,8 +360,9 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
PR_ASSERT(mdOlp->ioModel == _MD_BlockingIO);
completed_io = _PR_THREAD_MD_TO_PTR(mdOlp->data.mdThread);
completed_io->md.blocked_io_status = rv;
- if (rv == 0)
+ if (rv == 0) {
completed_io->md.blocked_io_error = GetLastError();
+ }
completed_io->md.blocked_io_bytes = bytes;
if ( !_PR_IS_NATIVE_THREAD(completed_io) ) {
@@ -354,7 +371,7 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
/* The KEY_CVAR notification only occurs when a native thread
* is notifying a user thread. For user-user notifications
- * the wakeup occurs by having the notifier place the thread
+ * the wakeup occurs by having the notifier place the thread
* on the runq directly; for native-native notifications the
* wakeup occurs by calling ReleaseSemaphore.
*/
@@ -391,16 +408,17 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
_PR_THREAD_UNLOCK(completed_io);
- /*
- * If an I/O operation is suspended, the thread
- * must be running on the same cpu on which the
- * I/O operation was issued.
- */
- PR_ASSERT(!completed_io->md.thr_bound_cpu ||
- (completed_io->cpu == completed_io->md.thr_bound_cpu));
-
- if (!completed_io->md.thr_bound_cpu)
- completed_io->cpu = lockedCPU;
+ /*
+ * If an I/O operation is suspended, the thread
+ * must be running on the same cpu on which the
+ * I/O operation was issued.
+ */
+ PR_ASSERT(!completed_io->md.thr_bound_cpu ||
+ (completed_io->cpu == completed_io->md.thr_bound_cpu));
+
+ if (!completed_io->md.thr_bound_cpu) {
+ completed_io->cpu = lockedCPU;
+ }
completed_io->state = _PR_RUNNABLE;
_PR_RUNQ_LOCK(completed_io->cpu);
_PR_ADD_RUNQ(completed_io, completed_io->cpu, pri);
@@ -423,7 +441,7 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
completed_io->state = _PR_RUNNABLE;
_PR_THREAD_UNLOCK(completed_io);
rv = ReleaseSemaphore(completed_io->md.blocked_sema,
- 1, NULL);
+ 1, NULL);
PR_ASSERT(0 != rv);
} else {
_PR_THREAD_UNLOCK(completed_io);
@@ -443,41 +461,41 @@ static PRStatus
_native_thread_md_wait(PRThread *thread, PRIntervalTime ticks)
{
DWORD rv;
- PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(ticks);
-
- /*
- * thread waiting for a cvar or a joining thread
- */
- rv = WaitForSingleObject(thread->md.blocked_sema, msecs);
- switch(rv) {
- case WAIT_OBJECT_0:
- return PR_SUCCESS;
- break;
- case WAIT_TIMEOUT:
- _PR_THREAD_LOCK(thread);
- PR_ASSERT (thread->state != _PR_IO_WAIT);
- if (thread->wait.cvar != NULL) {
- PR_ASSERT(thread->state == _PR_COND_WAIT);
- thread->wait.cvar = NULL;
- thread->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(thread);
- } else {
- /* The CVAR was notified just as the timeout
- * occurred. This left the semaphore in the
- * signaled state. Call WaitForSingleObject()
- * to clear the semaphore.
- */
- _PR_THREAD_UNLOCK(thread);
- rv = WaitForSingleObject(thread->md.blocked_sema, INFINITE);
- PR_ASSERT(rv == WAIT_OBJECT_0);
- }
- return PR_SUCCESS;
- break;
- default:
- return PR_FAILURE;
- break;
- }
+ PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
+ INFINITE : PR_IntervalToMilliseconds(ticks);
+
+ /*
+ * thread waiting for a cvar or a joining thread
+ */
+ rv = WaitForSingleObject(thread->md.blocked_sema, msecs);
+ switch(rv) {
+ case WAIT_OBJECT_0:
+ return PR_SUCCESS;
+ break;
+ case WAIT_TIMEOUT:
+ _PR_THREAD_LOCK(thread);
+ PR_ASSERT (thread->state != _PR_IO_WAIT);
+ if (thread->wait.cvar != NULL) {
+ PR_ASSERT(thread->state == _PR_COND_WAIT);
+ thread->wait.cvar = NULL;
+ thread->state = _PR_RUNNING;
+ _PR_THREAD_UNLOCK(thread);
+ } else {
+ /* The CVAR was notified just as the timeout
+ * occurred. This left the semaphore in the
+ * signaled state. Call WaitForSingleObject()
+ * to clear the semaphore.
+ */
+ _PR_THREAD_UNLOCK(thread);
+ rv = WaitForSingleObject(thread->md.blocked_sema, INFINITE);
+ PR_ASSERT(rv == WAIT_OBJECT_0);
+ }
+ return PR_SUCCESS;
+ break;
+ default:
+ return PR_FAILURE;
+ break;
+ }
return PR_SUCCESS;
}
@@ -487,12 +505,12 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
{
DWORD rv;
- if (_native_threads_only) {
- return(_native_thread_md_wait(thread, ticks));
- }
+ if (_native_threads_only) {
+ return(_native_thread_md_wait(thread, ticks));
+ }
if ( thread->flags & _PR_GLOBAL_SCOPE ) {
PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(ticks);
+ INFINITE : PR_IntervalToMilliseconds(ticks);
rv = WaitForSingleObject(thread->md.blocked_sema, msecs);
switch(rv) {
case WAIT_OBJECT_0:
@@ -589,96 +607,96 @@ static PRStatus
_native_thread_io_wait(PRThread *thread, PRIntervalTime ticks)
{
DWORD rv, bytes;
-#define _NATIVE_IO_WAIT_HANDLES 2
-#define _NATIVE_WAKEUP_EVENT_INDEX 0
-#define _NATIVE_IO_EVENT_INDEX 1
+#define _NATIVE_IO_WAIT_HANDLES 2
+#define _NATIVE_WAKEUP_EVENT_INDEX 0
+#define _NATIVE_IO_EVENT_INDEX 1
- HANDLE wait_handles[_NATIVE_IO_WAIT_HANDLES];
+ HANDLE wait_handles[_NATIVE_IO_WAIT_HANDLES];
- PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(ticks);
+ PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
+ INFINITE : PR_IntervalToMilliseconds(ticks);
PR_ASSERT(thread->flags & _PR_GLOBAL_SCOPE);
- wait_handles[0] = thread->md.blocked_sema;
- wait_handles[1] = thread->md.thr_event;
- rv = WaitForMultipleObjects(_NATIVE_IO_WAIT_HANDLES, wait_handles,
- FALSE, msecs);
-
- switch(rv) {
- case WAIT_OBJECT_0 + _NATIVE_IO_EVENT_INDEX:
- /*
- * I/O op completed
- */
- _PR_THREAD_LOCK(thread);
- if (thread->state == _PR_IO_WAIT) {
-
- PR_ASSERT(thread->io_suspended == PR_FALSE);
- PR_ASSERT(thread->io_pending == PR_TRUE);
- thread->state = _PR_RUNNING;
- thread->io_pending = PR_FALSE;
- _PR_THREAD_UNLOCK(thread);
- } else {
- /* The IO completed just at the same time the
- * thread was interrupted. This led to us being
- * notified twice. Call WaitForSingleObject()
- * to clear the semaphore.
- */
- PR_ASSERT(thread->io_suspended == PR_TRUE);
- PR_ASSERT(thread->io_pending == PR_TRUE);
- thread->io_pending = PR_FALSE;
- _PR_THREAD_UNLOCK(thread);
- rv = WaitForSingleObject(thread->md.blocked_sema,
- INFINITE);
- PR_ASSERT(rv == WAIT_OBJECT_0);
- }
-
- rv = GetOverlappedResult((HANDLE) thread->io_fd,
- &thread->md.overlapped.overlapped, &bytes, FALSE);
-
- thread->md.blocked_io_status = rv;
- if (rv != 0) {
- thread->md.blocked_io_bytes = bytes;
- } else {
- thread->md.blocked_io_error = GetLastError();
- PR_ASSERT(ERROR_IO_PENDING != thread->md.blocked_io_error);
- }
- rv = ResetEvent(thread->md.thr_event);
- PR_ASSERT(rv != 0);
- break;
- case WAIT_OBJECT_0 + _NATIVE_WAKEUP_EVENT_INDEX:
- /*
- * I/O interrupted;
- */
+ wait_handles[0] = thread->md.blocked_sema;
+ wait_handles[1] = thread->md.thr_event;
+ rv = WaitForMultipleObjects(_NATIVE_IO_WAIT_HANDLES, wait_handles,
+ FALSE, msecs);
+
+ switch(rv) {
+ case WAIT_OBJECT_0 + _NATIVE_IO_EVENT_INDEX:
+ /*
+ * I/O op completed
+ */
+ _PR_THREAD_LOCK(thread);
+ if (thread->state == _PR_IO_WAIT) {
+
+ PR_ASSERT(thread->io_suspended == PR_FALSE);
+ PR_ASSERT(thread->io_pending == PR_TRUE);
+ thread->state = _PR_RUNNING;
+ thread->io_pending = PR_FALSE;
+ _PR_THREAD_UNLOCK(thread);
+ } else {
+ /* The IO completed just at the same time the
+ * thread was interrupted. This led to us being
+ * notified twice. Call WaitForSingleObject()
+ * to clear the semaphore.
+ */
+ PR_ASSERT(thread->io_suspended == PR_TRUE);
+ PR_ASSERT(thread->io_pending == PR_TRUE);
+ thread->io_pending = PR_FALSE;
+ _PR_THREAD_UNLOCK(thread);
+ rv = WaitForSingleObject(thread->md.blocked_sema,
+ INFINITE);
+ PR_ASSERT(rv == WAIT_OBJECT_0);
+ }
+
+ rv = GetOverlappedResult((HANDLE) thread->io_fd,
+ &thread->md.overlapped.overlapped, &bytes, FALSE);
+
+ thread->md.blocked_io_status = rv;
+ if (rv != 0) {
+ thread->md.blocked_io_bytes = bytes;
+ } else {
+ thread->md.blocked_io_error = GetLastError();
+ PR_ASSERT(ERROR_IO_PENDING != thread->md.blocked_io_error);
+ }
+ rv = ResetEvent(thread->md.thr_event);
+ PR_ASSERT(rv != 0);
+ break;
+ case WAIT_OBJECT_0 + _NATIVE_WAKEUP_EVENT_INDEX:
+ /*
+ * I/O interrupted;
+ */
#ifdef DEBUG
- _PR_THREAD_LOCK(thread);
- PR_ASSERT(thread->io_suspended == PR_TRUE);
- _PR_THREAD_UNLOCK(thread);
+ _PR_THREAD_LOCK(thread);
+ PR_ASSERT(thread->io_suspended == PR_TRUE);
+ _PR_THREAD_UNLOCK(thread);
#endif
- break;
- case WAIT_TIMEOUT:
- _PR_THREAD_LOCK(thread);
- if (thread->state == _PR_IO_WAIT) {
- thread->state = _PR_RUNNING;
- thread->io_suspended = PR_TRUE;
- _PR_THREAD_UNLOCK(thread);
- } else {
- /*
- * The thread was interrupted just as the timeout
- * occurred. This left the semaphore in the signaled
- * state. Call WaitForSingleObject() to clear the
- * semaphore.
- */
- PR_ASSERT(thread->io_suspended == PR_TRUE);
- _PR_THREAD_UNLOCK(thread);
- rv = WaitForSingleObject(thread->md.blocked_sema, INFINITE);
- PR_ASSERT(rv == WAIT_OBJECT_0);
- }
- break;
- default:
- return PR_FAILURE;
- break;
- }
+ break;
+ case WAIT_TIMEOUT:
+ _PR_THREAD_LOCK(thread);
+ if (thread->state == _PR_IO_WAIT) {
+ thread->state = _PR_RUNNING;
+ thread->io_suspended = PR_TRUE;
+ _PR_THREAD_UNLOCK(thread);
+ } else {
+ /*
+ * The thread was interrupted just as the timeout
+ * occurred. This left the semaphore in the signaled
+ * state. Call WaitForSingleObject() to clear the
+ * semaphore.
+ */
+ PR_ASSERT(thread->io_suspended == PR_TRUE);
+ _PR_THREAD_UNLOCK(thread);
+ rv = WaitForSingleObject(thread->md.blocked_sema, INFINITE);
+ PR_ASSERT(rv == WAIT_OBJECT_0);
+ }
+ break;
+ default:
+ return PR_FAILURE;
+ break;
+ }
return PR_SUCCESS;
}
@@ -689,28 +707,31 @@ _NT_IO_WAIT(PRThread *thread, PRIntervalTime timeout)
{
PRBool fWait = PR_TRUE;
- if (_native_threads_only) {
- return(_native_thread_io_wait(thread, timeout));
- }
+ if (_native_threads_only) {
+ return(_native_thread_io_wait(thread, timeout));
+ }
if (!_PR_IS_NATIVE_THREAD(thread)) {
_PR_THREAD_LOCK(thread);
- /* The IO may have already completed; if so, don't add to sleepQ,
+ /* The IO may have already completed; if so, don't add to sleepQ,
* since we are already on the runQ!
*/
if (thread->io_pending == PR_TRUE) {
_PR_SLEEPQ_LOCK(thread->cpu);
_PR_ADD_SLEEPQ(thread, timeout);
_PR_SLEEPQ_UNLOCK(thread->cpu);
- } else
+ } else {
fWait = PR_FALSE;
+ }
_PR_THREAD_UNLOCK(thread);
}
- if (fWait)
+ if (fWait) {
return _PR_MD_WAIT(thread, timeout);
- else
+ }
+ else {
return PR_SUCCESS;
+ }
}
/*
@@ -724,18 +745,18 @@ void _PR_Unblock_IO_Wait(PRThread *thr)
{
PRStatus rv;
_PRCPU *cpu = thr->cpu;
-
+
PR_ASSERT(thr->state == _PR_IO_WAIT);
- /*
- * A thread for which an I/O timed out or was interrupted cannot be
- * in an IO_WAIT state except as a result of calling PR_Close or
- * PR_NT_CancelIo for the FD. For these two cases, _PR_IO_WAIT state
- * is not interruptible
- */
- if (thr->md.interrupt_disabled == PR_TRUE) {
- _PR_THREAD_UNLOCK(thr);
- return;
- }
+ /*
+ * A thread for which an I/O timed out or was interrupted cannot be
+ * in an IO_WAIT state except as a result of calling PR_Close or
+ * PR_NT_CancelIo for the FD. For these two cases, _PR_IO_WAIT state
+ * is not interruptible
+ */
+ if (thr->md.interrupt_disabled == PR_TRUE) {
+ _PR_THREAD_UNLOCK(thr);
+ return;
+ }
thr->io_suspended = PR_TRUE;
thr->state = _PR_RUNNABLE;
@@ -745,11 +766,11 @@ void _PR_Unblock_IO_Wait(PRThread *thr)
_PR_SLEEPQ_LOCK(cpu);
_PR_DEL_SLEEPQ(thr, PR_TRUE);
_PR_SLEEPQ_UNLOCK(cpu);
- /*
- * this thread will continue to run on the same cpu until the
- * I/O is aborted by closing the FD or calling CancelIO
- */
- thr->md.thr_bound_cpu = cpu;
+ /*
+ * this thread will continue to run on the same cpu until the
+ * I/O is aborted by closing the FD or calling CancelIO
+ */
+ thr->md.thr_bound_cpu = cpu;
PR_ASSERT(!(thr->flags & _PR_IDLE_THREAD));
_PR_AddThreadToRunQ(me, thr);
@@ -773,13 +794,14 @@ _NT_ResumeIO(PRThread *thread, PRIntervalTime ticks)
}
} else {
_PR_THREAD_LOCK(thread);
- if (!thread->io_pending)
+ if (!thread->io_pending) {
fWait = PR_FALSE;
+ }
thread->io_suspended = PR_FALSE;
-
+
_PR_THREAD_UNLOCK(thread);
}
- /* We don't put ourselves back on the sleepQ yet; until we
+ /* We don't put ourselves back on the sleepQ yet; until we
* set the suspended bit to false, we can't do that. Just save
* the sleep time here, and then continue. The restarted_io handler
* will add us to the sleepQ if needed.
@@ -787,10 +809,12 @@ _NT_ResumeIO(PRThread *thread, PRIntervalTime ticks)
thread->sleep = ticks;
if (fWait) {
- if (!_PR_IS_NATIVE_THREAD(thread))
+ if (!_PR_IS_NATIVE_THREAD(thread)) {
return _PR_MD_WAIT(thread, ticks);
- else
+ }
+ else {
return _NT_IO_WAIT(thread, ticks);
+ }
}
return PR_SUCCESS;
}
@@ -800,36 +824,40 @@ _PR_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread == NULL) {
/* If thread is NULL, we aren't waking a thread, we're just poking
- * idle thread
+ * idle thread
*/
- if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
- KEY_CVAR, NULL) == FALSE)
+ if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
+ KEY_CVAR, NULL) == FALSE) {
return PR_FAILURE;
+ }
return PR_SUCCESS;
}
if ( _PR_IS_NATIVE_THREAD(thread) ) {
- if (ReleaseSemaphore(thread->md.blocked_sema, 1, NULL) == FALSE)
+ if (ReleaseSemaphore(thread->md.blocked_sema, 1, NULL) == FALSE) {
return PR_FAILURE;
- else
+ }
+ else {
return PR_SUCCESS;
+ }
} else {
PRThread *me = _PR_MD_CURRENT_THREAD();
/* When a Native thread has to awaken a user thread, it has to poke
* the completion port because all user threads might be idle, and
- * thus the CPUs are just waiting for a completion.
+ * thus the CPUs are just waiting for a completion.
*
- * XXXMB - can we know when we are truely idle (and not checking
+ * XXXMB - can we know when we are truely idle (and not checking
* the runq)?
*/
if ((_PR_IS_NATIVE_THREAD(me) || (thread->cpu != me->cpu)) &&
- (!thread->md.thr_bound_cpu)) {
+ (!thread->md.thr_bound_cpu)) {
/* The thread should not be in any queue */
PR_ASSERT(thread->queueCount == 0);
- if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
- KEY_CVAR, &(thread->md.overlapped.overlapped)) == FALSE)
+ if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
+ KEY_CVAR, &(thread->md.overlapped.overlapped)) == FALSE) {
return PR_FAILURE;
+ }
}
return PR_SUCCESS;
}
@@ -845,12 +873,12 @@ _PR_MD_INIT_IO()
err = WSAStartup( WSAVersion, &WSAData );
PR_ASSERT(0 == err);
-
- _pr_completion_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE,
- NULL,
- 0,
- 0);
-
+
+ _pr_completion_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE,
+ NULL,
+ 0,
+ 0);
+
_MD_NEW_LOCK(&_pr_recycle_lock);
_MD_NEW_LOCK(&_pr_ioq_lock);
@@ -860,8 +888,9 @@ _PR_MD_INIT_IO()
if (OSversion.dwMajorVersion >= 4) {
_nt_version_gets_lockfile_completion = PR_TRUE;
}
- } else
+ } else {
PR_ASSERT(0);
+ }
#ifdef _NEED_351_FILE_LOCKING_HACK
IsFileLocalInit();
@@ -882,8 +911,8 @@ _PR_MD_INIT_IO()
#endif
pt_tq.thread = PR_CreateThread(
- PR_SYSTEM_THREAD, ContinuationThread, NULL,
- PR_PRIORITY_URGENT, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_SYSTEM_THREAD, ContinuationThread, NULL,
+ PR_PRIORITY_URGENT, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(NULL != pt_tq.thread);
@@ -892,8 +921,8 @@ _PR_MD_INIT_IO()
{
SYSTEMTIME systime;
union {
- PRTime prt;
- FILETIME ft;
+ PRTime prt;
+ FILETIME ft;
} filetime;
BOOL rv;
@@ -972,7 +1001,7 @@ _md_put_recycled_socket(SOCKET newsock, int af)
_MD_UNLOCK(&_pr_recycle_lock);
closesocket(newsock);
}
-
+
return;
}
@@ -985,17 +1014,17 @@ _md_Associate(HANDLE file)
{
HANDLE port;
- if (!_native_threads_only) {
- port = CreateIoCompletionPort((HANDLE)file,
- _pr_completion_port,
- KEY_IO,
- 0);
-
- /* XXX should map error codes on failures */
- return (port == _pr_completion_port);
- } else {
- return 1;
- }
+ if (!_native_threads_only) {
+ port = CreateIoCompletionPort((HANDLE)file,
+ _pr_completion_port,
+ KEY_IO,
+ 0);
+
+ /* XXX should map error codes on failures */
+ return (port == _pr_completion_port);
+ } else {
+ return 1;
+ }
}
/*
@@ -1026,7 +1055,7 @@ _NT_IO_ABORT(PROsfd sock)
int loop_count;
/* This is a clumsy way to abort the IO, but it is all we can do.
- * It looks a bit racy, but we handle all the cases.
+ * It looks a bit racy, but we handle all the cases.
* case 1: IO completes before calling closesocket
* case 1a: fWait is set to PR_FALSE
* This should e the most likely case. We'll properly
@@ -1139,15 +1168,16 @@ _PR_MD_connect_thread(void *cdata)
cd->status = connect(cd->osfd, cd->addr, cd->addrlen);
- if (cd->status == SOCKET_ERROR)
+ if (cd->status == SOCKET_ERROR) {
cd->error = WSAGetLastError();
+ }
return;
}
PRInt32
-_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
+_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
PRIntervalTime timeout)
{
PROsfd osfd = fd->secret->md.osfd;
@@ -1207,7 +1237,7 @@ _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen)
#if 0
/* Disable nagle- so far unknown if this is good or not...
*/
- rv = setsockopt(fd->secret->md.osfd,
+ rv = setsockopt(fd->secret->md.osfd,
SOL_SOCKET,
TCP_NODELAY,
(const char *)&one,
@@ -1221,19 +1251,19 @@ _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen)
void _PR_MD_UPDATE_ACCEPT_CONTEXT(PROsfd accept_sock, PROsfd listen_sock)
{
/* Sockets accept()'d with AcceptEx need to call this setsockopt before
- * calling anything other than ReadFile(), WriteFile(), send(), recv(),
- * Transmitfile(), and closesocket(). In order to call any other
+ * calling anything other than ReadFile(), WriteFile(), send(), recv(),
+ * Transmitfile(), and closesocket(). In order to call any other
* winsock functions, we have to make this setsockopt call.
*
* XXXMB - For the server, we *NEVER* need this in
* the "normal" code path. But now we have to call it. This is a waste
- * of a system call. We'd like to only call it before calling the
+ * of a system call. We'd like to only call it before calling the
* obscure socket calls, but since we don't know at that point what the
* original socket was (or even if it is still alive) we can't do it
- * at that point...
+ * at that point...
*/
- setsockopt((SOCKET)accept_sock,
- SOL_SOCKET,
+ setsockopt((SOCKET)accept_sock,
+ SOL_SOCKET,
SO_UPDATE_ACCEPT_CONTEXT,
(char *)&listen_sock,
sizeof(listen_sock));
@@ -1243,8 +1273,8 @@ void _PR_MD_UPDATE_ACCEPT_CONTEXT(PROsfd accept_sock, PROsfd listen_sock)
#define INET_ADDR_PADDED (sizeof(PRNetAddr) + 16)
PROsfd
_PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
- PRIntervalTime timeout, PRBool fast,
- _PR_AcceptTimeoutCallback callback, void *callbackArg)
+ PRIntervalTime timeout, PRBool fast,
+ _PR_AcceptTimeoutCallback callback, void *callbackArg)
{
PROsfd osfd = fd->secret->md.osfd;
PRThread *me = _PR_MD_CURRENT_THREAD();
@@ -1296,21 +1326,23 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
}
accept_sock = _md_get_recycled_socket(fd->secret->af);
- if (accept_sock == INVALID_SOCKET)
+ if (accept_sock == INVALID_SOCKET) {
return -1;
+ }
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- closesocket(accept_sock);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ closesocket(accept_sock);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
@@ -1327,19 +1359,19 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
if ( (rv == 0) && ((err = WSAGetLastError()) != ERROR_IO_PENDING)) {
/* Argh! The IO failed */
- closesocket(accept_sock);
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_ACCEPTEX_ERROR(err);
+ closesocket(accept_sock);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_ACCEPTEX_ERROR(err);
return -1;
}
@@ -1365,27 +1397,29 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
}
if (me->md.blocked_io_status == 0) {
- closesocket(accept_sock);
- _PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
+ closesocket(accept_sock);
+ _PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
return -1;
}
- if (!fast)
+ if (!fast) {
_PR_MD_UPDATE_ACCEPT_CONTEXT((SOCKET)accept_sock, (SOCKET)osfd);
+ }
/* IO is done */
GetAcceptExSockaddrs(
- me->md.acceptex_buf,
- 0,
- INET_ADDR_PADDED,
- INET_ADDR_PADDED,
- (LPSOCKADDR *)&(Laddr),
- &llen,
- (LPSOCKADDR *)&(Raddr),
- (unsigned int *)rlen);
-
- if (raddr != NULL)
+ me->md.acceptex_buf,
+ 0,
+ INET_ADDR_PADDED,
+ INET_ADDR_PADDED,
+ (LPSOCKADDR *)&(Laddr),
+ &llen,
+ (LPSOCKADDR *)&(Raddr),
+ (unsigned int *)rlen);
+
+ if (raddr != NULL) {
memcpy((char *)raddr, (char *)&Raddr->inet, *rlen);
+ }
PR_ASSERT(me->io_pending == PR_FALSE);
@@ -1393,10 +1427,10 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
}
PRInt32
-_PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr,
- void *buf, PRInt32 amount, PRIntervalTime timeout,
- PRBool fast, _PR_AcceptTimeoutCallback callback,
- void *callbackArg)
+_PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr,
+ void *buf, PRInt32 amount, PRIntervalTime timeout,
+ PRBool fast, _PR_AcceptTimeoutCallback callback,
+ void *callbackArg)
{
PROsfd sock = sd->secret->md.osfd;
PRThread *me = _PR_MD_CURRENT_THREAD();
@@ -1419,21 +1453,23 @@ _PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr,
}
*newSock = _md_get_recycled_socket(sd->secret->af);
- if (*newSock == INVALID_SOCKET)
+ if (*newSock == INVALID_SOCKET) {
return -1;
+ }
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- closesocket(*newSock);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ closesocket(*newSock);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
@@ -1449,19 +1485,19 @@ _PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr,
&(me->md.overlapped.overlapped));
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING)) {
- closesocket(*newSock);
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_ACCEPTEX_ERROR(err);
+ closesocket(*newSock);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_ACCEPTEX_ERROR(err);
return -1;
}
@@ -1481,7 +1517,7 @@ retry:
PR_ASSERT(timeout != PR_INTERVAL_NO_TIMEOUT);
- err = getsockopt(*newSock,
+ err = getsockopt(*newSock,
SOL_SOCKET,
SO_CONNECT_TIME,
(char *)&seconds,
@@ -1489,14 +1525,17 @@ retry:
if ( err == NO_ERROR ) {
PRIntervalTime elapsed = PR_SecondsToInterval(seconds);
- if (seconds == 0xffffffff)
+ if (seconds == 0xffffffff) {
isConnected = PR_FALSE;
- else
+ }
+ else {
isConnected = PR_TRUE;
+ }
if (!isConnected) {
- if (madeCallback == PR_FALSE && callback)
+ if (madeCallback == PR_FALSE && callback) {
callback(callbackArg);
+ }
madeCallback = PR_TRUE;
me->state = _PR_IO_WAIT;
if (_NT_ResumeIO(me, timeout) == PR_FAILURE) {
@@ -1527,9 +1566,9 @@ retry:
PR_ASSERT(me->io_pending == PR_FALSE);
PR_ASSERT(me->io_suspended == PR_FALSE);
PR_ASSERT(me->md.thr_bound_cpu == NULL);
- /* If the IO is still suspended, it means we didn't get any
+ /* If the IO is still suspended, it means we didn't get any
* completion from NT_IO_WAIT. This is not disasterous, I hope,
- * but it may mean we still have an IO outstanding... Try to
+ * but it may mean we still have an IO outstanding... Try to
* recover by just allowing ourselves to continue.
*/
me->io_suspended = PR_FALSE;
@@ -1549,31 +1588,32 @@ retry:
PR_ASSERT(me->md.thr_bound_cpu == NULL);
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
closesocket(*newSock);
return -1;
}
- if (!fast)
+ if (!fast) {
_PR_MD_UPDATE_ACCEPT_CONTEXT((SOCKET)*newSock, (SOCKET)sock);
+ }
/* IO is done */
GetAcceptExSockaddrs(
- buf,
- amount,
- INET_ADDR_PADDED,
- INET_ADDR_PADDED,
- (LPSOCKADDR *)&(Laddr),
- &llen,
- (LPSOCKADDR *)(raddr),
- (unsigned int *)&rlen);
+ buf,
+ amount,
+ INET_ADDR_PADDED,
+ INET_ADDR_PADDED,
+ (LPSOCKADDR *)&(Laddr),
+ &llen,
+ (LPSOCKADDR *)(raddr),
+ (unsigned int *)&rlen);
return me->md.blocked_io_bytes;
}
PRInt32
_PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
- PRInt32 flags, PRIntervalTime timeout)
+ PRInt32 flags, PRIntervalTime timeout)
{
PRThread *me = _PR_MD_CURRENT_THREAD();
PRInt32 tflags;
@@ -1603,20 +1643,22 @@ _PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
me->md.overlapped.overlapped.Offset = sfd->file_offset;
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
tflags = 0;
- if (flags & PR_TRANSMITFILE_CLOSE_SOCKET)
+ if (flags & PR_TRANSMITFILE_CLOSE_SOCKET) {
tflags = TF_DISCONNECT | TF_REUSE_SOCKET;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
@@ -1630,18 +1672,18 @@ _PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
(TRANSMIT_FILE_BUFFERS *)me->md.xmit_bufs,
(DWORD)tflags);
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_TRANSMITFILE_ERROR(err);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_TRANSMITFILE_ERROR(err);
return -1;
}
@@ -1663,7 +1705,7 @@ _PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
}
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_TRANSMITFILE_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_TRANSMITFILE_ERROR(me->md.blocked_io_error);
return -1;
}
@@ -1677,7 +1719,7 @@ _PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
}
PRInt32
-_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
+_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PRIntervalTime timeout)
{
PROsfd osfd = fd->secret->md.osfd;
@@ -1706,41 +1748,43 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
}
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
me->io_fd = osfd;
rv = ReadFile((HANDLE)osfd,
- buf,
+ buf,
amount,
&bytes,
&(me->md.overlapped.overlapped));
if ( (rv == 0) && (GetLastError() != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
+ _PR_THREAD_LOCK(me);
me->io_pending = PR_FALSE;
me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- if ((err = GetLastError()) == ERROR_HANDLE_EOF)
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ if ((err = GetLastError()) == ERROR_HANDLE_EOF) {
return 0;
- _PR_MD_MAP_READ_ERROR(err);
+ }
+ _PR_MD_MAP_READ_ERROR(err);
return -1;
}
@@ -1764,9 +1808,10 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
}
if (me->md.blocked_io_status == 0) {
- if (me->md.blocked_io_error == ERROR_HANDLE_EOF)
+ if (me->md.blocked_io_error == ERROR_HANDLE_EOF) {
return 0;
- _PR_MD_MAP_READ_ERROR(me->md.blocked_io_error);
+ }
+ _PR_MD_MAP_READ_ERROR(me->md.blocked_io_error);
return -1;
}
@@ -1805,39 +1850,40 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
}
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
me->io_fd = osfd;
rv = WriteFile((HANDLE)osfd,
- buf,
+ buf,
amount,
&bytes,
&(me->md.overlapped.overlapped));
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
+ _PR_THREAD_LOCK(me);
me->io_pending = PR_FALSE;
me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_WRITE_ERROR(err);
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_WRITE_ERROR(err);
return -1;
}
@@ -1861,7 +1907,7 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
}
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_WRITE_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_WRITE_ERROR(me->md.blocked_io_error);
return -1;
}
@@ -1882,10 +1928,12 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
PR_ASSERT(0 != rv);
fd->secret->md.io_model_committed = PR_TRUE;
}
- if (_NT_USE_NB_IO(fd))
+ if (_NT_USE_NB_IO(fd)) {
return _nt_nonblock_sendto(fd, buf, amount, (struct sockaddr *)addr, addrlen, timeout);
- else
+ }
+ else {
return pt_SendTo(osfd, buf, amount, flags, addr, addrlen, timeout);
+ }
}
PRInt32
@@ -1900,10 +1948,12 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PR_ASSERT(0 != rv);
fd->secret->md.io_model_committed = PR_TRUE;
}
- if (_NT_USE_NB_IO(fd))
+ if (_NT_USE_NB_IO(fd)) {
return _nt_nonblock_recvfrom(fd, buf, amount, (struct sockaddr *)addr, addrlen, timeout);
- else
+ }
+ else {
return pt_RecvFrom(osfd, buf, amount, flags, addr, addrlen, timeout);
+ }
}
/* XXXMB - for now this is a sockets call only */
@@ -1926,12 +1976,14 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTi
for (index=0; index<iov_size; index++) {
rv = _PR_MD_SEND(fd, iov[index].iov_base, iov[index].iov_len, 0,
- timeout);
- if (rv > 0)
+ timeout);
+ if (rv > 0) {
sent += rv;
+ }
if ( rv != iov[index].iov_len ) {
- if (sent <= 0)
+ if (sent <= 0) {
return -1;
+ }
return -1;
}
}
@@ -1945,9 +1997,10 @@ _PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog)
PRInt32 rv;
rv = listen(fd->secret->md.osfd, backlog);
- if (rv < 0)
- _PR_MD_MAP_LISTEN_ERROR(WSAGetLastError());
- return(rv);
+ if (rv < 0) {
+ _PR_MD_MAP_LISTEN_ERROR(WSAGetLastError());
+ }
+ return(rv);
}
PRInt32
@@ -1956,9 +2009,10 @@ _PR_MD_SHUTDOWN(PRFileDesc *fd, PRIntn how)
PRInt32 rv;
rv = shutdown(fd->secret->md.osfd, how);
- if (rv < 0)
- _PR_MD_MAP_SHUTDOWN_ERROR(WSAGetLastError());
- return(rv);
+ if (rv < 0) {
+ _PR_MD_MAP_SHUTDOWN_ERROR(WSAGetLastError());
+ }
+ return(rv);
}
PRStatus
@@ -1967,12 +2021,13 @@ _PR_MD_GETSOCKNAME(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *len)
PRInt32 rv;
rv = getsockname((SOCKET)fd->secret->md.osfd, (struct sockaddr *)addr, len);
- if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_GETSOCKNAME_ERROR(WSAGetLastError());
- return PR_FAILURE;
- }
+ if (rv==0) {
+ return PR_SUCCESS;
+ }
+ else {
+ _PR_MD_MAP_GETSOCKNAME_ERROR(WSAGetLastError());
+ return PR_FAILURE;
+ }
}
PRStatus
@@ -1996,7 +2051,7 @@ _PR_MD_GETPEERNAME(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *len)
* Determine if the socket is connected.
*/
- rv = getsockopt(fd->secret->md.osfd,
+ rv = getsockopt(fd->secret->md.osfd,
SOL_SOCKET,
SO_CONNECT_TIME,
(char *) &seconds,
@@ -2013,7 +2068,7 @@ _PR_MD_GETPEERNAME(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *len)
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return PR_FAILURE;
}
- } else {
+ } else {
rv = getpeername((SOCKET)fd->secret->md.osfd,
(struct sockaddr *) addr, len);
if (rv == 0) {
@@ -2031,12 +2086,13 @@ _PR_MD_GETSOCKOPT(PRFileDesc *fd, PRInt32 level, PRInt32 optname, char* optval,
PRInt32 rv;
rv = getsockopt((SOCKET)fd->secret->md.osfd, level, optname, optval, optlen);
- if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
- return PR_FAILURE;
- }
+ if (rv==0) {
+ return PR_SUCCESS;
+ }
+ else {
+ _PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
+ return PR_FAILURE;
+ }
}
PRStatus
@@ -2045,12 +2101,13 @@ _PR_MD_SETSOCKOPT(PRFileDesc *fd, PRInt32 level, PRInt32 optname, const char* op
PRInt32 rv;
rv = setsockopt((SOCKET)fd->secret->md.osfd, level, optname, optval, optlen);
- if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_SETSOCKOPT_ERROR(WSAGetLastError());
- return PR_FAILURE;
- }
+ if (rv==0) {
+ return PR_SUCCESS;
+ }
+ else {
+ _PR_MD_MAP_SETSOCKOPT_ERROR(WSAGetLastError());
+ return PR_FAILURE;
+ }
}
/* --- FILE IO ----------------------------------------------------------- */
@@ -2062,27 +2119,39 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, PRIntn mode)
PRInt32 access = 0;
PRInt32 flags = 0;
PRInt32 flag6 = 0;
-
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
-
- if (osflags & PR_RDONLY || osflags & PR_RDWR) access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR) access |= GENERIC_WRITE;
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
+
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
+ access |= GENERIC_READ;
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
+ access |= GENERIC_WRITE;
+ }
+
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
- else if (osflags & PR_CREATE_FILE)
+ }
+ else if (osflags & PR_CREATE_FILE) {
flags = (0 != (osflags & PR_TRUNCATE)) ? CREATE_ALWAYS : OPEN_ALWAYS;
- else if (osflags & PR_TRUNCATE) flags = TRUNCATE_EXISTING;
- else flags = OPEN_EXISTING;
+ }
+ else if (osflags & PR_TRUNCATE) {
+ flags = TRUNCATE_EXISTING;
+ }
+ else {
+ flags = OPEN_EXISTING;
+ }
flag6 |= FILE_FLAG_OVERLAPPED;
- file = CreateFile(name,
- access,
+ file = CreateFile(name,
+ access,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
- flags,
+ flags,
flag6,
NULL);
if (file == INVALID_HANDLE_VALUE) {
@@ -2113,35 +2182,47 @@ _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, PRIntn mode)
PSECURITY_DESCRIPTOR pSD = NULL;
PACL pACL = NULL;
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
-
- if (osflags & PR_RDONLY || osflags & PR_RDWR) access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR) access |= GENERIC_WRITE;
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
+
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
+ access |= GENERIC_READ;
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
+ access |= GENERIC_WRITE;
+ }
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
- else if (osflags & PR_CREATE_FILE)
+ }
+ else if (osflags & PR_CREATE_FILE) {
flags = (0 != (osflags & PR_TRUNCATE)) ? CREATE_ALWAYS : OPEN_ALWAYS;
- else if (osflags & PR_TRUNCATE) flags = TRUNCATE_EXISTING;
- else flags = OPEN_EXISTING;
+ }
+ else if (osflags & PR_TRUNCATE) {
+ flags = TRUNCATE_EXISTING;
+ }
+ else {
+ flags = OPEN_EXISTING;
+ }
flag6 |= FILE_FLAG_OVERLAPPED;
if (osflags & PR_CREATE_FILE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, fileAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
lpSA = &sa;
}
}
- file = CreateFile(name,
- access,
+ file = CreateFile(name,
+ access,
FILE_SHARE_READ|FILE_SHARE_WRITE,
lpSA,
- flags,
+ flags,
flag6,
NULL);
if (lpSA != NULL) {
@@ -2163,7 +2244,7 @@ _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, PRIntn mode)
return (PROsfd)file;
}
-PRInt32
+PRInt32
_PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
{
PROsfd f = fd->secret->md.osfd;
@@ -2186,10 +2267,10 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
PR_ASSERT((me->md.overlapped.overlapped.Offset != 0xffffffff) || (GetLastError() == NO_ERROR));
if (fd->secret->inheritable == _PR_TRI_TRUE) {
- rv = ReadFile((HANDLE)f,
- (LPVOID)buf,
- len,
- &bytes,
+ rv = ReadFile((HANDLE)f,
+ (LPVOID)buf,
+ len,
+ &bytes,
&me->md.overlapped.overlapped);
if (rv != 0) {
loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
@@ -2199,7 +2280,7 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
err = GetLastError();
if (err == ERROR_IO_PENDING) {
rv = GetOverlappedResult((HANDLE)f,
- &me->md.overlapped.overlapped, &bytes, TRUE);
+ &me->md.overlapped.overlapped, &bytes, TRUE);
if (rv != 0) {
loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
PR_ASSERT((loOffset != 0xffffffff) || (GetLastError() == NO_ERROR));
@@ -2220,37 +2301,38 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
fd->secret->md.io_model_committed = PR_TRUE;
}
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
-
- _PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- me->io_pending = PR_TRUE;
- me->state = _PR_IO_WAIT;
- _PR_THREAD_UNLOCK(me);
- me->io_fd = f;
-
- rv = ReadFile((HANDLE)f,
- (LPVOID)buf,
- len,
- &bytes,
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
+
+ _PR_THREAD_LOCK(me);
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ me->io_pending = PR_TRUE;
+ me->state = _PR_IO_WAIT;
+ _PR_THREAD_UNLOCK(me);
+ me->io_fd = f;
+
+ rv = ReadFile((HANDLE)f,
+ (LPVOID)buf,
+ len,
+ &bytes,
&me->md.overlapped.overlapped);
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
if (err == ERROR_HANDLE_EOF) {
return 0;
@@ -2287,7 +2369,7 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
}
SetFilePointer((HANDLE)f, me->md.blocked_io_bytes, 0, FILE_CURRENT);
-
+
PR_ASSERT(me->io_pending == PR_FALSE);
return me->md.blocked_io_bytes;
@@ -2304,7 +2386,7 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
/* ERROR_HANDLE_EOF can only be returned by async io */
PR_ASSERT(err != ERROR_HANDLE_EOF);
if (err == ERROR_BROKEN_PIPE) {
- /* The write end of the pipe has been closed. */
+ /* The write end of the pipe has been closed. */
return 0;
}
_PR_MD_MAP_READ_ERROR(err);
@@ -2338,11 +2420,11 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
PR_ASSERT((me->md.overlapped.overlapped.Offset != 0xffffffff) || (GetLastError() == NO_ERROR));
if (fd->secret->inheritable == _PR_TRI_TRUE) {
- rv = WriteFile((HANDLE)f,
- (LPVOID)buf,
- len,
- &bytes,
- &me->md.overlapped.overlapped);
+ rv = WriteFile((HANDLE)f,
+ (LPVOID)buf,
+ len,
+ &bytes,
+ &me->md.overlapped.overlapped);
if (rv != 0) {
loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
PR_ASSERT((loOffset != 0xffffffff) || (GetLastError() == NO_ERROR));
@@ -2351,7 +2433,7 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
err = GetLastError();
if (err == ERROR_IO_PENDING) {
rv = GetOverlappedResult((HANDLE)f,
- &me->md.overlapped.overlapped, &bytes, TRUE);
+ &me->md.overlapped.overlapped, &bytes, TRUE);
if (rv != 0) {
loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
PR_ASSERT((loOffset != 0xffffffff) || (GetLastError() == NO_ERROR));
@@ -2367,37 +2449,38 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
PR_ASSERT(rv != 0);
fd->secret->md.io_model_committed = PR_TRUE;
}
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
-
- _PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- me->io_pending = PR_TRUE;
- me->state = _PR_IO_WAIT;
- _PR_THREAD_UNLOCK(me);
- me->io_fd = f;
-
- rv = WriteFile((HANDLE)f,
- buf,
- len,
- &bytes,
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
+
+ _PR_THREAD_LOCK(me);
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ me->io_pending = PR_TRUE;
+ me->state = _PR_IO_WAIT;
+ _PR_THREAD_UNLOCK(me);
+ me->io_fd = f;
+
+ rv = WriteFile((HANDLE)f,
+ buf,
+ len,
+ &bytes,
&(me->md.overlapped.overlapped));
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
_PR_MD_MAP_WRITE_ERROR(err);
return -1;
@@ -2439,7 +2522,7 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
offset.QuadPart += me->md.blocked_io_bytes;
SetFilePointer((HANDLE)f, offset.LowPart, &offset.HighPart, FILE_BEGIN);
-
+
PR_ASSERT(me->io_pending == PR_FALSE);
return me->md.blocked_io_bytes;
@@ -2464,7 +2547,7 @@ _PR_MD_SOCKETAVAILABLE(PRFileDesc *fd)
PRInt32 result;
if (ioctlsocket(fd->secret->md.osfd, FIONREAD, &result) < 0) {
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, WSAGetLastError());
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, WSAGetLastError());
return -1;
}
return result;
@@ -2473,10 +2556,12 @@ _PR_MD_SOCKETAVAILABLE(PRFileDesc *fd)
PRInt32
_PR_MD_PIPEAVAILABLE(PRFileDesc *fd)
{
- if (NULL == fd)
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
- else
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ if (NULL == fd) {
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
+ }
+ else {
+ PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ }
return -1;
}
@@ -2537,7 +2622,7 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence)
li.QuadPart = offset;
li.LowPart = SetFilePointer((HANDLE)fd->secret->md.osfd,
- li.LowPart, &li.HighPart, moveMethod);
+ li.LowPart, &li.HighPart, moveMethod);
if (0xffffffff == li.LowPart && (err = GetLastError()) != NO_ERROR) {
_PR_MD_MAP_LSEEK_ERROR(err);
@@ -2558,10 +2643,10 @@ _PR_MD_FSYNC(PRFileDesc *fd)
/*
* From the documentation:
*
- * On Windows NT, the function FlushFileBuffers fails if hFile
- * is a handle to console output. That is because console
- * output is not buffered. The function returns FALSE, and
- * GetLastError returns ERROR_INVALID_HANDLE.
+ * On Windows NT, the function FlushFileBuffers fails if hFile
+ * is a handle to console output. That is because console
+ * output is not buffered. The function returns FALSE, and
+ * GetLastError returns ERROR_INVALID_HANDLE.
*
* On the other hand, on Win95, it returns without error. I cannot
* assume that 0, 1, and 2 are console, because if someone closes
@@ -2575,12 +2660,12 @@ _PR_MD_FSYNC(PRFileDesc *fd)
BOOL ok = FlushFileBuffers((HANDLE)fd->secret->md.osfd);
if (!ok) {
- DWORD err = GetLastError();
+ DWORD err = GetLastError();
- if (err != ERROR_ACCESS_DENIED) { /* from winerror.h */
- _PR_MD_MAP_FSYNC_ERROR(err);
- return -1;
- }
+ if (err != ERROR_ACCESS_DENIED) { /* from winerror.h */
+ _PR_MD_MAP_FSYNC_ERROR(err);
+ return -1;
+ }
}
return 0;
}
@@ -2593,12 +2678,14 @@ _PR_MD_CLOSE(PROsfd osfd, PRBool socket)
if (socket) {
rv = closesocket((SOCKET)osfd);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_CLOSE_ERROR(WSAGetLastError());
+ }
} else {
rv = CloseHandle((HANDLE)osfd)?0:-1;
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_CLOSE_ERROR(GetLastError());
+ }
}
if (rv == 0 && me->io_suspended) {
@@ -2608,7 +2695,7 @@ _PR_MD_CLOSE(PROsfd osfd, PRBool socket)
_PR_THREAD_LOCK(me);
me->state = _PR_IO_WAIT;
/* The IO could have completed on another thread just after
- * calling closesocket while the io_suspended flag was true.
+ * calling closesocket while the io_suspended flag was true.
* So we now grab the lock to do a safe check on io_pending to
* see if we need to wait or not.
*/
@@ -2617,8 +2704,9 @@ _PR_MD_CLOSE(PROsfd osfd, PRBool socket)
me->md.interrupt_disabled = PR_TRUE;
_PR_THREAD_UNLOCK(me);
- if (fWait)
+ if (fWait) {
_NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_ASSERT(me->io_suspended == PR_FALSE);
PR_ASSERT(me->io_pending == PR_FALSE);
/*
@@ -2647,15 +2735,15 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
return PR_FAILURE;
}
rv = SetHandleInformation(
- (HANDLE)fd->secret->md.osfd,
- HANDLE_FLAG_INHERIT,
- inheritable ? HANDLE_FLAG_INHERIT : 0);
+ (HANDLE)fd->secret->md.osfd,
+ HANDLE_FLAG_INHERIT,
+ inheritable ? HANDLE_FLAG_INHERIT : 0);
if (0 == rv) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
return PR_FAILURE;
}
return PR_SUCCESS;
-}
+}
void
_PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported)
@@ -2750,7 +2838,7 @@ _PR_MD_OPEN_DIR(_MDDir *d, const char *name)
d->d_hdl = FindFirstFile( filename, &(d->d_entry) );
if ( d->d_hdl == INVALID_HANDLE_VALUE ) {
- _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
+ _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return PR_FAILURE;
}
d->firstEntry = PR_TRUE;
@@ -2778,21 +2866,24 @@ _PR_MD_READ_DIR(_MDDir *d, PRIntn flags)
}
fileName = GetFileFromDIR(d);
if ( (flags & PR_SKIP_DOT) &&
- (fileName[0] == '.') && (fileName[1] == '\0'))
- continue;
+ (fileName[0] == '.') && (fileName[1] == '\0')) {
+ continue;
+ }
if ( (flags & PR_SKIP_DOT_DOT) &&
(fileName[0] == '.') && (fileName[1] == '.') &&
- (fileName[2] == '\0'))
- continue;
- if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d))
- continue;
+ (fileName[2] == '\0')) {
+ continue;
+ }
+ if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d)) {
+ continue;
+ }
return fileName;
}
- err = GetLastError();
- PR_ASSERT(NO_ERROR != err);
- _PR_MD_MAP_READDIR_ERROR(err);
- return NULL;
- }
+ err = GetLastError();
+ PR_ASSERT(NO_ERROR != err);
+ _PR_MD_MAP_READDIR_ERROR(err);
+ return NULL;
+ }
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
@@ -2801,11 +2892,11 @@ PRInt32
_PR_MD_DELETE(const char *name)
{
if (DeleteFile(name)) {
- return 0;
- } else {
- _PR_MD_MAP_DELETE_ERROR(GetLastError());
- return -1;
- }
+ return 0;
+ } else {
+ _PR_MD_MAP_DELETE_ERROR(GetLastError());
+ return -1;
+ }
}
void
@@ -2880,7 +2971,7 @@ _PR_MD_STAT(const char *fn, struct stat *info)
int len = strlen(fn);
if (len > 0 && len <= _MAX_PATH
- && IsPrevCharSlash(fn, fn + len)) {
+ && IsPrevCharSlash(fn, fn + len)) {
char newfn[_MAX_PATH + 1];
strcpy(newfn, fn);
@@ -2902,8 +2993,9 @@ IsPrevCharSlash(const char *str, const char *current)
{
const char *prev;
- if (str >= current)
+ if (str >= current) {
return PR_FALSE;
+ }
prev = _mbsdec(str, current);
return (prev == current - 1) && _PR_IS_SLASH(*prev);
}
@@ -2938,7 +3030,7 @@ IsRootDirectory(char *fn, size_t buflen)
}
if (isalpha(fn[0]) && fn[1] == ':' && _PR_IS_SLASH(fn[2])
- && fn[3] == '\0') {
+ && fn[3] == '\0') {
rv = GetDriveType(fn) > 1 ? PR_TRUE : PR_FALSE;
return rv;
}
@@ -3000,7 +3092,7 @@ PRInt32
_PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
{
WIN32_FILE_ATTRIBUTE_DATA findFileData;
-
+
if (NULL == fn || '\0' == *fn) {
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return -1;
@@ -3023,11 +3115,11 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
_PR_FileTimeToPRTime(&findFileData.ftLastWriteTime, &info->modifyTime);
if (0 == findFileData.ftCreationTime.dwLowDateTime &&
- 0 == findFileData.ftCreationTime.dwHighDateTime) {
+ 0 == findFileData.ftCreationTime.dwHighDateTime) {
info->creationTime = info->modifyTime;
} else {
_PR_FileTimeToPRTime(&findFileData.ftCreationTime,
- &info->creationTime);
+ &info->creationTime);
}
return 0;
@@ -3057,14 +3149,16 @@ _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info)
rv = GetFileInformationByHandle((HANDLE)fd->secret->md.osfd, &hinfo);
if (rv == FALSE) {
- _PR_MD_MAP_FSTAT_ERROR(GetLastError());
+ _PR_MD_MAP_FSTAT_ERROR(GetLastError());
return -1;
- }
+ }
- if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_FILE;
+ }
info->size = hinfo.nFileSizeHigh;
info->size = (info->size << 32) + hinfo.nFileSizeLow;
@@ -3084,14 +3178,16 @@ _PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info)
rv = GetFileInformationByHandle((HANDLE)fd->secret->md.osfd, &hinfo);
if (rv == FALSE) {
- _PR_MD_MAP_FSTAT_ERROR(GetLastError());
+ _PR_MD_MAP_FSTAT_ERROR(GetLastError());
return -1;
- }
+ }
- if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_FILE;
+ }
info->size = hinfo.nFileSizeLow;
@@ -3106,11 +3202,11 @@ _PR_MD_RENAME(const char *from, const char *to)
{
/* Does this work with dot-relative pathnames? */
if (MoveFile(from, to)) {
- return 0;
- } else {
- _PR_MD_MAP_RENAME_ERROR(GetLastError());
- return -1;
- }
+ return 0;
+ } else {
+ _PR_MD_MAP_RENAME_ERROR(GetLastError());
+ return -1;
+ }
}
PRInt32
@@ -3119,21 +3215,21 @@ _PR_MD_ACCESS(const char *name, PRAccessHow how)
PRInt32 rv;
switch (how) {
- case PR_ACCESS_WRITE_OK:
- rv = _access(name, 02);
- break;
- case PR_ACCESS_READ_OK:
- rv = _access(name, 04);
- break;
- case PR_ACCESS_EXISTS:
- rv = _access(name, 00);
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
- if (rv < 0) {
- _PR_MD_MAP_ACCESS_ERROR(errno);
+ case PR_ACCESS_WRITE_OK:
+ rv = _access(name, 02);
+ break;
+ case PR_ACCESS_READ_OK:
+ rv = _access(name, 04);
+ break;
+ case PR_ACCESS_EXISTS:
+ rv = _access(name, 00);
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
+ }
+ if (rv < 0) {
+ _PR_MD_MAP_ACCESS_ERROR(errno);
}
return rv;
}
@@ -3160,7 +3256,7 @@ _PR_MD_MAKE_DIR(const char *name, PRIntn mode)
PACL pACL = NULL;
if (_PR_NT_MakeSecurityDescriptorACL(mode, dirAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -3203,17 +3299,17 @@ _PR_MD_LOCKFILE(PROsfd f)
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
- rv = LockFileEx((HANDLE)f,
+ rv = LockFileEx((HANDLE)f,
LOCKFILE_EXCLUSIVE_LOCK,
0,
0x7fffffff,
@@ -3221,16 +3317,16 @@ _PR_MD_LOCKFILE(PROsfd f)
&me->md.overlapped.overlapped);
if (_native_threads_only) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
if (rv == FALSE) {
err = GetLastError();
@@ -3249,7 +3345,7 @@ _PR_MD_LOCKFILE(PROsfd f)
*
* If we pretend we won't get a completion, NSPR gets confused later
* when the unexpected completion arrives. If we assume we do get
- * a completion, we hang on 3.51. Worse, Microsoft informs me that the
+ * a completion, we hang on 3.51. Worse, Microsoft informs me that the
* behavior varies on 3.51 depending on if you are using a network
* file system or a local disk!
*
@@ -3257,51 +3353,51 @@ _PR_MD_LOCKFILE(PROsfd f)
* depending on whether or not this system is EITHER
* - running NT 4.0
* - running NT 3.51 with a service pack greater than 5.
- *
+ *
* In the meantime, this code may not work on network file systems.
*
*/
if ( rv == FALSE && ((err = GetLastError()) != ERROR_IO_PENDING)) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_LOCKF_ERROR(err);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_LOCKF_ERROR(err);
return PR_FAILURE;
}
#ifdef _NEED_351_FILE_LOCKING_HACK
else if (rv) {
- /* If this is NT 3.51 and the file is local, then we won't get a
+ /* If this is NT 3.51 and the file is local, then we won't get a
* completion back from LockFile when it succeeded.
*/
if (_nt_version_gets_lockfile_completion == PR_FALSE) {
if ( IsFileLocal((HANDLE)f) == _PR_LOCAL_FILE) {
me->io_pending = PR_FALSE;
me->state = _PR_RUNNING;
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
}
}
#endif /* _NEED_351_FILE_LOCKING_HACK */
if (_NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE) {
- _PR_THREAD_LOCK(me);
+ _PR_THREAD_LOCK(me);
me->io_pending = PR_FALSE;
me->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_UNLOCK(me);
return PR_FAILURE;
}
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
return PR_FAILURE;
}
@@ -3322,33 +3418,33 @@ _PR_MD_TLOCKFILE(PROsfd f)
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
- rv = LockFileEx((HANDLE)f,
+ rv = LockFileEx((HANDLE)f,
LOCKFILE_FAIL_IMMEDIATELY|LOCKFILE_EXCLUSIVE_LOCK,
0,
0x7fffffff,
0,
&me->md.overlapped.overlapped);
if (_native_threads_only) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
if (rv == FALSE) {
err = GetLastError();
@@ -3359,61 +3455,61 @@ _PR_MD_TLOCKFILE(PROsfd f)
return PR_SUCCESS;
}
if ( rv == FALSE && ((err = GetLastError()) != ERROR_IO_PENDING)) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
_PR_MD_MAP_LOCKF_ERROR(err);
return PR_FAILURE;
}
#ifdef _NEED_351_FILE_LOCKING_HACK
else if (rv) {
- /* If this is NT 3.51 and the file is local, then we won't get a
+ /* If this is NT 3.51 and the file is local, then we won't get a
* completion back from LockFile when it succeeded.
*/
if (_nt_version_gets_lockfile_completion == PR_FALSE) {
if ( IsFileLocal((HANDLE)f) == _PR_LOCAL_FILE) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
-
- return PR_SUCCESS;
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ return PR_SUCCESS;
}
}
}
#endif /* _NEED_351_FILE_LOCKING_HACK */
if (_NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
return PR_FAILURE;
}
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
return PR_FAILURE;
}
@@ -3440,11 +3536,12 @@ _PR_MD_UNLOCKFILE(PROsfd f)
0,
&me->md.overlapped.overlapped);
- if (rv)
+ if (rv) {
return PR_SUCCESS;
+ }
else {
int err = GetLastError();
- _PR_MD_MAP_LOCKF_ERROR(err);
+ _PR_MD_MAP_LOCKF_ERROR(err);
return PR_FAILURE;
}
}
@@ -3465,17 +3562,17 @@ _PR_MD_MAKE_NONBLOCK(PRFileDesc *f)
#ifdef _NEED_351_FILE_LOCKING_HACK
/***************
-**
+**
** Lockfile hacks
**
** The following code is a hack to work around a microsoft bug with lockfile.
** The problem is that on NT 3.51, if LockFileEx() succeeds, you never
** get a completion back for files that are on local disks. So, we need to
-** know if a file is local or remote so we can tell if we should expect
+** know if a file is local or remote so we can tell if we should expect
** a completion.
**
** The only way to check if a file is local or remote based on the handle is
-** to get the serial number for the volume it is mounted on and then to
+** to get the serial number for the volume it is mounted on and then to
** compare that with mounted drives. This code caches the volume numbers of
** fixed disks and does a relatively quick check.
**
@@ -3499,222 +3596,228 @@ DWORD dwRemoveableDrivesToCheck = 0; /* bitmask for removeable drives */
PRBool IsFileLocalInit()
{
- TCHAR lpBuffer[_PR_MAX_DRIVES*5];
- DWORD nBufferLength = _PR_MAX_DRIVES*5;
- DWORD nBufferNeeded = GetLogicalDriveStrings(0, NULL);
- DWORD dwIndex = 0;
- DWORD dwDriveType;
- DWORD dwVolumeSerialNumber;
- DWORD dwDriveIndex = 0;
- DWORD oldmode = (DWORD) -1;
-
- _MD_NEW_LOCK(&cachedVolumeLock);
-
- nBufferNeeded = GetLogicalDriveStrings(nBufferLength, lpBuffer);
- if (nBufferNeeded == 0 || nBufferNeeded > nBufferLength)
- return PR_FALSE;
-
- // Calling GetVolumeInformation on a removeable drive where the
- // disk is currently removed will cause a dialog box to the
- // console. This is not good.
- // Temporarily disable the SEM_FAILCRITICALERRORS to avoid the
- // damn dialog.
-
- dwCachedVolumeSerialNumbers[dwDriveIndex] = 0;
- oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
-
- // now loop through the logical drives
- while(lpBuffer[dwIndex] != TEXT('\0'))
- {
- // skip the floppy drives. This is *SLOW*
- if ((lpBuffer[dwIndex] == TEXT('A')) || (lpBuffer[dwIndex] == TEXT('B')))
- /* Skip over floppies */;
- else
- {
- dwDriveIndex = (lpBuffer[dwIndex] - TEXT('A'));
-
- dwDriveType = GetDriveType(&lpBuffer[dwIndex]);
-
- switch(dwDriveType)
- {
- // Ignore these drive types
- case 0:
- case 1:
- case DRIVE_REMOTE:
- default: // If the drive type is unknown, ignore it.
- break;
-
- // Removable media drives can have different serial numbers
- // at different times, so cache the current serial number
- // but keep track of them so they can be rechecked if necessary.
- case DRIVE_REMOVABLE:
-
- // CDROM is a removable media
- case DRIVE_CDROM:
-
- // no idea if ramdisks can change serial numbers or not
- // but it doesn't hurt to treat them as removable.
-
- case DRIVE_RAMDISK:
-
-
- // Here is where we keep track of removable drives.
- dwRemoveableDrivesToCheck |= 1 << dwDriveIndex;
-
- // removable drives fall through to fixed drives and get cached.
-
- case DRIVE_FIXED:
-
- // cache volume serial numbers.
- if (GetVolumeInformation(
- &lpBuffer[dwIndex],
- NULL, 0,
- &dwVolumeSerialNumber,
- NULL, NULL, NULL, 0)
- )
- {
- if (dwLastCachedDrive < dwDriveIndex)
- dwLastCachedDrive = dwDriveIndex;
- dwCachedVolumeSerialNumbers[dwDriveIndex] = dwVolumeSerialNumber;
- }
-
- break;
- }
- }
-
- dwIndex += lstrlen(&lpBuffer[dwIndex]) +1;
- }
-
- if (oldmode != (DWORD) -1) {
- SetErrorMode(oldmode);
- oldmode = (DWORD) -1;
- }
-
- return PR_TRUE;
+ TCHAR lpBuffer[_PR_MAX_DRIVES*5];
+ DWORD nBufferLength = _PR_MAX_DRIVES*5;
+ DWORD nBufferNeeded = GetLogicalDriveStrings(0, NULL);
+ DWORD dwIndex = 0;
+ DWORD dwDriveType;
+ DWORD dwVolumeSerialNumber;
+ DWORD dwDriveIndex = 0;
+ DWORD oldmode = (DWORD) -1;
+
+ _MD_NEW_LOCK(&cachedVolumeLock);
+
+ nBufferNeeded = GetLogicalDriveStrings(nBufferLength, lpBuffer);
+ if (nBufferNeeded == 0 || nBufferNeeded > nBufferLength) {
+ return PR_FALSE;
+ }
+
+ // Calling GetVolumeInformation on a removeable drive where the
+ // disk is currently removed will cause a dialog box to the
+ // console. This is not good.
+ // Temporarily disable the SEM_FAILCRITICALERRORS to avoid the
+ // damn dialog.
+
+ dwCachedVolumeSerialNumbers[dwDriveIndex] = 0;
+ oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
+
+ // now loop through the logical drives
+ while(lpBuffer[dwIndex] != TEXT('\0'))
+ {
+ // skip the floppy drives. This is *SLOW*
+ if ((lpBuffer[dwIndex] == TEXT('A')) || (lpBuffer[dwIndex] == TEXT('B')))
+ /* Skip over floppies */;
+ else
+ {
+ dwDriveIndex = (lpBuffer[dwIndex] - TEXT('A'));
+
+ dwDriveType = GetDriveType(&lpBuffer[dwIndex]);
+
+ switch(dwDriveType)
+ {
+ // Ignore these drive types
+ case 0:
+ case 1:
+ case DRIVE_REMOTE:
+ default: // If the drive type is unknown, ignore it.
+ break;
+
+ // Removable media drives can have different serial numbers
+ // at different times, so cache the current serial number
+ // but keep track of them so they can be rechecked if necessary.
+ case DRIVE_REMOVABLE:
+
+ // CDROM is a removable media
+ case DRIVE_CDROM:
+
+ // no idea if ramdisks can change serial numbers or not
+ // but it doesn't hurt to treat them as removable.
+
+ case DRIVE_RAMDISK:
+
+
+ // Here is where we keep track of removable drives.
+ dwRemoveableDrivesToCheck |= 1 << dwDriveIndex;
+
+ // removable drives fall through to fixed drives and get cached.
+
+ case DRIVE_FIXED:
+
+ // cache volume serial numbers.
+ if (GetVolumeInformation(
+ &lpBuffer[dwIndex],
+ NULL, 0,
+ &dwVolumeSerialNumber,
+ NULL, NULL, NULL, 0)
+ )
+ {
+ if (dwLastCachedDrive < dwDriveIndex) {
+ dwLastCachedDrive = dwDriveIndex;
+ }
+ dwCachedVolumeSerialNumbers[dwDriveIndex] = dwVolumeSerialNumber;
+ }
+
+ break;
+ }
+ }
+
+ dwIndex += lstrlen(&lpBuffer[dwIndex]) +1;
+ }
+
+ if (oldmode != (DWORD) -1) {
+ SetErrorMode(oldmode);
+ oldmode = (DWORD) -1;
+ }
+
+ return PR_TRUE;
}
PRInt32 IsFileLocal(HANDLE hFile)
{
- DWORD dwIndex = 0, dwMask;
- BY_HANDLE_FILE_INFORMATION Info;
- TCHAR szDrive[4] = TEXT("C:\\");
- DWORD dwVolumeSerialNumber;
- DWORD oldmode = (DWORD) -1;
- int rv = _PR_REMOTE_FILE;
-
- if (!GetFileInformationByHandle(hFile, &Info))
- return -1;
-
- // look to see if the volume serial number has been cached.
- _MD_LOCK(&cachedVolumeLock);
- while(dwIndex <= dwLastCachedDrive)
- if (dwCachedVolumeSerialNumbers[dwIndex++] == Info.dwVolumeSerialNumber)
- {
- _MD_UNLOCK(&cachedVolumeLock);
- return _PR_LOCAL_FILE;
- }
- _MD_UNLOCK(&cachedVolumeLock);
-
- // volume serial number not found in the cache. Check removable files.
- // removable drives are noted as a bitmask. If the bit associated with
- // a specific drive is set, then we should query its volume serial number
- // as its possible it has changed.
- dwMask = dwRemoveableDrivesToCheck;
- dwIndex = 0;
-
- while(dwMask)
- {
- while(!(dwMask & 1))
- {
- dwIndex++;
- dwMask = dwMask >> 1;
- }
-
- szDrive[0] = TEXT('A')+ (TCHAR) dwIndex;
-
- // Calling GetVolumeInformation on a removeable drive where the
- // disk is currently removed will cause a dialog box to the
- // console. This is not good.
- // Temporarily disable the SEM_FAILCRITICALERRORS to avoid the
- // dialog.
-
- oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
-
- if (GetVolumeInformation(
- szDrive,
- NULL, 0,
- &dwVolumeSerialNumber,
- NULL, NULL, NULL, 0)
- )
- {
- if (dwVolumeSerialNumber == Info.dwVolumeSerialNumber)
- {
- _MD_LOCK(&cachedVolumeLock);
- if (dwLastCachedDrive < dwIndex)
- dwLastCachedDrive = dwIndex;
- dwCachedVolumeSerialNumbers[dwIndex] = dwVolumeSerialNumber;
+ DWORD dwIndex = 0, dwMask;
+ BY_HANDLE_FILE_INFORMATION Info;
+ TCHAR szDrive[4] = TEXT("C:\\");
+ DWORD dwVolumeSerialNumber;
+ DWORD oldmode = (DWORD) -1;
+ int rv = _PR_REMOTE_FILE;
+
+ if (!GetFileInformationByHandle(hFile, &Info)) {
+ return -1;
+ }
+
+ // look to see if the volume serial number has been cached.
+ _MD_LOCK(&cachedVolumeLock);
+ while(dwIndex <= dwLastCachedDrive)
+ if (dwCachedVolumeSerialNumbers[dwIndex++] == Info.dwVolumeSerialNumber)
+ {
_MD_UNLOCK(&cachedVolumeLock);
- rv = _PR_LOCAL_FILE;
- }
- }
- if (oldmode != (DWORD) -1) {
- SetErrorMode(oldmode);
- oldmode = (DWORD) -1;
- }
-
- if (rv == _PR_LOCAL_FILE)
- return _PR_LOCAL_FILE;
-
- dwIndex++;
- dwMask = dwMask >> 1;
- }
-
- return _PR_REMOTE_FILE;
+ return _PR_LOCAL_FILE;
+ }
+ _MD_UNLOCK(&cachedVolumeLock);
+
+ // volume serial number not found in the cache. Check removable files.
+ // removable drives are noted as a bitmask. If the bit associated with
+ // a specific drive is set, then we should query its volume serial number
+ // as its possible it has changed.
+ dwMask = dwRemoveableDrivesToCheck;
+ dwIndex = 0;
+
+ while(dwMask)
+ {
+ while(!(dwMask & 1))
+ {
+ dwIndex++;
+ dwMask = dwMask >> 1;
+ }
+
+ szDrive[0] = TEXT('A')+ (TCHAR) dwIndex;
+
+ // Calling GetVolumeInformation on a removeable drive where the
+ // disk is currently removed will cause a dialog box to the
+ // console. This is not good.
+ // Temporarily disable the SEM_FAILCRITICALERRORS to avoid the
+ // dialog.
+
+ oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
+
+ if (GetVolumeInformation(
+ szDrive,
+ NULL, 0,
+ &dwVolumeSerialNumber,
+ NULL, NULL, NULL, 0)
+ )
+ {
+ if (dwVolumeSerialNumber == Info.dwVolumeSerialNumber)
+ {
+ _MD_LOCK(&cachedVolumeLock);
+ if (dwLastCachedDrive < dwIndex) {
+ dwLastCachedDrive = dwIndex;
+ }
+ dwCachedVolumeSerialNumbers[dwIndex] = dwVolumeSerialNumber;
+ _MD_UNLOCK(&cachedVolumeLock);
+ rv = _PR_LOCAL_FILE;
+ }
+ }
+ if (oldmode != (DWORD) -1) {
+ SetErrorMode(oldmode);
+ oldmode = (DWORD) -1;
+ }
+
+ if (rv == _PR_LOCAL_FILE) {
+ return _PR_LOCAL_FILE;
+ }
+
+ dwIndex++;
+ dwMask = dwMask >> 1;
+ }
+
+ return _PR_REMOTE_FILE;
}
#endif /* _NEED_351_FILE_LOCKING_HACK */
PR_IMPLEMENT(PRStatus) PR_NT_CancelIo(PRFileDesc *fd)
{
PRThread *me = _PR_MD_CURRENT_THREAD();
- PRBool fWait;
- PRFileDesc *bottom;
+ PRBool fWait;
+ PRFileDesc *bottom;
- bottom = PR_GetIdentitiesLayer(fd, PR_NSPR_IO_LAYER);
+ bottom = PR_GetIdentitiesLayer(fd, PR_NSPR_IO_LAYER);
if (!me->io_suspended || (NULL == bottom) ||
- (me->io_fd != bottom->secret->md.osfd)) {
+ (me->io_fd != bottom->secret->md.osfd)) {
PR_SetError(PR_INVALID_STATE_ERROR, 0);
return PR_FAILURE;
}
- /*
- * The CancelIO operation has to be issued by the same NT thread that
- * issued the I/O operation
- */
- PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || (me->cpu == me->md.thr_bound_cpu));
- if (me->io_pending) {
- if (!CancelIo((HANDLE)bottom->secret->md.osfd)) {
- PR_SetError(PR_INVALID_STATE_ERROR, GetLastError());
- return PR_FAILURE;
- }
- }
- _PR_THREAD_LOCK(me);
- fWait = me->io_pending;
- me->io_suspended = PR_FALSE;
- me->state = _PR_IO_WAIT;
- me->md.interrupt_disabled = PR_TRUE;
- _PR_THREAD_UNLOCK(me);
- if (fWait)
- _NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
- PR_ASSERT(me->io_suspended == PR_FALSE);
- PR_ASSERT(me->io_pending == PR_FALSE);
-
- _PR_THREAD_LOCK(me);
- me->md.interrupt_disabled = PR_FALSE;
- me->md.thr_bound_cpu = NULL;
+ /*
+ * The CancelIO operation has to be issued by the same NT thread that
+ * issued the I/O operation
+ */
+ PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || (me->cpu == me->md.thr_bound_cpu));
+ if (me->io_pending) {
+ if (!CancelIo((HANDLE)bottom->secret->md.osfd)) {
+ PR_SetError(PR_INVALID_STATE_ERROR, GetLastError());
+ return PR_FAILURE;
+ }
+ }
+ _PR_THREAD_LOCK(me);
+ fWait = me->io_pending;
+ me->io_suspended = PR_FALSE;
+ me->state = _PR_IO_WAIT;
+ me->md.interrupt_disabled = PR_TRUE;
+ _PR_THREAD_UNLOCK(me);
+ if (fWait) {
+ _NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
+ }
+ PR_ASSERT(me->io_suspended == PR_FALSE);
+ PR_ASSERT(me->io_pending == PR_FALSE);
+
+ _PR_THREAD_LOCK(me);
+ me->md.interrupt_disabled = PR_FALSE;
+ me->md.thr_bound_cpu = NULL;
me->io_suspended = PR_FALSE;
me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(me);
- return PR_SUCCESS;
+ me->state = _PR_RUNNING;
+ _PR_THREAD_UNLOCK(me);
+ return PR_SUCCESS;
}
static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *addrlen, PRIntervalTime timeout)
@@ -3730,9 +3833,9 @@ static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *ad
if (timeout == PR_INTERVAL_NO_TIMEOUT) {
while ((sock = accept(osfd, addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
if ((rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL,
- NULL)) == -1) {
+ NULL)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
break;
}
@@ -3744,7 +3847,7 @@ static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *ad
} else if (timeout == PR_INTERVAL_NO_WAIT) {
if ((sock = accept(osfd, addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
} else {
_PR_MD_MAP_ACCEPT_ERROR(err);
@@ -3754,10 +3857,10 @@ static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *ad
retry:
if ((sock = accept(osfd, addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL, tvp);
@@ -3792,7 +3895,7 @@ static PRInt32 _nt_nonblock_connect(PRFileDesc *fd, struct sockaddr *addr, int a
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wr);
@@ -3800,7 +3903,7 @@ static PRInt32 _nt_nonblock_connect(PRFileDesc *fd, struct sockaddr *addr, int a
FD_SET((SOCKET)osfd, &wr);
FD_SET((SOCKET)osfd, &ex);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wr, &ex,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return rv;
}
@@ -3813,13 +3916,13 @@ static PRInt32 _nt_nonblock_connect(PRFileDesc *fd, struct sockaddr *addr, int a
if (FD_ISSET((SOCKET)osfd, &ex)) {
len = sizeof(err);
if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &len) == SOCKET_ERROR) {
+ (char *) &err, &len) == SOCKET_ERROR) {
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return -1;
}
_PR_MD_MAP_CONNECT_ERROR(err);
return -1;
- }
+ }
PR_ASSERT(FD_ISSET((SOCKET)osfd, &wr));
rv = 0;
} else {
@@ -3845,7 +3948,7 @@ static PRInt32 _nt_nonblock_recv(PRFileDesc *fd, char *buf, int len, int flags,
}
while ((rv = recv(osfd,buf,len,osflags)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
FD_ZERO(&rd);
FD_SET((SOCKET)osfd, &rd);
if (timeout == PR_INTERVAL_NO_TIMEOUT) {
@@ -3853,11 +3956,11 @@ static PRInt32 _nt_nonblock_recv(PRFileDesc *fd, char *buf, int len, int flags,
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
if ((rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
break;
} else if (rv == 0) {
@@ -3884,19 +3987,19 @@ static PRInt32 _nt_nonblock_send(PRFileDesc *fd, char *buf, int len, PRIntervalT
while(bytesSent < len) {
while ((rv = send(osfd,buf,len,0)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
if ( timeout == PR_INTERVAL_NO_TIMEOUT ) {
tvp = NULL;
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET((SOCKET)osfd, &wd);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return -1;
}
@@ -3919,13 +4022,13 @@ static PRInt32 _nt_nonblock_send(PRFileDesc *fd, char *buf, int len, PRIntervalT
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET((SOCKET)osfd, &wd);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return -1;
}
@@ -3946,13 +4049,14 @@ static PRInt32 _nt_nonblock_writev(PRFileDesc *fd, const PRIOVec *iov, int size,
for (index=0; index<size; index++) {
rv = _nt_nonblock_send(fd, iov[index].iov_base, iov[index].iov_len, timeout);
- if (rv > 0)
+ if (rv > 0) {
sent += rv;
+ }
if ( rv != iov[index].iov_len ) {
if (rv < 0) {
if (fd->secret->nonblocking
- && (PR_GetError() == PR_WOULD_BLOCK_ERROR)
- && (sent > 0)) {
+ && (PR_GetError() == PR_WOULD_BLOCK_ERROR)
+ && (sent > 0)) {
return sent;
} else {
return -1;
@@ -3980,19 +4084,19 @@ static PRInt32 _nt_nonblock_sendto(
while(bytesSent < len) {
while ((rv = sendto(osfd,buf,len,0, addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
if ( timeout == PR_INTERVAL_NO_TIMEOUT ) {
tvp = NULL;
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET((SOCKET)osfd, &wd);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return -1;
}
@@ -4015,13 +4119,13 @@ static PRInt32 _nt_nonblock_sendto(
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET((SOCKET)osfd, &wd);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return -1;
}
@@ -4043,19 +4147,19 @@ static PRInt32 _nt_nonblock_recvfrom(PRFileDesc *fd, char *buf, int len, struct
while ((rv = recvfrom(osfd,buf,len,0,addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
if (timeout == PR_INTERVAL_NO_TIMEOUT) {
tvp = NULL;
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&rd);
FD_SET((SOCKET)osfd, &rd);
if ((rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
break;
} else if (rv == 0) {
@@ -4110,7 +4214,7 @@ static void pt_InsertTimedInternal(pt_Continuation *op)
* Subsequently earlier timeouts are computed based on the latter
* knowledge by subracting the timeout deltas that are stored in
* the operation list. There are operation[n]->timeout ticks
- * between the expiration of operation[n-1] and operation[n].e e
+ * between the expiration of operation[n-1] and operation[n].e e
*
* Therefore, the operation[n-1] will expire operation[n]->timeout
* ticks prior to operation[n].
@@ -4145,7 +4249,9 @@ static void pt_InsertTimedInternal(pt_Continuation *op)
qd_tmo -= t_op->timeout; /* previous operaton expiration */
t_op = t_op->prev; /* point to previous operation */
- if (NULL != t_op) qd_tmo += t_op->timeout;
+ if (NULL != t_op) {
+ qd_tmo += t_op->timeout;
+ }
} while (NULL != t_op);
/*
@@ -4170,19 +4276,26 @@ done:
op->prev = NULL;
op->next = pt_tq.head;
pt_tq.head = op;
- if (NULL == pt_tq.tail) pt_tq.tail = op;
- else op->next->prev = op;
+ if (NULL == pt_tq.tail) {
+ pt_tq.tail = op;
+ }
+ else {
+ op->next->prev = op;
+ }
}
else
{
op->prev = t_op;
op->next = t_op->next;
- if (NULL != op->prev)
+ if (NULL != op->prev) {
op->prev->next = op;
- if (NULL != op->next)
+ }
+ if (NULL != op->next) {
op->next->prev = op;
- if (t_op == pt_tq.tail)
+ }
+ if (t_op == pt_tq.tail) {
pt_tq.tail = op;
+ }
}
/*
@@ -4193,7 +4306,7 @@ done:
if (PR_INTERVAL_NO_TIMEOUT != op->timeout)
{
if ((NULL == pt_tq.op) /* we're the one and only */
- || (t_op == pt_tq.op)) /* we're replacing */
+ || (t_op == pt_tq.op)) /* we're replacing */
{
pt_tq.op = op;
pt_tq.epoch = now;
@@ -4217,13 +4330,23 @@ static pt_Continuation *pt_FinishTimedInternal(pt_Continuation *op)
pt_Continuation *next;
/* remove this one from the list */
- if (NULL == op->prev) pt_tq.head = op->next;
- else op->prev->next = op->next;
- if (NULL == op->next) pt_tq.tail = op->prev;
- else op->next->prev = op->prev;
+ if (NULL == op->prev) {
+ pt_tq.head = op->next;
+ }
+ else {
+ op->prev->next = op->next;
+ }
+ if (NULL == op->next) {
+ pt_tq.tail = op->prev;
+ }
+ else {
+ op->next->prev = op->prev;
+ }
/* did we happen to hit the timed op? */
- if (op == pt_tq.op) pt_tq.op = op->prev;
+ if (op == pt_tq.op) {
+ pt_tq.op = op->prev;
+ }
next = op->next;
op->next = op->prev = NULL;
@@ -4264,20 +4387,24 @@ static void ContinuationThread(void *arg)
{
status = PR_WaitCondVar(pt_tq.new_op, PR_INTERVAL_NO_TIMEOUT);
if ((PR_FAILURE == status)
- && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) break;
+ && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ break;
+ }
}
pollingListNeeded = pt_tq.op_count;
PR_Unlock(pt_tq.ml);
/* Okay. We're history */
if ((PR_FAILURE == status)
- && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) break;
+ && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ break;
+ }
- /*
- * We are not holding the pt_tq.ml lock now, so more items may
- * get added to pt_tq during this window of time. We hope
- * that 10 more spaces in the polling list should be enough.
- */
+ /*
+ * We are not holding the pt_tq.ml lock now, so more items may
+ * get added to pt_tq during this window of time. We hope
+ * that 10 more spaces in the polling list should be enough.
+ */
FD_ZERO(&readSet);
FD_ZERO(&writeSet);
@@ -4285,15 +4412,18 @@ static void ContinuationThread(void *arg)
pollingListNeeded += 10;
if (pollingListNeeded > pollingSlotsAllocated)
{
- if (NULL != pollingList) PR_DELETE(pollingList);
+ if (NULL != pollingList) {
+ PR_DELETE(pollingList);
+ }
pollingList = PR_MALLOC(pollingListNeeded * sizeof(PRPollDesc));
PR_ASSERT(NULL != pollingList);
pollingSlotsAllocated = pollingListNeeded;
}
#if defined(DEBUG)
- if (pollingListNeeded > pt_debug.pollingListMax)
+ if (pollingListNeeded > pt_debug.pollingListMax) {
pt_debug.pollingListMax = pollingListUsed;
+ }
#endif
/*
@@ -4328,7 +4458,9 @@ static void ContinuationThread(void *arg)
}
pollingList[pollingListUsed] = op->arg1.osfd;
pollingListUsed += 1;
- if (pollingListUsed == pollingSlotsAllocated) break;
+ if (pollingListUsed == pollingSlotsAllocated) {
+ break;
+ }
op = op->next;
}
}
@@ -4351,7 +4483,9 @@ static void ContinuationThread(void *arg)
}
/* there's a chance that all ops got blown away */
- if (NULL == pt_tq.head) continue;
+ if (NULL == pt_tq.head) {
+ continue;
+ }
/* if not, we know this is the shortest timeout */
timeout = pt_tq.head->timeout;
@@ -4362,10 +4496,13 @@ static void ContinuationThread(void *arg)
* should persist forever. But they may be aborted. That's
* what this anxiety is all about.
*/
- if (timeout > mx_select_ticks) timeout = mx_select_ticks;
+ if (timeout > mx_select_ticks) {
+ timeout = mx_select_ticks;
+ }
- if (PR_INTERVAL_NO_TIMEOUT != pt_tq.head->timeout)
+ if (PR_INTERVAL_NO_TIMEOUT != pt_tq.head->timeout) {
pt_tq.head->timeout -= timeout;
+ }
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(timeout) % PR_USEC_PER_SEC;
@@ -4375,7 +4512,7 @@ static void ContinuationThread(void *arg)
{
if (0 == pt_tq.head->timeout)
{
- /*
+ /*
* The leading element of the timed queue has timed
* out. Get rid of it. In any case go around the
* loop again, computing the polling list, checking
@@ -4394,7 +4531,7 @@ static void ContinuationThread(void *arg)
}
if (-1 == rv && (WSAGetLastError() == WSAEINTR
- || WSAGetLastError() == WSAEINPROGRESS))
+ || WSAGetLastError() == WSAEINPROGRESS))
{
continue; /* go around the loop again */
}
@@ -4463,7 +4600,9 @@ static void ContinuationThread(void *arg)
}
}
}
- if (NULL != pollingList) PR_DELETE(pollingList);
+ if (NULL != pollingList) {
+ PR_DELETE(pollingList);
+ }
} /* ContinuationThread */
static int pt_Continue(pt_Continuation *op)
@@ -4493,8 +4632,9 @@ static int pt_Continue(pt_Continuation *op)
* anyhow and should notice the request in there.
*/
if ((PR_FAILURE == rv)
- && (PR_PENDING_INTERRUPT_ERROR == PR_GetError()))
- op->status = pt_continuation_abort; /* our status */
+ && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ op->status = pt_continuation_abort; /* our status */
+ }
}
PR_Unlock(pt_tq.ml); /* we provide the locking */
@@ -4507,8 +4647,8 @@ static int pt_Continue(pt_Continuation *op)
static PRBool pt_sendto_cont(pt_Continuation *op, PRInt16 revents)
{
PRIntn bytes = sendto(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags,
- (struct sockaddr*)op->arg5.addr, sizeof(*(op->arg5.addr)));
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags,
+ (struct sockaddr*)op->arg5.addr, sizeof(*(op->arg5.addr)));
op->syserrno = WSAGetLastError();
if (bytes > 0) /* this is progress */
{
@@ -4520,18 +4660,18 @@ static PRBool pt_sendto_cont(pt_Continuation *op, PRInt16 revents)
return (0 == op->arg3.amount) ? PR_TRUE : PR_FALSE;
}
else return ((-1 == bytes) && (WSAEWOULDBLOCK == op->syserrno)) ?
- PR_FALSE : PR_TRUE;
+ PR_FALSE : PR_TRUE;
} /* pt_sendto_cont */
static PRBool pt_recvfrom_cont(pt_Continuation *op, PRInt16 revents)
{
PRIntn addr_len = sizeof(*(op->arg5.addr));
op->result.code = recvfrom(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount,
- op->arg4.flags, (struct sockaddr*)op->arg5.addr, &addr_len);
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount,
+ op->arg4.flags, (struct sockaddr*)op->arg5.addr, &addr_len);
op->syserrno = WSAGetLastError();
return ((-1 == op->result.code) && (WSAEWOULDBLOCK == op->syserrno)) ?
- PR_FALSE : PR_TRUE;
+ PR_FALSE : PR_TRUE;
} /* pt_recvfrom_cont */
static PRInt32 pt_SendTo(
@@ -4543,13 +4683,15 @@ static PRInt32 pt_SendTo(
PRBool fNeedContinue = PR_FALSE;
bytes = sendto(
- osfd, buf, amount, flags,
- (struct sockaddr*)addr, PR_NETADDR_SIZE(addr));
+ osfd, buf, amount, flags,
+ (struct sockaddr*)addr, PR_NETADDR_SIZE(addr));
if (bytes == -1) {
- if ((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- fNeedContinue = PR_TRUE;
- else
- _PR_MD_MAP_SENDTO_ERROR(err);
+ if ((err = WSAGetLastError()) == WSAEWOULDBLOCK) {
+ fNeedContinue = PR_TRUE;
+ }
+ else {
+ _PR_MD_MAP_SENDTO_ERROR(err);
+ }
}
if (fNeedContinue == PR_TRUE)
{
@@ -4566,26 +4708,28 @@ static PRInt32 pt_SendTo(
bytes = pt_Continue(&op);
if (bytes < 0) {
WSASetLastError(op.syserrno);
- _PR_MD_MAP_SENDTO_ERROR(op.syserrno);
+ _PR_MD_MAP_SENDTO_ERROR(op.syserrno);
}
}
return bytes;
} /* pt_SendTo */
static PRInt32 pt_RecvFrom(SOCKET osfd, void *buf, PRInt32 amount,
- PRInt32 flags, PRNetAddr *addr, PRIntn *addr_len, PRIntervalTime timeout)
+ PRInt32 flags, PRNetAddr *addr, PRIntn *addr_len, PRIntervalTime timeout)
{
PRInt32 bytes = -1, err;
PRBool fNeedContinue = PR_FALSE;
bytes = recvfrom(
- osfd, buf, amount, flags,
- (struct sockaddr*)addr, addr_len);
+ osfd, buf, amount, flags,
+ (struct sockaddr*)addr, addr_len);
if (bytes == -1) {
- if ((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- fNeedContinue = PR_TRUE;
- else
- _PR_MD_MAP_RECVFROM_ERROR(err);
+ if ((err = WSAGetLastError()) == WSAEWOULDBLOCK) {
+ fNeedContinue = PR_TRUE;
+ }
+ else {
+ _PR_MD_MAP_RECVFROM_ERROR(err);
+ }
}
if (fNeedContinue == PR_TRUE)
@@ -4602,7 +4746,7 @@ static PRInt32 pt_RecvFrom(SOCKET osfd, void *buf, PRInt32 amount,
bytes = pt_Continue(&op);
if (bytes < 0) {
WSASetLastError(op.syserrno);
- _PR_MD_MAP_RECVFROM_ERROR(op.syserrno);
+ _PR_MD_MAP_RECVFROM_ERROR(op.syserrno);
}
}
return bytes;
diff --git a/nsprpub/pr/src/md/windows/ntmisc.c b/nsprpub/pr/src/md/windows/ntmisc.c
index 12f8c1df7..1ec6c2a5e 100644
--- a/nsprpub/pr/src/md/windows/ntmisc.c
+++ b/nsprpub/pr/src/md/windows/ntmisc.c
@@ -88,43 +88,43 @@ NowCalibrate(void)
LARGE_INTEGER liFreq, now;
if (calibration.freq == 0.0) {
- if(!QueryPerformanceFrequency(&liFreq)) {
- /* High-performance timer is unavailable */
- calibration.freq = -1.0;
- } else {
- calibration.freq = (long double) liFreq.QuadPart;
- }
+ if(!QueryPerformanceFrequency(&liFreq)) {
+ /* High-performance timer is unavailable */
+ calibration.freq = -1.0;
+ } else {
+ calibration.freq = (long double) liFreq.QuadPart;
+ }
}
if (calibration.freq > 0.0) {
- PRInt64 calibrationDelta = 0;
- /*
- * By wrapping a timeBegin/EndPeriod pair of calls around this loop,
- * the loop seems to take much less time (1 ms vs 15ms) on Vista.
- */
- timeBeginPeriod(1);
- LowResTime(&ftStart);
- do {
- LowResTime(&ft);
- } while (memcmp(&ftStart,&ft, sizeof(ft)) == 0);
- timeEndPeriod(1);
-
- calibration.granularity =
- (FILETIME_TO_INT64(ft) - FILETIME_TO_INT64(ftStart))/10;
-
- QueryPerformanceCounter(&now);
-
- calibration.offset = (long double) FILETIME_TO_INT64(ft);
- calibration.timer_offset = (long double) now.QuadPart;
- /*
- * The windows epoch is around 1600. The unix epoch is around 1970.
- * _pr_filetime_offset is the difference (in windows time units which
- * are 10 times more highres than the JS time unit)
- */
- calibration.offset -= _pr_filetime_offset;
- calibration.offset *= 0.1;
- calibration.last = 0;
-
- calibration.calibrated = PR_TRUE;
+ PRInt64 calibrationDelta = 0;
+ /*
+ * By wrapping a timeBegin/EndPeriod pair of calls around this loop,
+ * the loop seems to take much less time (1 ms vs 15ms) on Vista.
+ */
+ timeBeginPeriod(1);
+ LowResTime(&ftStart);
+ do {
+ LowResTime(&ft);
+ } while (memcmp(&ftStart,&ft, sizeof(ft)) == 0);
+ timeEndPeriod(1);
+
+ calibration.granularity =
+ (FILETIME_TO_INT64(ft) - FILETIME_TO_INT64(ftStart))/10;
+
+ QueryPerformanceCounter(&now);
+
+ calibration.offset = (long double) FILETIME_TO_INT64(ft);
+ calibration.timer_offset = (long double) now.QuadPart;
+ /*
+ * The windows epoch is around 1600. The unix epoch is around 1970.
+ * _pr_filetime_offset is the difference (in windows time units which
+ * are 10 times more highres than the JS time unit)
+ */
+ calibration.offset -= _pr_filetime_offset;
+ calibration.offset *= 0.1;
+ calibration.last = 0;
+
+ calibration.calibrated = PR_TRUE;
}
}
@@ -138,7 +138,7 @@ _MD_InitTime(void)
/* try for CE6 GetSystemTimeAsFileTime first */
HANDLE h = GetModuleHandleW(L"coredll.dll");
ce6_GetSystemTimeAsFileTime = (GetSystemTimeAsFileTimeFcn)
- GetProcAddressA(h, "GetSystemTimeAsFileTime");
+ GetProcAddressA(h, "GetSystemTimeAsFileTime");
/* otherwise go the slow route */
if (ce6_GetSystemTimeAsFileTime == NULL) {
@@ -199,113 +199,113 @@ PR_Now(void)
* a constant, and the entire expression is faster to execute.
*/
return currentTime.prt/_pr_filetime_divisor -
- _pr_filetime_offset/_pr_filetime_divisor;
+ _pr_filetime_offset/_pr_filetime_divisor;
}
do {
- if (!calibration.calibrated || needsCalibration) {
- EnterCriticalSection(&calibration.calibration_lock);
- EnterCriticalSection(&calibration.data_lock);
-
- /* Recalibrate only if no one else did before us */
- if (calibration.offset == cachedOffset) {
- /*
- * Since calibration can take a while, make any other
- * threads immediately wait
- */
- MUTEX_SETSPINCOUNT(&calibration.data_lock, 0);
-
- NowCalibrate();
-
- calibrated = PR_TRUE;
-
- /* Restore spin count */
- MUTEX_SETSPINCOUNT(&calibration.data_lock, DATALOCK_SPINCOUNT);
- }
- LeaveCriticalSection(&calibration.data_lock);
- LeaveCriticalSection(&calibration.calibration_lock);
- }
-
- /* Calculate a low resolution time */
- LowResTime(&ft);
- lowresTime =
+ if (!calibration.calibrated || needsCalibration) {
+ EnterCriticalSection(&calibration.calibration_lock);
+ EnterCriticalSection(&calibration.data_lock);
+
+ /* Recalibrate only if no one else did before us */
+ if (calibration.offset == cachedOffset) {
+ /*
+ * Since calibration can take a while, make any other
+ * threads immediately wait
+ */
+ MUTEX_SETSPINCOUNT(&calibration.data_lock, 0);
+
+ NowCalibrate();
+
+ calibrated = PR_TRUE;
+
+ /* Restore spin count */
+ MUTEX_SETSPINCOUNT(&calibration.data_lock, DATALOCK_SPINCOUNT);
+ }
+ LeaveCriticalSection(&calibration.data_lock);
+ LeaveCriticalSection(&calibration.calibration_lock);
+ }
+
+ /* Calculate a low resolution time */
+ LowResTime(&ft);
+ lowresTime =
((long double)(FILETIME_TO_INT64(ft) - _pr_filetime_offset)) * 0.1;
- if (calibration.freq > 0.0) {
- long double highresTime, diff;
- DWORD timeAdjustment, timeIncrement;
- BOOL timeAdjustmentDisabled;
-
- /* Default to 15.625 ms if the syscall fails */
- long double skewThreshold = 15625.25;
-
- /* Grab high resolution time */
- QueryPerformanceCounter(&now);
- highresTimerValue = (long double)now.QuadPart;
-
- EnterCriticalSection(&calibration.data_lock);
- highresTime = calibration.offset + 1000000L *
- (highresTimerValue-calibration.timer_offset)/calibration.freq;
- cachedOffset = calibration.offset;
-
- /*
- * On some dual processor/core systems, we might get an earlier
- * time so we cache the last time that we returned.
- */
- calibration.last = PR_MAX(calibration.last,(PRInt64)highresTime);
- returnedTime = calibration.last;
- LeaveCriticalSection(&calibration.data_lock);
-
- /* Get an estimate of clock ticks per second from our own test */
- skewThreshold = calibration.granularity;
- /* Check for clock skew */
- diff = lowresTime - highresTime;
-
- /*
- * For some reason that I have not determined, the skew can be
- * up to twice a kernel tick. This does not seem to happen by
- * itself, but I have only seen it triggered by another program
- * doing some kind of file I/O. The symptoms are a negative diff
- * followed by an equally large positive diff.
- */
- if (fabs(diff) > 2*skewThreshold) {
- if (calibrated) {
- /*
- * If we already calibrated once this instance, and the
- * clock is still skewed, then either the processor(s) are
- * wildly changing clockspeed or the system is so busy that
- * we get switched out for long periods of time. In either
- * case, it would be infeasible to make use of high
- * resolution results for anything, so let's resort to old
- * behavior for this call. It's possible that in the
- * future, the user will want the high resolution timer, so
- * we don't disable it entirely.
- */
- returnedTime = (PRInt64)lowresTime;
- needsCalibration = PR_FALSE;
- } else {
- /*
- * It is possible that when we recalibrate, we will return
- * a value less than what we have returned before; this is
- * unavoidable. We cannot tell the different between a
- * faulty QueryPerformanceCounter implementation and user
- * changes to the operating system time. Since we must
- * respect user changes to the operating system time, we
- * cannot maintain the invariant that Date.now() never
- * decreases; the old implementation has this behavior as
- * well.
- */
- needsCalibration = PR_TRUE;
- }
- } else {
- /* No detectable clock skew */
- returnedTime = (PRInt64)highresTime;
- needsCalibration = PR_FALSE;
- }
- } else {
- /* No high resolution timer is available, so fall back */
- returnedTime = (PRInt64)lowresTime;
- }
+ if (calibration.freq > 0.0) {
+ long double highresTime, diff;
+ DWORD timeAdjustment, timeIncrement;
+ BOOL timeAdjustmentDisabled;
+
+ /* Default to 15.625 ms if the syscall fails */
+ long double skewThreshold = 15625.25;
+
+ /* Grab high resolution time */
+ QueryPerformanceCounter(&now);
+ highresTimerValue = (long double)now.QuadPart;
+
+ EnterCriticalSection(&calibration.data_lock);
+ highresTime = calibration.offset + 1000000L *
+ (highresTimerValue-calibration.timer_offset)/calibration.freq;
+ cachedOffset = calibration.offset;
+
+ /*
+ * On some dual processor/core systems, we might get an earlier
+ * time so we cache the last time that we returned.
+ */
+ calibration.last = PR_MAX(calibration.last,(PRInt64)highresTime);
+ returnedTime = calibration.last;
+ LeaveCriticalSection(&calibration.data_lock);
+
+ /* Get an estimate of clock ticks per second from our own test */
+ skewThreshold = calibration.granularity;
+ /* Check for clock skew */
+ diff = lowresTime - highresTime;
+
+ /*
+ * For some reason that I have not determined, the skew can be
+ * up to twice a kernel tick. This does not seem to happen by
+ * itself, but I have only seen it triggered by another program
+ * doing some kind of file I/O. The symptoms are a negative diff
+ * followed by an equally large positive diff.
+ */
+ if (fabs(diff) > 2*skewThreshold) {
+ if (calibrated) {
+ /*
+ * If we already calibrated once this instance, and the
+ * clock is still skewed, then either the processor(s) are
+ * wildly changing clockspeed or the system is so busy that
+ * we get switched out for long periods of time. In either
+ * case, it would be infeasible to make use of high
+ * resolution results for anything, so let's resort to old
+ * behavior for this call. It's possible that in the
+ * future, the user will want the high resolution timer, so
+ * we don't disable it entirely.
+ */
+ returnedTime = (PRInt64)lowresTime;
+ needsCalibration = PR_FALSE;
+ } else {
+ /*
+ * It is possible that when we recalibrate, we will return
+ * a value less than what we have returned before; this is
+ * unavoidable. We cannot tell the different between a
+ * faulty QueryPerformanceCounter implementation and user
+ * changes to the operating system time. Since we must
+ * respect user changes to the operating system time, we
+ * cannot maintain the invariant that Date.now() never
+ * decreases; the old implementation has this behavior as
+ * well.
+ */
+ needsCalibration = PR_TRUE;
+ }
+ } else {
+ /* No detectable clock skew */
+ returnedTime = (PRInt64)highresTime;
+ needsCalibration = PR_FALSE;
+ }
+ } else {
+ /* No high resolution timer is available, so fall back */
+ returnedTime = (PRInt64)lowresTime;
+ }
} while (needsCalibration);
return returnedTime;
@@ -323,7 +323,7 @@ PR_Now(void)
GetSystemTime(&st);
SystemTimeToFileTime(&st, &ft);
_PR_FileTimeToPRTime(&ft, &prt);
- return prt;
+ return prt;
}
#endif
@@ -365,8 +365,8 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
* a null byte at the end of command line.
*/
cmdLineSize += 2 * strlen(*arg) /* \ and " need to be escaped */
- + 2 /* we quote every argument */
- + 1; /* space in between, or final null */
+ + 2 /* we quote every argument */
+ + 1; /* space in between, or final null */
}
p = *cmdLine = PR_MALLOC((PRUint32) cmdLineSize);
if (p == NULL) {
@@ -376,7 +376,7 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
for (arg = argv; *arg; arg++) {
/* Add a space to separates the arguments */
if (arg != argv) {
- *p++ = ' ';
+ *p++ = ' ';
}
q = *arg;
numBackslashes = 0;
@@ -442,7 +442,7 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
if (argNeedQuotes) {
*p++ = '"';
}
- }
+ }
*p = '\0';
return 0;
@@ -488,7 +488,7 @@ static int assembleEnvBlock(char **envp, char **envBlock)
cwdStart = curEnv;
while (*cwdStart) {
if (cwdStart[0] == '=' && cwdStart[1] != '\0'
- && cwdStart[2] == ':' && cwdStart[3] == '=') {
+ && cwdStart[2] == ':' && cwdStart[3] == '=') {
break;
}
cwdStart += strlen(cwdStart) + 1;
@@ -498,7 +498,7 @@ static int assembleEnvBlock(char **envp, char **envBlock)
cwdEnd += strlen(cwdEnd) + 1;
while (*cwdEnd) {
if (cwdEnd[0] != '=' || cwdEnd[1] == '\0'
- || cwdEnd[2] != ':' || cwdEnd[3] != '=') {
+ || cwdEnd[2] != ':' || cwdEnd[3] != '=') {
break;
}
cwdEnd += strlen(cwdEnd) + 1;
@@ -609,7 +609,7 @@ PRProcess * _PR_CreateWindowsProcess(
for (idx = 0; idx < numEnv; idx++) {
newEnvp[idx] = envp[idx];
if (hasFdInheritBuffer && !found
- && !strncmp(newEnvp[idx], "NSPR_INHERIT_FDS=", 17)) {
+ && !strncmp(newEnvp[idx], "NSPR_INHERIT_FDS=", 17)) {
newEnvp[idx] = attr->fdInheritBuffer;
found = PR_TRUE;
}
@@ -759,7 +759,7 @@ PRStatus _PR_DetachWindowsProcess(PRProcess *process)
* It can be called by native threads only (not by fibers).
*/
PRStatus _PR_WaitWindowsProcess(PRProcess *process,
- PRInt32 *exitCode)
+ PRInt32 *exitCode)
{
DWORD dwRetVal;
@@ -770,7 +770,7 @@ PRStatus _PR_WaitWindowsProcess(PRProcess *process,
}
PR_ASSERT(dwRetVal == WAIT_OBJECT_0);
if (exitCode != NULL &&
- GetExitCodeProcess(process->md.handle, exitCode) == FALSE) {
+ GetExitCodeProcess(process->md.handle, exitCode) == FALSE) {
PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
return PR_FAILURE;
}
@@ -787,7 +787,7 @@ PRStatus _PR_KillWindowsProcess(PRProcess *process)
* 256 to indicate that the process is killed.
*/
if (TerminateProcess(process->md.handle, 256)) {
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
return PR_FAILURE;
@@ -804,86 +804,92 @@ PRStatus _MD_WindowsGetHostName(char *name, PRUint32 namelen)
}
syserror = WSAGetLastError();
PR_ASSERT(WSANOTINITIALISED != syserror);
- _PR_MD_MAP_GETHOSTNAME_ERROR(syserror);
+ _PR_MD_MAP_GETHOSTNAME_ERROR(syserror);
return PR_FAILURE;
}
PRStatus _MD_WindowsGetSysInfo(PRSysInfo cmd, char *name, PRUint32 namelen)
{
- OSVERSIONINFO osvi;
-
- PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE));
-
- ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
- if (! GetVersionEx (&osvi) ) {
- _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
- return PR_FAILURE;
- }
-
- switch (osvi.dwPlatformId) {
- case VER_PLATFORM_WIN32_NT:
- if (PR_SI_SYSNAME == cmd)
- (void)PR_snprintf(name, namelen, "Windows_NT");
- else if (PR_SI_RELEASE == cmd)
- (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
- osvi.dwMinorVersion);
- break;
- case VER_PLATFORM_WIN32_WINDOWS:
- if (PR_SI_SYSNAME == cmd) {
- if ((osvi.dwMajorVersion > 4) ||
- ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0)))
- (void)PR_snprintf(name, namelen, "Windows_98");
- else
- (void)PR_snprintf(name, namelen, "Windows_95");
- } else if (PR_SI_RELEASE == cmd) {
- (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
- osvi.dwMinorVersion);
- }
- break;
+ OSVERSIONINFO osvi;
+
+ PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE));
+
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ if (! GetVersionEx (&osvi) ) {
+ _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+ return PR_FAILURE;
+ }
+
+ switch (osvi.dwPlatformId) {
+ case VER_PLATFORM_WIN32_NT:
+ if (PR_SI_SYSNAME == cmd) {
+ (void)PR_snprintf(name, namelen, "Windows_NT");
+ }
+ else if (PR_SI_RELEASE == cmd)
+ (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
+ osvi.dwMinorVersion);
+ break;
+ case VER_PLATFORM_WIN32_WINDOWS:
+ if (PR_SI_SYSNAME == cmd) {
+ if ((osvi.dwMajorVersion > 4) ||
+ ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0))) {
+ (void)PR_snprintf(name, namelen, "Windows_98");
+ }
+ else {
+ (void)PR_snprintf(name, namelen, "Windows_95");
+ }
+ } else if (PR_SI_RELEASE == cmd) {
+ (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
+ osvi.dwMinorVersion);
+ }
+ break;
#ifdef VER_PLATFORM_WIN32_CE
- case VER_PLATFORM_WIN32_CE:
- if (PR_SI_SYSNAME == cmd)
- (void)PR_snprintf(name, namelen, "Windows_CE");
- else if (PR_SI_RELEASE == cmd)
- (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
- osvi.dwMinorVersion);
- break;
+ case VER_PLATFORM_WIN32_CE:
+ if (PR_SI_SYSNAME == cmd) {
+ (void)PR_snprintf(name, namelen, "Windows_CE");
+ }
+ else if (PR_SI_RELEASE == cmd)
+ (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
+ osvi.dwMinorVersion);
+ break;
#endif
- default:
- if (PR_SI_SYSNAME == cmd)
- (void)PR_snprintf(name, namelen, "Windows_Unknown");
- else if (PR_SI_RELEASE == cmd)
- (void)PR_snprintf(name, namelen, "%d.%d",0,0);
- break;
- }
- return PR_SUCCESS;
+ default:
+ if (PR_SI_SYSNAME == cmd) {
+ (void)PR_snprintf(name, namelen, "Windows_Unknown");
+ }
+ else if (PR_SI_RELEASE == cmd) {
+ (void)PR_snprintf(name, namelen, "%d.%d",0,0);
+ }
+ break;
+ }
+ return PR_SUCCESS;
}
PRStatus _MD_WindowsGetReleaseName(char *name, PRUint32 namelen)
{
- OSVERSIONINFO osvi;
-
- ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
- if (! GetVersionEx (&osvi) ) {
- _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
- return PR_FAILURE;
- }
-
- switch (osvi.dwPlatformId) {
- case VER_PLATFORM_WIN32_NT:
- case VER_PLATFORM_WIN32_WINDOWS:
- (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
- osvi.dwMinorVersion);
- break;
- default:
- (void)PR_snprintf(name, namelen, "%d.%d",0,0);
- break;
- }
- return PR_SUCCESS;
+ OSVERSIONINFO osvi;
+
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ if (! GetVersionEx (&osvi) ) {
+ _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+ return PR_FAILURE;
+ }
+
+ switch (osvi.dwPlatformId) {
+ case VER_PLATFORM_WIN32_NT:
+ case VER_PLATFORM_WIN32_WINDOWS:
+ (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
+ osvi.dwMinorVersion);
+ break;
+ default:
+ (void)PR_snprintf(name, namelen, "%d.%d",0,0);
+ break;
+ }
+ return PR_SUCCESS;
}
/*
@@ -924,12 +930,12 @@ PRStatus _MD_CreateFileMap(PRFileMap *fmap, PRInt64 size)
}
fmap->md.hFileMap = CreateFileMapping(
- (HANDLE) osfd,
- NULL,
- flProtect,
- dwHi,
- dwLo,
- NULL);
+ (HANDLE) osfd,
+ NULL,
+ flProtect,
+ dwHi,
+ dwLo,
+ NULL);
if (fmap->md.hFileMap == NULL) {
PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
@@ -958,18 +964,18 @@ void * _MD_MemMap(
dwLo = (DWORD) (offset & 0xffffffff);
dwHi = (DWORD) (((PRUint64) offset >> 32) & 0xffffffff);
if ((addr = MapViewOfFile(fmap->md.hFileMap, fmap->md.dwAccess,
- dwHi, dwLo, len)) == NULL) {
+ dwHi, dwLo, len)) == NULL) {
{
- LPVOID lpMsgBuf;
-
- FormatMessage(
+ LPVOID lpMsgBuf;
+
+ FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
- NULL
+ NULL
);
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("md_memmap(): %s", lpMsgBuf ));
}
@@ -1035,13 +1041,13 @@ PRStatus _MD_SyncMemMap(
#pragma warning(disable: 4035)
PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *val)
-{
+{
#if defined(__GNUC__)
- PRInt32 result;
- asm volatile ("lock ; xadd %0, %1"
- : "=r"(result), "=m"(*val)
- : "0"(1), "m"(*val));
- return result + 1;
+ PRInt32 result;
+ asm volatile ("lock ; xadd %0, %1"
+ : "=r"(result), "=m"(*val)
+ : "0"(1), "m"(*val));
+ return result + 1;
#else
__asm
{
@@ -1058,12 +1064,12 @@ PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *val)
PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *val)
{
#if defined(__GNUC__)
- PRInt32 result;
- asm volatile ("lock ; xadd %0, %1"
- : "=r"(result), "=m"(*val)
- : "0"(-1), "m"(*val));
- //asm volatile("lock ; xadd %0, %1" : "=m" (val), "=a" (result) : "-1" (1));
- return result - 1;
+ PRInt32 result;
+ asm volatile ("lock ; xadd %0, %1"
+ : "=r"(result), "=m"(*val)
+ : "0"(-1), "m"(*val));
+ //asm volatile("lock ; xadd %0, %1" : "=m" (val), "=a" (result) : "-1" (1));
+ return result - 1;
#else
__asm
{
@@ -1080,12 +1086,12 @@ PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *val)
PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *intp, PRInt32 val)
{
#if defined(__GNUC__)
- PRInt32 result;
- //asm volatile("lock ; xadd %1, %0" : "=m" (intp), "=a" (result) : "1" (val));
- asm volatile ("lock ; xadd %0, %1"
- : "=r"(result), "=m"(*intp)
- : "0"(val), "m"(*intp));
- return result + val;
+ PRInt32 result;
+ //asm volatile("lock ; xadd %1, %0" : "=m" (intp), "=a" (result) : "1" (val));
+ asm volatile ("lock ; xadd %0, %1"
+ : "=r"(result), "=m"(*intp)
+ : "0"(val), "m"(*intp));
+ return result + val;
#else
__asm
{
@@ -1102,96 +1108,101 @@ PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *intp, PRInt32 val)
#ifdef _PR_HAVE_ATOMIC_CAS
#pragma warning(disable: 4035)
-void
+void
PR_StackPush(PRStack *stack, PRStackElem *stack_elem)
{
#if defined(__GNUC__)
- void **tos = (void **) stack;
- void *tmp;
-
- retry:
- if (*tos == (void *) -1)
- goto retry;
-
- __asm__("xchg %0,%1"
- : "=r" (tmp), "=m"(*tos)
- : "0" (-1), "m"(*tos));
-
- if (tmp == (void *) -1)
- goto retry;
-
- *(void **)stack_elem = tmp;
- __asm__("" : : : "memory");
- *tos = stack_elem;
+ void **tos = (void **) stack;
+ void *tmp;
+
+retry:
+ if (*tos == (void *) -1) {
+ goto retry;
+ }
+
+ __asm__("xchg %0,%1"
+ : "=r" (tmp), "=m"(*tos)
+ : "0" (-1), "m"(*tos));
+
+ if (tmp == (void *) -1) {
+ goto retry;
+ }
+
+ *(void **)stack_elem = tmp;
+ __asm__("" : : : "memory");
+ *tos = stack_elem;
#else
__asm
{
- mov ebx, stack
- mov ecx, stack_elem
-retry: mov eax,[ebx]
- cmp eax,-1
- je retry
- mov eax,-1
- xchg dword ptr [ebx], eax
- cmp eax,-1
- je retry
- mov [ecx],eax
- mov [ebx],ecx
+ mov ebx, stack
+ mov ecx, stack_elem
+ retry: mov eax,[ebx]
+ cmp eax,-1
+ je retry
+ mov eax,-1
+ xchg dword ptr [ebx], eax
+ cmp eax,-1
+ je retry
+ mov [ecx],eax
+ mov [ebx],ecx
}
#endif /* __GNUC__ */
}
#pragma warning(default: 4035)
#pragma warning(disable: 4035)
-PRStackElem *
+PRStackElem *
PR_StackPop(PRStack *stack)
{
#if defined(__GNUC__)
- void **tos = (void **) stack;
- void *tmp;
-
- retry:
- if (*tos == (void *) -1)
- goto retry;
-
- __asm__("xchg %0,%1"
- : "=r" (tmp), "=m"(*tos)
- : "0" (-1), "m"(*tos));
-
- if (tmp == (void *) -1)
- goto retry;
-
- if (tmp != (void *) 0)
+ void **tos = (void **) stack;
+ void *tmp;
+
+retry:
+ if (*tos == (void *) -1) {
+ goto retry;
+ }
+
+ __asm__("xchg %0,%1"
+ : "=r" (tmp), "=m"(*tos)
+ : "0" (-1), "m"(*tos));
+
+ if (tmp == (void *) -1) {
+ goto retry;
+ }
+
+ if (tmp != (void *) 0)
{
- void *next = *(void **)tmp;
- *tos = next;
- *(void **)tmp = 0;
+ void *next = *(void **)tmp;
+ *tos = next;
+ *(void **)tmp = 0;
+ }
+ else {
+ *tos = tmp;
}
- else
- *tos = tmp;
-
- return tmp;
+
+ return tmp;
#else
__asm
{
- mov ebx, stack
-retry: mov eax,[ebx]
- cmp eax,-1
- je retry
- mov eax,-1
- xchg dword ptr [ebx], eax
- cmp eax,-1
- je retry
- cmp eax,0
- je empty
- mov ecx,[eax]
- mov [ebx],ecx
- mov [eax],0
- jmp done
-empty:
- mov [ebx],eax
-done:
- }
+ mov ebx, stack
+ retry: mov eax,[ebx]
+ cmp eax,-1
+ je retry
+ mov eax,-1
+ xchg dword ptr [ebx], eax
+ cmp eax,-1
+ je retry
+ cmp eax,0
+ je empty
+ mov ecx,[eax]
+ mov [ebx],ecx
+ mov [eax],0
+ jmp done
+ empty:
+ mov [ebx],eax
+ done:
+ }
#endif /* __GNUC__ */
}
#pragma warning(default: 4035)
diff --git a/nsprpub/pr/src/md/windows/ntsec.c b/nsprpub/pr/src/md/windows/ntsec.c
index c0682e454..0006e8399 100644
--- a/nsprpub/pr/src/md/windows/ntsec.c
+++ b/nsprpub/pr/src/md/windows/ntsec.c
@@ -47,7 +47,7 @@ void _PR_NT_InitSids(void)
* to force proper alignment */
PTOKEN_OWNER pTokenOwner = (PTOKEN_OWNER) infoBuffer;
PTOKEN_PRIMARY_GROUP pTokenPrimaryGroup
- = (PTOKEN_PRIMARY_GROUP) infoBuffer;
+ = (PTOKEN_PRIMARY_GROUP) infoBuffer;
DWORD dwLength;
BOOL rv;
@@ -67,13 +67,13 @@ void _PR_NT_InitSids(void)
* with the error code ERROR_ACCESS_DENIED.
*/
PR_LOG(_pr_io_lm, PR_LOG_DEBUG,
- ("_PR_NT_InitSids: OpenProcessToken() failed. Error: %d",
+ ("_PR_NT_InitSids: OpenProcessToken() failed. Error: %d",
GetLastError()));
return;
}
rv = GetTokenInformation(hToken, TokenOwner, infoBuffer,
- sizeof(infoBuffer), &dwLength);
+ sizeof(infoBuffer), &dwLength);
PR_ASSERT(rv != 0);
dwLength = GetLengthSid(pTokenOwner->Owner);
_pr_nt_sids.owner = (PSID) PR_Malloc(dwLength);
@@ -82,13 +82,13 @@ void _PR_NT_InitSids(void)
PR_ASSERT(rv != 0);
rv = GetTokenInformation(hToken, TokenPrimaryGroup, infoBuffer,
- sizeof(infoBuffer), &dwLength);
+ sizeof(infoBuffer), &dwLength);
PR_ASSERT(rv != 0);
dwLength = GetLengthSid(pTokenPrimaryGroup->PrimaryGroup);
_pr_nt_sids.group = (PSID) PR_Malloc(dwLength);
PR_ASSERT(_pr_nt_sids.group != NULL);
rv = CopySid(dwLength, _pr_nt_sids.group,
- pTokenPrimaryGroup->PrimaryGroup);
+ pTokenPrimaryGroup->PrimaryGroup);
PR_ASSERT(rv != 0);
rv = CloseHandle(hToken);
@@ -96,9 +96,9 @@ void _PR_NT_InitSids(void)
/* Create a well-known SID for the Everyone group. */
rv = AllocateAndInitializeSid(&SIDAuthWorld, 1,
- SECURITY_WORLD_RID,
- 0, 0, 0, 0, 0, 0, 0,
- &_pr_nt_sids.everyone);
+ SECURITY_WORLD_RID,
+ 0, 0, 0, 0, 0, 0, 0,
+ &_pr_nt_sids.everyone);
PR_ASSERT(rv != 0);
#endif
}
@@ -184,10 +184,10 @@ _PR_NT_MakeSecurityDescriptorACL(
*/
cbACL = sizeof(ACL)
- + 3 * (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD))
- + GetLengthSid(_pr_nt_sids.owner)
- + GetLengthSid(_pr_nt_sids.group)
- + GetLengthSid(_pr_nt_sids.everyone);
+ + 3 * (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD))
+ + GetLengthSid(_pr_nt_sids.owner)
+ + GetLengthSid(_pr_nt_sids.group)
+ + GetLengthSid(_pr_nt_sids.everyone);
pACL = (PACL) PR_Malloc(cbACL);
if (pACL == NULL) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
@@ -198,29 +198,47 @@ _PR_NT_MakeSecurityDescriptorACL(
goto failed;
}
accessMask = 0;
- if (mode & 00400) accessMask |= accessTable[0];
- if (mode & 00200) accessMask |= accessTable[1];
- if (mode & 00100) accessMask |= accessTable[2];
+ if (mode & 00400) {
+ accessMask |= accessTable[0];
+ }
+ if (mode & 00200) {
+ accessMask |= accessTable[1];
+ }
+ if (mode & 00100) {
+ accessMask |= accessTable[2];
+ }
if (accessMask && !AddAccessAllowedAce(pACL, ACL_REVISION, accessMask,
- _pr_nt_sids.owner)) {
+ _pr_nt_sids.owner)) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
goto failed;
}
accessMask = 0;
- if (mode & 00040) accessMask |= accessTable[0];
- if (mode & 00020) accessMask |= accessTable[1];
- if (mode & 00010) accessMask |= accessTable[2];
+ if (mode & 00040) {
+ accessMask |= accessTable[0];
+ }
+ if (mode & 00020) {
+ accessMask |= accessTable[1];
+ }
+ if (mode & 00010) {
+ accessMask |= accessTable[2];
+ }
if (accessMask && !AddAccessAllowedAce(pACL, ACL_REVISION, accessMask,
- _pr_nt_sids.group)) {
+ _pr_nt_sids.group)) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
goto failed;
}
accessMask = 0;
- if (mode & 00004) accessMask |= accessTable[0];
- if (mode & 00002) accessMask |= accessTable[1];
- if (mode & 00001) accessMask |= accessTable[2];
+ if (mode & 00004) {
+ accessMask |= accessTable[0];
+ }
+ if (mode & 00002) {
+ accessMask |= accessTable[1];
+ }
+ if (mode & 00001) {
+ accessMask |= accessTable[2];
+ }
if (accessMask && !AddAccessAllowedAce(pACL, ACL_REVISION, accessMask,
- _pr_nt_sids.everyone)) {
+ _pr_nt_sids.everyone)) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
goto failed;
}
diff --git a/nsprpub/pr/src/md/windows/ntsem.c b/nsprpub/pr/src/md/windows/ntsem.c
index f36a145a9..757bc839e 100644
--- a/nsprpub/pr/src/md/windows/ntsem.c
+++ b/nsprpub/pr/src/md/windows/ntsem.c
@@ -12,38 +12,40 @@
#include "primpl.h"
-void
+void
_PR_MD_NEW_SEM(_MDSemaphore *md, PRUintn value)
{
md->sem = CreateSemaphore(NULL, value, 0x7fffffff, NULL);
}
-void
+void
_PR_MD_DESTROY_SEM(_MDSemaphore *md)
{
CloseHandle(md->sem);
}
-PRStatus
+PRStatus
_PR_MD_TIMED_WAIT_SEM(_MDSemaphore *md, PRIntervalTime ticks)
{
int rv;
rv = WaitForSingleObject(md->sem, PR_IntervalToMilliseconds(ticks));
- if (rv == WAIT_OBJECT_0)
+ if (rv == WAIT_OBJECT_0) {
return PR_SUCCESS;
- else
+ }
+ else {
return PR_FAILURE;
+ }
}
-PRStatus
+PRStatus
_PR_MD_WAIT_SEM(_MDSemaphore *md)
{
return _PR_MD_TIMED_WAIT_SEM(md, PR_INTERVAL_NO_TIMEOUT);
}
-void
+void
_PR_MD_POST_SEM(_MDSemaphore *md)
{
ReleaseSemaphore(md->sem, 1, NULL);
diff --git a/nsprpub/pr/src/md/windows/ntthread.c b/nsprpub/pr/src/md/windows/ntthread.c
index 1fdf0e93b..395a80dcc 100644
--- a/nsprpub/pr/src/md/windows/ntthread.c
+++ b/nsprpub/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;
@@ -181,23 +181,23 @@ pr_root(void *arg)
return 0;
}
-PRStatus
-_PR_MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+PRStatus
+_PR_MD_CREATE_THREAD(PRThread *thread,
+ 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;
@@ -250,14 +251,14 @@ _PR_MD_END_THREAD(void)
_endthreadex(0);
}
-void
+void
_PR_MD_YIELD(void)
{
/* Can NT really yield at all? */
Sleep(0);
}
-void
+void
_PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
{
int nativePri;
@@ -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);
@@ -428,7 +430,7 @@ _PR_MD_EXIT(PRIntn status)
#ifdef HAVE_FIBERS
void
-_pr_fiber_mainline(void *unused)
+_pr_fiber_mainline(void *unused)
{
PRThread *fiber = _PR_MD_CURRENT_THREAD();
@@ -445,7 +447,7 @@ PRThread *_PR_MD_CREATE_USER_THREAD(
if ( (thread = PR_NEW(PRThread)) == NULL ) {
return NULL;
}
-
+
memset(thread, 0, sizeof(PRThread));
thread->md.fiber_fn = start;
thread->md.fiber_arg = arg;
@@ -468,10 +470,11 @@ void
_PR_MD_INIT_CONTEXT(PRThread *thread, char *top, void (*start) (void), PRBool *status)
{
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)
+ thread->md.fiber_id = CreateFiber(thread->md.fiber_stacksize,
+ (LPFIBER_START_ROUTINE)_pr_fiber_mainline, NULL);
+ if (thread->md.fiber_id != 0) {
*status = PR_TRUE;
+ }
else {
DWORD oserror = GetLastError();
PRErrorCode prerror;
@@ -502,7 +505,7 @@ _PR_MD_RESTORE_CONTEXT(PRThread *thread)
PR_ASSERT( !_PR_IS_NATIVE_THREAD(thread) );
/* The user-level code for yielding will happily add ourselves to the runq
- * and then switch to ourselves; the NT fibers can't handle switching to
+ * and then switch to ourselves; the NT fibers can't handle switching to
* ourselves.
*/
if (thread != me) {
@@ -532,12 +535,12 @@ PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask)
PRInt32 rv, system_mask;
rv = GetProcessAffinityMask(GetCurrentProcess(), mask, &system_mask);
-
+
return rv?0:-1;
}
-void
-_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
+void
+_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
{
_PR_MD_SUSPEND_THREAD(cpu->thread);
}
@@ -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;
}
diff --git a/nsprpub/pr/src/md/windows/w32ipcsem.c b/nsprpub/pr/src/md/windows/w32ipcsem.c
index 954591002..500009352 100644
--- a/nsprpub/pr/src/md/windows/w32ipcsem.c
+++ b/nsprpub/pr/src/md/windows/w32ipcsem.c
@@ -18,17 +18,19 @@ static HANDLE OpenSemaphore(DWORD inDesiredAccess,
HANDLE retval = NULL;
HANDLE semaphore = NULL;
PRUnichar wideName[MAX_PATH]; /* name size is limited to MAX_PATH */
-
+
MultiByteToWideChar(CP_ACP, 0, inName, -1, wideName, MAX_PATH);
/* 0x7fffffff is the max count for our semaphore */
semaphore = CreateSemaphoreW(NULL, 0, 0x7fffffff, wideName);
if (NULL != semaphore) {
DWORD lastErr = GetLastError();
-
- if (ERROR_ALREADY_EXISTS != lastErr)
+
+ if (ERROR_ALREADY_EXISTS != lastErr) {
CloseHandle(semaphore);
- else
+ }
+ else {
retval = semaphore;
+ }
}
return retval;
}
@@ -97,8 +99,8 @@ static DWORD FiberSafeWaitForSingleObject(
warg.handle = hHandle;
warg.timeout = dwMilliseconds;
waitThread = PR_CreateThread(
- PR_USER_THREAD, WaitSingleThread, &warg,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, WaitSingleThread, &warg,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (waitThread == NULL) {
return WAIT_FAILED;
}
@@ -133,7 +135,7 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
}
if (flags & PR_SEM_CREATE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, semAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -142,7 +144,7 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
#ifdef WINCE
{
/* The size of a sem's name is limited to MAX_PATH. */
- PRUnichar wosname[MAX_PATH];
+ PRUnichar wosname[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, osname, -1, wosname, MAX_PATH);
sem->sem = CreateSemaphoreW(lpSA, value, 0x7fffffff, wosname);
}
@@ -165,7 +167,7 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
}
} else {
sem->sem = OpenSemaphore(
- SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, FALSE, osname);
+ SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, FALSE, osname);
if (sem->sem == NULL) {
DWORD err = GetLastError();
diff --git a/nsprpub/pr/src/md/windows/w32poll.c b/nsprpub/pr/src/md/windows/w32poll.c
index daf14dfe0..241c7e3e4 100644
--- a/nsprpub/pr/src/md/windows/w32poll.c
+++ b/nsprpub/pr/src/md/windows/w32poll.c
@@ -62,13 +62,17 @@ int _PR_NTFiberSafeSelect(
data.tv = timeout;
selectThread = PR_CreateThread(
- PR_USER_THREAD, _PR_MD_select_thread, &data,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
- if (selectThread == NULL) return -1;
+ PR_USER_THREAD, _PR_MD_select_thread, &data,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ if (selectThread == NULL) {
+ return -1;
+ }
PR_JoinThread(selectThread);
ready = data.status;
- if (ready == SOCKET_ERROR) WSASetLastError(data.error);
+ if (ready == SOCKET_ERROR) {
+ WSASetLastError(data.error);
+ }
}
return ready;
}
@@ -120,17 +124,17 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
if (pd->in_flags & PR_POLL_READ)
{
in_flags_read = (pd->fd->methods->poll)(
- pd->fd, (PRInt16)(pd->in_flags & ~PR_POLL_WRITE),
- &out_flags_read);
+ pd->fd, (PRInt16)(pd->in_flags & ~PR_POLL_WRITE),
+ &out_flags_read);
}
if (pd->in_flags & PR_POLL_WRITE)
{
in_flags_write = (pd->fd->methods->poll)(
- pd->fd, (PRInt16)(pd->in_flags & ~PR_POLL_READ),
- &out_flags_write);
+ pd->fd, (PRInt16)(pd->in_flags & ~PR_POLL_READ),
+ &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
+ || (0 != (in_flags_write & out_flags_write)))
{
/* this one's ready right now (buffered input) */
if (0 == ready)
@@ -158,7 +162,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
/* ignore a socket without PR_NSPR_IO_LAYER available */
if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
+ && (_PR_FILEDESC_OPEN == bottom->secret->state))
{
if (0 == ready)
{
@@ -214,7 +218,9 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
}
}
- if (0 != ready) return ready; /* no need to block */
+ if (0 != ready) {
+ return ready; /* no need to block */
+ }
/*
* FD_SET does nothing if the fd_set's internal fd_array is full. If
@@ -271,22 +277,30 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
if (FD_ISSET(osfd, &rd))
{
- if (pd->out_flags & _PR_POLL_READ_SYS_READ)
+ if (pd->out_flags & _PR_POLL_READ_SYS_READ) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_READ)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) {
out_flags |= PR_POLL_WRITE;
- }
+ }
+ }
if (FD_ISSET(osfd, &wt))
{
- if (pd->out_flags & _PR_POLL_READ_SYS_WRITE)
+ if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) {
out_flags |= PR_POLL_WRITE;
- }
- if (FD_ISSET(osfd, &ex)) out_flags |= PR_POLL_EXCEPT;
+ }
+ }
+ if (FD_ISSET(osfd, &ex)) {
+ out_flags |= PR_POLL_EXCEPT;
+ }
}
pd->out_flags = out_flags;
- if (out_flags) ready++;
+ if (out_flags) {
+ ready++;
+ }
}
PR_ASSERT(ready > 0);
}
@@ -306,7 +320,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
{
bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
if (getsockopt(bottom->secret->md.osfd, SOL_SOCKET,
- SO_TYPE, (char *) &optval, &optlen) == -1)
+ SO_TYPE, (char *) &optval, &optlen) == -1)
{
PR_ASSERT(WSAGetLastError() == WSAENOTSOCK);
if (WSAGetLastError() == WSAENOTSOCK)
@@ -319,7 +333,9 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
}
PR_ASSERT(ready > 0);
}
- else _PR_MD_MAP_SELECT_ERROR(err);
+ else {
+ _PR_MD_MAP_SELECT_ERROR(err);
+ }
}
return ready;
diff --git a/nsprpub/pr/src/md/windows/w32rng.c b/nsprpub/pr/src/md/windows/w32rng.c
index 633ae0da5..c07625ecc 100644
--- a/nsprpub/pr/src/md/windows/w32rng.c
+++ b/nsprpub/pr/src/md/windows/w32rng.c
@@ -16,8 +16,9 @@ CurrentClockTickTime(LPDWORD lpdwHigh, LPDWORD lpdwLow)
{
LARGE_INTEGER liCount;
- if (!QueryPerformanceCounter(&liCount))
+ if (!QueryPerformanceCounter(&liCount)) {
return FALSE;
+ }
*lpdwHigh = liCount.u.HighPart;
*lpdwLow = liCount.u.LowPart;
@@ -31,8 +32,9 @@ extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
size_t nBytes;
time_t sTime;
- if (size <= 0)
+ if (size <= 0) {
return 0;
+ }
CurrentClockTickTime(&dwHigh, &dwLow);
@@ -42,16 +44,18 @@ extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
n += nBytes;
size -= nBytes;
- if (size <= 0)
+ if (size <= 0) {
return n;
+ }
nBytes = sizeof(dwHigh) > size ? size : sizeof(dwHigh);
memcpy(((char *)buf) + n, &dwHigh, nBytes);
n += nBytes;
size -= nBytes;
- if (size <= 0)
+ if (size <= 0) {
return n;
+ }
// get the number of milliseconds that have elapsed since Windows started
dwVal = GetTickCount();
@@ -61,8 +65,9 @@ extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
n += nBytes;
size -= nBytes;
- if (size <= 0)
+ if (size <= 0) {
return n;
+ }
// get the time in seconds since midnight Jan 1, 1970
time(&sTime);
diff --git a/nsprpub/pr/src/md/windows/w32shm.c b/nsprpub/pr/src/md/windows/w32shm.c
index 8e8b1d684..b0d38b9d7 100644
--- a/nsprpub/pr/src/md/windows/w32shm.c
+++ b/nsprpub/pr/src/md/windows/w32shm.c
@@ -3,7 +3,7 @@
* 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 <private/primpl.h>
+#include <private/primpl.h>
#include <string.h>
#include <prshm.h>
#include <prerr.h>
@@ -23,15 +23,15 @@ extern PRLogModuleInfo *_pr_shm_lm;
*/
static DWORD filemapAccessTable[] = {
FILE_MAP_ALL_ACCESS & ~FILE_MAP_WRITE, /* read */
- FILE_MAP_ALL_ACCESS & ~FILE_MAP_READ, /* write */
+ FILE_MAP_ALL_ACCESS & ~FILE_MAP_READ, /* write */
0 /* execute */
};
-extern PRSharedMemory * _MD_OpenSharedMemory(
- const char *name,
- PRSize size,
- PRIntn flags,
- PRIntn mode
+extern PRSharedMemory * _MD_OpenSharedMemory(
+ const char *name,
+ PRSize size,
+ PRIntn flags,
+ PRIntn mode
)
{
char ipcname[PR_IPC_NAME_SIZE];
@@ -48,15 +48,15 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( PR_FAILURE == rc )
{
PR_SetError(PR_UNKNOWN_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: name is invalid"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: name is invalid"));
return(NULL);
}
shm = PR_NEWZAP( PRSharedMemory );
- if ( NULL == shm )
+ if ( NULL == shm )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
return(NULL);
}
@@ -64,14 +64,14 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( NULL == shm->ipcname )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
PR_DELETE(shm);
return(NULL);
}
/* copy args to struct */
strcpy( shm->ipcname, ipcname );
- shm->size = size;
+ shm->size = size;
shm->mode = mode;
shm->flags = flags;
shm->ident = _PR_SHM_IDENT;
@@ -81,7 +81,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
dwLo = (DWORD) (shm->size & 0xffffffff);
if (_PR_NT_MakeSecurityDescriptorACL(mode, filemapAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -97,48 +97,48 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
MultiByteToWideChar(CP_ACP, 0, shm->ipcname, -1,
wideIpcName, MAX_PATH);
shm->handle = CreateFileMappingW(
- (HANDLE)-1 ,
- lpSA,
- flProtect,
- dwHi,
- dwLo,
- wideIpcName);
+ (HANDLE)-1,
+ lpSA,
+ flProtect,
+ dwHi,
+ dwLo,
+ wideIpcName);
}
#else
shm->handle = CreateFileMappingA(
- (HANDLE)-1 ,
- lpSA,
- flProtect,
- dwHi,
- dwLo,
- shm->ipcname);
+ (HANDLE)-1,
+ lpSA,
+ flProtect,
+ dwHi,
+ dwLo,
+ shm->ipcname);
#endif
if (lpSA != NULL) {
_PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
}
if ( NULL == shm->handle ) {
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s",
- shm->ipcname ));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s",
+ shm->ipcname ));
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
PR_FREEIF( shm->ipcname )
PR_DELETE( shm );
return(NULL);
} else {
if (( flags & PR_SHM_EXCL) && ( GetLastError() == ERROR_ALREADY_EXISTS )) {
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: Request exclusive & already exists",
- shm->ipcname ));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: Request exclusive & already exists",
+ shm->ipcname ));
PR_SetError( PR_FILE_EXISTS_ERROR, ERROR_ALREADY_EXISTS );
CloseHandle( shm->handle );
PR_FREEIF( shm->ipcname )
PR_DELETE( shm );
return(NULL);
} else {
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d",
- shm->ipcname, shm->handle ));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d",
+ shm->ipcname, shm->handle ));
return(shm);
}
}
@@ -151,17 +151,17 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
#endif
if ( NULL == shm->handle ) {
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: OpenFileMapping() failed: %s, error: %d",
- shm->ipcname, PR_GetOSError()));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: OpenFileMapping() failed: %s, error: %d",
+ shm->ipcname, PR_GetOSError()));
PR_FREEIF( shm->ipcname );
PR_DELETE( shm );
return(NULL);
} else {
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: OpenFileMapping() success: %s, handle: %d",
- shm->ipcname, shm->handle ));
- return(shm);
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: OpenFileMapping() success: %s, handle: %d",
+ shm->ipcname, shm->handle ));
+ return(shm);
}
}
/* returns from separate paths */
@@ -174,18 +174,19 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags )
PR_ASSERT( shm->ident == _PR_SHM_IDENT );
- if ( PR_SHM_READONLY & flags )
+ if ( PR_SHM_READONLY & flags ) {
access = FILE_MAP_READ;
+ }
addr = MapViewOfFile( shm->handle,
- access,
- 0, 0,
- shm->size );
+ access,
+ 0, 0,
+ shm->size );
if ( NULL == addr ) {
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
- PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
- ("_MD_AttachSharedMemory: MapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
+ ("_MD_AttachSharedMemory: MapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
}
return( addr );
@@ -200,11 +201,11 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
PR_ASSERT( shm->ident == _PR_SHM_IDENT );
wrc = UnmapViewOfFile( addr );
- if ( FALSE == wrc )
+ if ( FALSE == wrc )
{
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
- PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
- ("_MD_DetachSharedMemory: UnmapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
+ ("_MD_DetachSharedMemory: UnmapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
rc = PR_FAILURE;
}
@@ -223,8 +224,8 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
if ( FALSE == wrc )
{
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
- PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
- ("_MD_CloseSharedMemory: CloseHandle() failed. OSerror: %d", PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
+ ("_MD_CloseSharedMemory: CloseHandle() failed. OSerror: %d", PR_GetOSError()));
rc = PR_FAILURE;
}
PR_FREEIF( shm->ipcname );
@@ -236,7 +237,7 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
extern PRStatus _MD_DeleteSharedMemory( const char *name )
{
return( PR_SUCCESS );
-}
+}
/*
@@ -244,7 +245,7 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
*/
extern PRLogModuleInfo *_pr_shma_lm;
-extern PRFileMap* _md_OpenAnonFileMap(
+extern PRFileMap* _md_OpenAnonFileMap(
const char *dirName,
PRSize size,
PRFileMapProtect prot
@@ -256,7 +257,7 @@ extern PRFileMap* _md_OpenAnonFileMap(
fm = PR_CreateFileMap( (PRFileDesc*)-1, size, prot );
if ( NULL == fm ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): PR_CreateFileMap(): failed"));
+ ("_md_OpenAnonFileMap(): PR_CreateFileMap(): failed"));
goto Finished;
}
@@ -267,12 +268,12 @@ extern PRFileMap* _md_OpenAnonFileMap(
** ERROR_CALL_NOT_IMPLEMENTED on Win95.
*/
if (DuplicateHandle(GetCurrentProcess(), fm->md.hFileMap,
- GetCurrentProcess(), &hFileMap,
- 0, TRUE /* inheritable */,
- DUPLICATE_SAME_ACCESS) == FALSE) {
+ GetCurrentProcess(), &hFileMap,
+ 0, TRUE /* inheritable */,
+ DUPLICATE_SAME_ACCESS) == FALSE) {
PR_SetError( PR_UNKNOWN_ERROR, GetLastError() );
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): DuplicateHandle(): failed"));
+ ("_md_OpenAnonFileMap(): DuplicateHandle(): failed"));
PR_CloseFileMap( fm );
fm = NULL;
goto Finished;
@@ -280,7 +281,7 @@ extern PRFileMap* _md_OpenAnonFileMap(
CloseHandle(fm->md.hFileMap);
fm->md.hFileMap = hFileMap;
-Finished:
+Finished:
return(fm);
} /* end md_OpenAnonFileMap() */
@@ -297,12 +298,12 @@ extern PRStatus _md_ExportFileMapAsString(
PRIntn written;
written = PR_snprintf( buf, (PRUint32) bufSize, "%d:%" PR_PRIdOSFD ":%ld",
- (PRIntn)fm->prot, (PROsfd)fm->md.hFileMap, (PRInt32)fm->md.dwAccess );
+ (PRIntn)fm->prot, (PROsfd)fm->md.hFileMap, (PRInt32)fm->md.dwAccess );
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ExportFileMapAsString(): prot: %x, hFileMap: %x, dwAccess: %x",
- fm->prot, fm->md.hFileMap, fm->md.dwAccess ));
-
+ ("_md_ExportFileMapAsString(): prot: %x, hFileMap: %x, dwAccess: %x",
+ fm->prot, fm->md.hFileMap, fm->md.dwAccess ));
+
return((written == -1)? PR_FAILURE : PR_SUCCESS);
} /* end _md_ExportFileMapAsString() */
@@ -321,12 +322,12 @@ extern PRFileMap * _md_ImportFileMapFromString(
PRFileMap *fm = NULL;
PR_sscanf( fmstring, "%d:%" PR_SCNdOSFD ":%ld",
- &prot, &hFileMap, &dwAccess );
+ &prot, &hFileMap, &dwAccess );
fm = PR_NEWZAP(PRFileMap);
if ( NULL == fm ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ImportFileMapFromString(): PR_NEWZAP(): Failed"));
+ ("_md_ImportFileMapFromString(): PR_NEWZAP(): Failed"));
return(fm);
}
@@ -336,12 +337,12 @@ extern PRFileMap * _md_ImportFileMapFromString(
fm->fd = (PRFileDesc*)-1;
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ImportFileMapFromString(): fm: %p, prot: %d, hFileMap: %8.8x, dwAccess: %8.8x, fd: %x",
- fm, prot, fm->md.hFileMap, fm->md.dwAccess, fm->fd));
+ ("_md_ImportFileMapFromString(): fm: %p, prot: %d, hFileMap: %8.8x, dwAccess: %8.8x, fd: %x",
+ fm, prot, fm->md.hFileMap, fm->md.dwAccess, fm->fd));
return(fm);
} /* end _md_ImportFileMapFromString() */
#else
-Error! Why is PR_HAVE_WIN32_NAMED_SHARED_MEMORY not defined?
+Error! Why is PR_HAVE_WIN32_NAMED_SHARED_MEMORY not defined?
#endif /* PR_HAVE_WIN32_NAMED_SHARED_MEMORY */
/* --- end w32shm.c --- */
diff --git a/nsprpub/pr/src/md/windows/w95cv.c b/nsprpub/pr/src/md/windows/w95cv.c
index 27b34e691..5cf2966ff 100644
--- a/nsprpub/pr/src/md/windows/w95cv.c
+++ b/nsprpub/pr/src/md/windows/w95cv.c
@@ -16,7 +16,7 @@
* until right after we unlock the lock. This way the awakened threads
* have a better chance to reaquire the lock.
*/
-
+
#include "primpl.h"
/*
@@ -30,7 +30,7 @@ static void
AddThreadToCVWaitQueueInternal(PRThread *thred, struct _MDCVar *cv)
{
PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
- || (cv->waitTail == NULL && cv->waitHead == NULL));
+ || (cv->waitTail == NULL && cv->waitHead == NULL));
cv->nwait += 1;
thred->md.inCVWaitQueue = PR_TRUE;
thred->md.next = NULL;
@@ -78,7 +78,7 @@ md_UnlockAndPostNotifies(
lock->notified.link = NULL;
#endif
- /*
+ /*
* Figure out how many threads we need to wake up.
*/
notified = &post; /* this is where we start */
@@ -87,7 +87,7 @@ md_UnlockAndPostNotifies(
_MDCVar *cv = notified->cv[index].cv;
PRThread *thred;
int i;
-
+
/* Fast special case: no waiting threads */
if (cv->waitHead == NULL) {
notified->cv[index].notifyHead = NULL;
@@ -134,7 +134,7 @@ md_UnlockAndPostNotifies(
}
/* Release the lock before notifying */
- LeaveCriticalSection(&lock->mutex);
+ LeaveCriticalSection(&lock->mutex);
notified = &post; /* this is where we start */
do {
@@ -156,7 +156,9 @@ md_UnlockAndPostNotifies(
}
prev = notified;
notified = notified->link;
- if (&post != prev) PR_DELETE(prev);
+ if (&post != prev) {
+ PR_DELETE(prev);
+ }
} while (NULL != notified);
}
@@ -166,7 +168,7 @@ md_UnlockAndPostNotifies(
* MP systems don't contend for a lock that they can't have.
*/
static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
- PRBool broadcast)
+ PRBool broadcast)
{
PRIntn index = 0;
_MDNotified *notified = &lock->notified;
@@ -183,7 +185,9 @@ static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
}
}
/* if not full, enter new CV in this array */
- if (notified->length < _MD_CV_NOTIFIED_LENGTH) break;
+ if (notified->length < _MD_CV_NOTIFIED_LENGTH) {
+ break;
+ }
/* if there's no link, create an empty array and link it */
if (NULL == notified->link) {
@@ -207,7 +211,7 @@ static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
* 0 when it succeeds.
*
*/
-PRInt32
+PRInt32
_PR_MD_NEW_CV(_MDCVar *cv)
{
cv->magic = _MD_MAGIC_CV;
@@ -216,7 +220,7 @@ _PR_MD_NEW_CV(_MDCVar *cv)
* when the PRCondVar structure is created.
*/
return 0;
-}
+}
void _PR_MD_FREE_CV(_MDCVar *cv)
{
@@ -232,7 +236,7 @@ void _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout )
PRThread *thred = _PR_MD_CURRENT_THREAD();
DWORD rv;
DWORD msecs = (timeout == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(timeout);
+ INFINITE : PR_IntervalToMilliseconds(timeout);
/*
* If we have pending notifies, post them now.
@@ -256,7 +260,7 @@ void _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout )
if (rv == WAIT_TIMEOUT) {
if (thred->md.inCVWaitQueue) {
PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
- || (cv->waitTail == NULL && cv->waitHead == NULL));
+ || (cv->waitTail == NULL && cv->waitHead == NULL));
cv->nwait -= 1;
thred->md.inCVWaitQueue = PR_FALSE;
if (cv->waitHead == thred) {
@@ -325,7 +329,7 @@ void _PR_MD_INIT_LOCKS(void)
PR_ASSERT(hKernel32);
PR_ASSERT(!sInitializeCriticalSectionEx);
sInitializeCriticalSectionEx = (INITIALIZECRITICALSECTIONEX)
- GetProcAddress(hKernel32, "InitializeCriticalSectionEx");
+ GetProcAddress(hKernel32, "InitializeCriticalSectionEx");
}
/*
diff --git a/nsprpub/pr/src/md/windows/w95dllmain.c b/nsprpub/pr/src/md/windows/w95dllmain.c
index 73707a6e1..c9ab87aec 100644
--- a/nsprpub/pr/src/md/windows/w95dllmain.c
+++ b/nsprpub/pr/src/md/windows/w95dllmain.c
@@ -18,7 +18,7 @@ BOOL WINAPI DllMain(
DWORD fdwReason,
LPVOID lpvReserved)
{
-PRThread *me;
+ PRThread *me;
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
@@ -28,8 +28,9 @@ PRThread *me;
case DLL_THREAD_DETACH:
if (_pr_initialized) {
me = _MD_GET_ATTACHED_THREAD();
- if ((me != NULL) && (me->flags & _PR_ATTACHED))
+ if ((me != NULL) && (me->flags & _PR_ATTACHED)) {
_PRI_DetachThread();
+ }
}
break;
case DLL_PROCESS_DETACH:
diff --git a/nsprpub/pr/src/md/windows/w95io.c b/nsprpub/pr/src/md/windows/w95io.c
index 9bae6f8df..2ad52e19b 100644
--- a/nsprpub/pr/src/md/windows/w95io.c
+++ b/nsprpub/pr/src/md/windows/w95io.c
@@ -53,8 +53,8 @@ _PR_MD_INIT_IO()
{
SYSTEMTIME systime;
union {
- PRTime prt;
- FILETIME ft;
+ PRTime prt;
+ FILETIME ft;
} filetime;
BOOL rv;
@@ -84,16 +84,16 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
DWORD rv;
PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(ticks);
+ INFINITE : PR_IntervalToMilliseconds(ticks);
rv = WaitForSingleObject(thread->md.blocked_sema, msecs);
- switch(rv)
+ switch(rv)
{
case WAIT_OBJECT_0:
return PR_SUCCESS;
case WAIT_TIMEOUT:
_PR_THREAD_LOCK(thread);
if (thread->state == _PR_IO_WAIT) {
- ;
+ ;
} else {
if (thread->wait.cvar != NULL) {
thread->wait.cvar = NULL;
@@ -116,13 +116,15 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
PRStatus
_PR_MD_WAKEUP_WAITER(PRThread *thread)
{
- if ( _PR_IS_NATIVE_THREAD(thread) )
+ if ( _PR_IS_NATIVE_THREAD(thread) )
{
- if (ReleaseSemaphore(thread->md.blocked_sema, 1, NULL) == FALSE)
+ if (ReleaseSemaphore(thread->md.blocked_sema, 1, NULL) == FALSE) {
return PR_FAILURE;
- else
- return PR_SUCCESS;
- }
+ }
+ else {
+ return PR_SUCCESS;
+ }
+ }
}
@@ -135,7 +137,7 @@ _PR_MD_WAKEUP_WAITER(PRThread *thread)
* The NSPR open flags (osflags) are translated into flags for Win95
*
* Mode seems to be passed in as a unix style file permissions argument
- * as in 0666, in the case of opening the logFile.
+ * as in 0666, in the case of opening the logFile.
*
*/
PROsfd
@@ -145,26 +147,35 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
PRInt32 access = 0;
PRInt32 flags = 0;
PRInt32 flag6 = 0;
-
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
-
- if (osflags & PR_RDONLY || osflags & PR_RDWR)
+
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
+
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR)
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
access |= GENERIC_WRITE;
+ }
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
+ }
else if (osflags & PR_CREATE_FILE) {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = CREATE_ALWAYS;
- else
+ }
+ else {
flags = OPEN_ALWAYS;
+ }
} else {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = TRUNCATE_EXISTING;
- else
+ }
+ else {
flags = OPEN_EXISTING;
+ }
}
file = CreateFileA(name,
@@ -175,9 +186,9 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
flag6,
NULL);
if (file == INVALID_HANDLE_VALUE) {
- _PR_MD_MAP_OPEN_ERROR(GetLastError());
- return -1;
- }
+ _PR_MD_MAP_OPEN_ERROR(GetLastError());
+ return -1;
+ }
return (PROsfd)file;
}
@@ -196,33 +207,42 @@ _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, int mode)
if (osflags & PR_CREATE_FILE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, fileAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
lpSA = &sa;
}
}
-
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
-
- if (osflags & PR_RDONLY || osflags & PR_RDWR)
+
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
+
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR)
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
access |= GENERIC_WRITE;
+ }
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
+ }
else if (osflags & PR_CREATE_FILE) {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = CREATE_ALWAYS;
- else
+ }
+ else {
flags = OPEN_ALWAYS;
+ }
} else {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = TRUNCATE_EXISTING;
- else
+ }
+ else {
flags = OPEN_EXISTING;
+ }
}
file = CreateFileA(name,
@@ -236,9 +256,9 @@ _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, int mode)
_PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
}
if (file == INVALID_HANDLE_VALUE) {
- _PR_MD_MAP_OPEN_ERROR(GetLastError());
- return -1;
- }
+ _PR_MD_MAP_OPEN_ERROR(GetLastError());
+ return -1;
+ }
return (PROsfd)file;
}
@@ -250,22 +270,23 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
int rv, err;
rv = ReadFile((HANDLE)fd->secret->md.osfd,
- (LPVOID)buf,
- len,
- &bytes,
- NULL);
-
- if (rv == 0)
+ (LPVOID)buf,
+ len,
+ &bytes,
+ NULL);
+
+ if (rv == 0)
{
err = GetLastError();
/* ERROR_HANDLE_EOF can only be returned by async io */
PR_ASSERT(err != ERROR_HANDLE_EOF);
- if (err == ERROR_BROKEN_PIPE)
+ if (err == ERROR_BROKEN_PIPE) {
return 0;
- else {
- _PR_MD_MAP_READ_ERROR(err);
- return -1;
- }
+ }
+ else {
+ _PR_MD_MAP_READ_ERROR(err);
+ return -1;
+ }
}
return bytes;
}
@@ -276,16 +297,16 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
PROsfd f = fd->secret->md.osfd;
PRInt32 bytes;
int rv;
-
+
rv = WriteFile((HANDLE)f,
- buf,
- len,
- &bytes,
- NULL );
-
- if (rv == 0)
+ buf,
+ len,
+ &bytes,
+ NULL );
+
+ if (rv == 0)
{
- _PR_MD_MAP_WRITE_ERROR(GetLastError());
+ _PR_MD_MAP_WRITE_ERROR(GetLastError());
return -1;
}
return bytes;
@@ -348,7 +369,7 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence)
li.QuadPart = offset;
li.LowPart = SetFilePointer((HANDLE)fd->secret->md.osfd,
- li.LowPart, &li.HighPart, moveMethod);
+ li.LowPart, &li.HighPart, moveMethod);
if (0xffffffff == li.LowPart && (err = GetLastError()) != NO_ERROR) {
_PR_MD_MAP_LSEEK_ERROR(err);
@@ -369,10 +390,10 @@ _PR_MD_FSYNC(PRFileDesc *fd)
/*
* From the documentation:
*
- * On Windows NT, the function FlushFileBuffers fails if hFile
- * is a handle to console output. That is because console
- * output is not buffered. The function returns FALSE, and
- * GetLastError returns ERROR_INVALID_HANDLE.
+ * On Windows NT, the function FlushFileBuffers fails if hFile
+ * is a handle to console output. That is because console
+ * output is not buffered. The function returns FALSE, and
+ * GetLastError returns ERROR_INVALID_HANDLE.
*
* On the other hand, on Win95, it returns without error. I cannot
* assume that 0, 1, and 2 are console, because if someone closes
@@ -386,11 +407,11 @@ _PR_MD_FSYNC(PRFileDesc *fd)
BOOL ok = FlushFileBuffers((HANDLE)fd->secret->md.osfd);
if (!ok) {
- DWORD err = GetLastError();
- if (err != ERROR_ACCESS_DENIED) { // from winerror.h
- _PR_MD_MAP_FSYNC_ERROR(err);
- return -1;
- }
+ DWORD err = GetLastError();
+ if (err != ERROR_ACCESS_DENIED) { // from winerror.h
+ _PR_MD_MAP_FSYNC_ERROR(err);
+ return -1;
+ }
}
return 0;
}
@@ -399,17 +420,18 @@ PRInt32
_MD_CloseFile(PROsfd osfd)
{
PRInt32 rv;
-
+
rv = (CloseHandle((HANDLE)osfd))?0:-1;
- if (rv == -1)
- _PR_MD_MAP_CLOSE_ERROR(GetLastError());
+ if (rv == -1) {
+ _PR_MD_MAP_CLOSE_ERROR(GetLastError());
+ }
return rv;
}
/* --- DIR IO ------------------------------------------------------------ */
#define GetFileFromDIR(d) (d)->d_entry.cFileName
-#define FileIsHidden(d) ((d)->d_entry.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
+#define FileIsHidden(d) ((d)->d_entry.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
static void FlipSlashes(char *cp, size_t len)
{
@@ -434,12 +456,12 @@ _PR_MD_CLOSE_DIR(_MDDir *d)
{
if ( d ) {
if (FindClose(d->d_hdl)) {
- d->magic = (PRUint32)-1;
- return 0;
- } else {
- _PR_MD_MAP_CLOSEDIR_ERROR(GetLastError());
- return -1;
- }
+ d->magic = (PRUint32)-1;
+ return 0;
+ } else {
+ _PR_MD_MAP_CLOSEDIR_ERROR(GetLastError());
+ return -1;
+ }
}
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return -1;
@@ -472,7 +494,7 @@ _PR_MD_OPEN_DIR(_MDDir *d, const char *name)
d->d_hdl = FindFirstFileA( filename, &(d->d_entry) );
if ( d->d_hdl == INVALID_HANDLE_VALUE ) {
- _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
+ _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return PR_FAILURE;
}
d->firstEntry = PR_TRUE;
@@ -500,21 +522,24 @@ _PR_MD_READ_DIR(_MDDir *d, PRIntn flags)
}
fileName = GetFileFromDIR(d);
if ( (flags & PR_SKIP_DOT) &&
- (fileName[0] == '.') && (fileName[1] == '\0'))
- continue;
+ (fileName[0] == '.') && (fileName[1] == '\0')) {
+ continue;
+ }
if ( (flags & PR_SKIP_DOT_DOT) &&
(fileName[0] == '.') && (fileName[1] == '.') &&
- (fileName[2] == '\0'))
- continue;
- if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d))
- continue;
+ (fileName[2] == '\0')) {
+ continue;
+ }
+ if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d)) {
+ continue;
+ }
return fileName;
}
err = GetLastError();
PR_ASSERT(NO_ERROR != err);
- _PR_MD_MAP_READDIR_ERROR(err);
+ _PR_MD_MAP_READDIR_ERROR(err);
return NULL;
- }
+ }
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
@@ -525,7 +550,7 @@ _PR_MD_DELETE(const char *name)
if (DeleteFileA(name)) {
return 0;
} else {
- _PR_MD_MAP_DELETE_ERROR(GetLastError());
+ _PR_MD_MAP_DELETE_ERROR(GetLastError());
return -1;
}
}
@@ -602,7 +627,7 @@ _PR_MD_STAT(const char *fn, struct stat *info)
size_t len = strlen(fn);
if (len > 0 && len <= _MAX_PATH
- && IsPrevCharSlash(fn, fn + len)) {
+ && IsPrevCharSlash(fn, fn + len)) {
char newfn[_MAX_PATH + 1];
strcpy(newfn, fn);
@@ -624,8 +649,9 @@ IsPrevCharSlash(const char *str, const char *current)
{
const char *prev;
- if (str >= current)
+ if (str >= current) {
return PR_FALSE;
+ }
prev = _mbsdec(str, current);
return (prev == current - 1) && _PR_IS_SLASH(*prev);
}
@@ -660,7 +686,7 @@ IsRootDirectory(char *fn, size_t buflen)
}
if (isalpha(fn[0]) && fn[1] == ':' && _PR_IS_SLASH(fn[2])
- && fn[3] == '\0') {
+ && fn[3] == '\0') {
rv = GetDriveType(fn) > 1 ? PR_TRUE : PR_FALSE;
return rv;
}
@@ -723,7 +749,7 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
{
WIN32_FILE_ATTRIBUTE_DATA findFileData;
BOOL rv;
-
+
if (NULL == fn || '\0' == *fn) {
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return -1;
@@ -747,11 +773,11 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
_PR_FileTimeToPRTime(&findFileData.ftLastWriteTime, &info->modifyTime);
if (0 == findFileData.ftCreationTime.dwLowDateTime &&
- 0 == findFileData.ftCreationTime.dwHighDateTime) {
+ 0 == findFileData.ftCreationTime.dwHighDateTime) {
info->creationTime = info->modifyTime;
} else {
_PR_FileTimeToPRTime(&findFileData.ftCreationTime,
- &info->creationTime);
+ &info->creationTime);
}
return 0;
@@ -781,14 +807,16 @@ _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info)
rv = GetFileInformationByHandle((HANDLE)fd->secret->md.osfd, &hinfo);
if (rv == FALSE) {
- _PR_MD_MAP_FSTAT_ERROR(GetLastError());
+ _PR_MD_MAP_FSTAT_ERROR(GetLastError());
return -1;
- }
+ }
- if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_FILE;
+ }
info->size = hinfo.nFileSizeHigh;
info->size = (info->size << 32) + hinfo.nFileSizeLow;
@@ -824,15 +852,15 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
* ERROR_CALL_NOT_IMPLEMENTED error on Win95.
*/
rv = SetHandleInformation(
- (HANDLE)fd->secret->md.osfd,
- HANDLE_FLAG_INHERIT,
- inheritable ? HANDLE_FLAG_INHERIT : 0);
+ (HANDLE)fd->secret->md.osfd,
+ HANDLE_FLAG_INHERIT,
+ inheritable ? HANDLE_FLAG_INHERIT : 0);
if (0 == rv) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
return PR_FAILURE;
}
return PR_SUCCESS;
-}
+}
void
_PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported)
@@ -866,7 +894,7 @@ _PR_MD_RENAME(const char *from, const char *to)
if (MoveFileA(from, to)) {
return 0;
} else {
- _PR_MD_MAP_RENAME_ERROR(GetLastError());
+ _PR_MD_MAP_RENAME_ERROR(GetLastError());
return -1;
}
}
@@ -874,23 +902,24 @@ _PR_MD_RENAME(const char *from, const char *to)
PRInt32
_PR_MD_ACCESS(const char *name, PRAccessHow how)
{
-PRInt32 rv;
+ PRInt32 rv;
switch (how) {
- case PR_ACCESS_WRITE_OK:
- rv = _access(name, 02);
- break;
- case PR_ACCESS_READ_OK:
- rv = _access(name, 04);
- break;
- case PR_ACCESS_EXISTS:
- return _access(name, 00);
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
- if (rv < 0)
- _PR_MD_MAP_ACCESS_ERROR(errno);
+ case PR_ACCESS_WRITE_OK:
+ rv = _access(name, 02);
+ break;
+ case PR_ACCESS_READ_OK:
+ rv = _access(name, 04);
+ break;
+ case PR_ACCESS_EXISTS:
+ return _access(name, 00);
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
+ }
+ if (rv < 0) {
+ _PR_MD_MAP_ACCESS_ERROR(errno);
+ }
return rv;
}
@@ -901,7 +930,7 @@ _PR_MD_MKDIR(const char *name, PRIntn mode)
if (CreateDirectoryA(name, NULL)) {
return 0;
} else {
- _PR_MD_MAP_MKDIR_ERROR(GetLastError());
+ _PR_MD_MAP_MKDIR_ERROR(GetLastError());
return -1;
}
}
@@ -916,7 +945,7 @@ _PR_MD_MAKE_DIR(const char *name, PRIntn mode)
PACL pACL = NULL;
if (_PR_NT_MakeSecurityDescriptorACL(mode, dirAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -940,7 +969,7 @@ _PR_MD_RMDIR(const char *name)
if (RemoveDirectoryA(name)) {
return 0;
} else {
- _PR_MD_MAP_RMDIR_ERROR(GetLastError());
+ _PR_MD_MAP_RMDIR_ERROR(GetLastError());
return -1;
}
}
@@ -949,16 +978,16 @@ PRStatus
_PR_MD_LOCKFILE(PROsfd f)
{
PRStatus rc = PR_SUCCESS;
- DWORD rv;
+ DWORD rv;
- rv = LockFile( (HANDLE)f,
- 0l, 0l,
- 0x0l, 0xffffffffl );
- if ( rv == 0 ) {
+ rv = LockFile( (HANDLE)f,
+ 0l, 0l,
+ 0x0l, 0xffffffffl );
+ if ( rv == 0 ) {
DWORD err = GetLastError();
_PR_MD_MAP_DEFAULT_ERROR(err);
PR_LOG( _pr_io_lm, PR_LOG_ERROR,
- ("_PR_MD_LOCKFILE() failed. Error: %d", err ));
+ ("_PR_MD_LOCKFILE() failed. Error: %d", err ));
rc = PR_FAILURE;
}
@@ -976,30 +1005,32 @@ _PR_MD_TLOCKFILE(PROsfd f)
PRStatus
_PR_MD_UNLOCKFILE(PROsfd f)
{
- PRInt32 rv;
-
+ PRInt32 rv;
+
rv = UnlockFile( (HANDLE) f,
- 0l, 0l,
- 0x0l, 0xffffffffl );
-
+ 0l, 0l,
+ 0x0l, 0xffffffffl );
+
if ( rv )
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
else
{
- _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
- return PR_FAILURE;
+ _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+ return PR_FAILURE;
}
} /* end _PR_MD_UNLOCKFILE() */
PRInt32
_PR_MD_PIPEAVAILABLE(PRFileDesc *fd)
{
- if (NULL == fd)
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
- else
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ if (NULL == fd) {
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
+ }
+ else {
+ PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ }
return -1;
}
@@ -1045,7 +1076,7 @@ _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, int mode)
if (osflags & PR_CREATE_FILE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, fileAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -1053,25 +1084,34 @@ _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, int mode)
}
}
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
- if (osflags & PR_RDONLY || osflags & PR_RDWR)
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR)
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
access |= GENERIC_WRITE;
-
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ }
+
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
+ }
else if (osflags & PR_CREATE_FILE) {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = CREATE_ALWAYS;
- else
+ }
+ else {
flags = OPEN_ALWAYS;
+ }
} else {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = TRUNCATE_EXISTING;
- else
+ }
+ else {
flags = OPEN_EXISTING;
+ }
}
file = createFileW(name,
@@ -1088,10 +1128,10 @@ _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, int mode)
_PR_MD_MAP_OPEN_ERROR(GetLastError());
return -1;
}
-
+
return (PROsfd)file;
}
-
+
PRStatus
_PR_MD_OPEN_DIR_UTF16(_MDDirUTF16 *d, const PRUnichar *name)
{
@@ -1146,14 +1186,17 @@ _PR_MD_READ_DIR_UTF16(_MDDirUTF16 *d, PRIntn flags)
}
fileName = GetFileFromDIR(d);
if ( (flags & PR_SKIP_DOT) &&
- (fileName[0] == L'.') && (fileName[1] == L'\0'))
+ (fileName[0] == L'.') && (fileName[1] == L'\0')) {
continue;
+ }
if ( (flags & PR_SKIP_DOT_DOT) &&
(fileName[0] == L'.') && (fileName[1] == L'.') &&
- (fileName[2] == L'\0'))
+ (fileName[2] == L'\0')) {
continue;
- if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d))
+ }
+ if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d)) {
continue;
+ }
return fileName;
}
err = GetLastError();
@@ -1164,7 +1207,7 @@ _PR_MD_READ_DIR_UTF16(_MDDirUTF16 *d, PRIntn flags)
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
-
+
PRInt32
_PR_MD_CLOSE_DIR_UTF16(_MDDirUTF16 *d)
{
@@ -1213,7 +1256,7 @@ IsRootDirectoryW(PRUnichar *fn, size_t buflen)
}
if (iswalpha(fn[0]) && fn[1] == L':' && _PR_IS_W_SLASH(fn[2])
- && fn[3] == L'\0') {
+ && fn[3] == L'\0') {
rv = getDriveTypeW(fn) > 1 ? PR_TRUE : PR_FALSE;
return rv;
}
@@ -1312,9 +1355,9 @@ _PR_MD_GETFILEINFO64_UTF16(const PRUnichar *fn, PRFileInfo64 *info)
if (NULL == wcspbrk(fn, L".\\/")) {
_PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return -1;
- }
+ }
len = getFullPathNameW(fn, sizeof(pathbuf)/sizeof(pathbuf[0]), pathbuf,
- &filePart);
+ &filePart);
if (0 == len) {
_PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return -1;
@@ -1360,11 +1403,11 @@ _PR_MD_GETFILEINFO64_UTF16(const PRUnichar *fn, PRFileInfo64 *info)
_PR_FileTimeToPRTime(&findFileData.ftLastWriteTime, &info->modifyTime);
if (0 == findFileData.ftCreationTime.dwLowDateTime &&
- 0 == findFileData.ftCreationTime.dwHighDateTime) {
+ 0 == findFileData.ftCreationTime.dwHighDateTime) {
info->creationTime = info->modifyTime;
} else {
_PR_FileTimeToPRTime(&findFileData.ftCreationTime,
- &info->creationTime);
+ &info->creationTime);
}
return 0;
diff --git a/nsprpub/pr/src/md/windows/w95sock.c b/nsprpub/pr/src/md/windows/w95sock.c
index c6a3ec111..7d7362c60 100644
--- a/nsprpub/pr/src/md/windows/w95sock.c
+++ b/nsprpub/pr/src/md/windows/w95sock.c
@@ -14,7 +14,7 @@
#define CONNECT_FD 3
static PRInt32 socket_io_wait(
- PROsfd osfd,
+ PROsfd osfd,
PRInt32 fd_type,
PRIntervalTime timeout);
@@ -51,7 +51,7 @@ _PR_MD_SOCKET(int af, int type, int flags)
sock = socket(af, type, flags);
- if (sock == INVALID_SOCKET )
+ if (sock == INVALID_SOCKET )
{
_PR_MD_MAP_SOCKET_ERROR(WSAGetLastError());
return (PROsfd)sock;
@@ -101,8 +101,9 @@ _MD_CloseSocket(PROsfd osfd)
PRInt32 rv;
rv = closesocket((SOCKET) osfd );
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_CLOSE_ERROR(WSAGetLastError());
+ }
return rv;
}
@@ -120,8 +121,8 @@ _MD_SocketAvailable(PRFileDesc *fd)
}
PROsfd _MD_Accept(
- PRFileDesc *fd,
- PRNetAddr *raddr,
+ PRFileDesc *fd,
+ PRNetAddr *raddr,
PRUint32 *rlen,
PRIntervalTime timeout )
{
@@ -129,7 +130,7 @@ PROsfd _MD_Accept(
SOCKET sock;
PRInt32 rv, err;
- while ((sock = accept(osfd, (struct sockaddr *) raddr, rlen)) == -1)
+ while ((sock = accept(osfd, (struct sockaddr *) raddr, rlen)) == -1)
{
err = WSAGetLastError();
if ((err == WSAEWOULDBLOCK) && (!fd->secret->nonblocking))
@@ -149,14 +150,14 @@ PROsfd _MD_Accept(
} /* end _MD_accept() */
PRInt32
-_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
+_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
PRIntervalTime timeout)
{
PROsfd osfd = fd->secret->md.osfd;
PRInt32 rv;
int err;
- if ((rv = connect(osfd, (struct sockaddr *) addr, addrlen)) == -1)
+ if ((rv = connect(osfd, (struct sockaddr *) addr, addrlen)) == -1)
{
err = WSAGetLastError();
if ((!fd->secret->nonblocking) && (err == WSAEWOULDBLOCK))
@@ -171,7 +172,7 @@ _PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
PR_ASSERT(rv > 0);
/* it's connected */
return(0);
- }
+ }
}
_PR_MD_MAP_CONNECT_ERROR(err);
}
@@ -209,7 +210,7 @@ _PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog)
}
PRInt32
-_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
+_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PRIntervalTime timeout)
{
PROsfd osfd = fd->secret->md.osfd;
@@ -222,18 +223,18 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PR_ASSERT(PR_MSG_PEEK == flags);
osflags = MSG_PEEK;
}
- while ((rv = recv( osfd, buf, amount, osflags)) == -1)
+ while ((rv = recv( osfd, buf, amount, osflags)) == -1)
{
- if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
+ if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
rv = socket_io_wait(osfd, READ_FD, timeout);
if ( rv < 0 )
{
return -1;
- }
- }
- else
+ }
+ }
+ else
{
_PR_MD_MAP_RECV_ERROR(err);
break;
@@ -250,11 +251,11 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
PRInt32 rv, err;
PRInt32 bytesSent = 0;
- while(bytesSent < amount )
+ while(bytesSent < amount )
{
- while ((rv = send( osfd, buf, amount, 0 )) == -1)
+ while ((rv = send( osfd, buf, amount, 0 )) == -1)
{
- if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
+ if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
rv = socket_io_wait(osfd, WRITE_FD, timeout);
@@ -262,8 +263,8 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
{
return -1;
}
- }
- else
+ }
+ else
{
_PR_MD_MAP_SEND_ERROR(err);
return -1;
@@ -274,7 +275,7 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
{
break;
}
- if (bytesSent < amount)
+ if (bytesSent < amount)
{
rv = socket_io_wait(osfd, WRITE_FD, timeout);
if ( rv < 0 )
@@ -296,9 +297,9 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
do {
while ((rv = sendto( osfd, buf, amount, 0, (struct sockaddr *) addr,
- addrlen)) == -1)
+ addrlen)) == -1)
{
- if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
+ if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
rv = socket_io_wait(osfd, WRITE_FD, timeout);
@@ -306,8 +307,8 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
{
return -1;
}
- }
- else
+ }
+ else
{
_PR_MD_MAP_SENDTO_ERROR(err);
return -1;
@@ -318,10 +319,10 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
{
break;
}
- if (bytesSent < amount)
+ if (bytesSent < amount)
{
rv = socket_io_wait(osfd, WRITE_FD, timeout);
- if (rv < 0)
+ if (rv < 0)
{
return -1;
}
@@ -361,8 +362,9 @@ static PRStatus PR_CALLBACK _pr_set_connectex(void)
/* Dummy socket needed for WSAIoctl */
sock = socket(AF_INET, SOCK_STREAM, 0);
- if (sock == INVALID_SOCKET)
+ if (sock == INVALID_SOCKET) {
return PR_SUCCESS;
+ }
GUID guid = WSAID_CONNECTEX;
rc = WSAIoctl(sock, SIO_GET_EXTENSION_FUNCTION_POINTER,
@@ -446,7 +448,7 @@ _PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
if (rv != 0) {
err = WSAGetLastError();
PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("_PR_MD_TCPSENDTO setting SO_UPDATE_CONNECT_CONTEXT failed %d\n", err));
+ ("_PR_MD_TCPSENDTO setting SO_UPDATE_CONNECT_CONTEXT failed %d\n", err));
_PR_MD_MAP_SETSOCKOPT_ERROR(err);
return -1;
}
@@ -472,7 +474,7 @@ _PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
* them during Fast Open or after connect. Therefore we can assumed
* this data already send. */
if (amount > 0) {
- return amount;
+ return amount;
}
_PR_MD_MAP_CONNECT_ERROR(WSAEWOULDBLOCK);
@@ -510,18 +512,18 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PRInt32 rv, err;
while ((rv = recvfrom( osfd, buf, amount, 0, (struct sockaddr *) addr,
- addrlen)) == -1)
+ addrlen)) == -1)
{
- if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
+ if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
rv = socket_io_wait(osfd, READ_FD, timeout);
if ( rv < 0)
{
return -1;
- }
- }
- else
+ }
+ }
+ else
{
_PR_MD_MAP_RECVFROM_ERROR(err);
break;
@@ -537,12 +539,13 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTi
int sent = 0;
int rv;
- for (index=0; index < iov_size; index++)
+ for (index=0; index < iov_size; index++)
{
rv = _PR_MD_SEND(fd, iov[index].iov_base, iov[index].iov_len, 0, timeout);
- if (rv > 0)
+ if (rv > 0) {
sent += rv;
- if ( rv != iov[index].iov_len )
+ }
+ if ( rv != iov[index].iov_len )
{
if (rv < 0)
{
@@ -568,11 +571,12 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTi
PRInt32
_PR_MD_SHUTDOWN(PRFileDesc *fd, PRIntn how)
{
-PRInt32 rv;
+ PRInt32 rv;
rv = shutdown(fd->secret->md.osfd, how);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_SHUTDOWN_ERROR(WSAGetLastError());
+ }
return rv;
}
@@ -651,7 +655,7 @@ _MD_MakeNonblock(PRFileDesc *f)
#define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5
static PRInt32 socket_io_wait(
- PROsfd osfd,
+ PROsfd osfd,
PRInt32 fd_type,
PRIntervalTime timeout)
{
@@ -709,15 +713,17 @@ static PRInt32 socket_io_wait(
{
len = sizeof(err);
if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &len) == SOCKET_ERROR)
- {
+ (char *) &err, &len) == SOCKET_ERROR)
+ {
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return -1;
}
- if (err != 0)
+ if (err != 0) {
_PR_MD_MAP_CONNECT_ERROR(err);
- else
+ }
+ else {
PR_SetError(PR_UNKNOWN_ERROR, 0);
+ }
return -1;
}
if (FD_ISSET((SOCKET)osfd, &rd_wr))
@@ -754,8 +760,8 @@ static PRInt32 socket_io_wait(
tv.tv_usec = 0;
} else {
tv.tv_usec = PR_IntervalToMicroseconds(
- remaining -
- PR_SecondsToInterval(tv.tv_sec));
+ remaining -
+ PR_SecondsToInterval(tv.tv_sec));
}
FD_SET(osfd, &rd_wr);
FD_SET(osfd, &ex);
@@ -789,15 +795,17 @@ static PRInt32 socket_io_wait(
{
len = sizeof(err);
if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &len) == SOCKET_ERROR)
- {
+ (char *) &err, &len) == SOCKET_ERROR)
+ {
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return -1;
}
- if (err != 0)
+ if (err != 0) {
_PR_MD_MAP_CONNECT_ERROR(err);
- else
+ }
+ else {
PR_SetError(PR_UNKNOWN_ERROR, 0);
+ }
return -1;
}
if (FD_ISSET((SOCKET)osfd, &rd_wr))
@@ -822,8 +830,8 @@ static PRInt32 socket_io_wait(
if (wait_for_remaining) {
elapsed = remaining;
} else {
- elapsed = PR_SecondsToInterval(tv.tv_sec)
- + PR_MicrosecondsToInterval(tv.tv_usec);
+ elapsed = PR_SecondsToInterval(tv.tv_sec)
+ + PR_MicrosecondsToInterval(tv.tv_usec);
}
if (elapsed >= remaining) {
PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
diff --git a/nsprpub/pr/src/md/windows/w95thred.c b/nsprpub/pr/src/md/windows/w95thred.c
index a365411f5..fb9c457d7 100644
--- a/nsprpub/pr/src/md/windows/w95thred.c
+++ b/nsprpub/pr/src/md/windows/w95thred.c
@@ -25,7 +25,7 @@ DWORD _pr_currentThreadIndex;
DWORD _pr_lastThreadIndex;
DWORD _pr_currentCPUIndex;
#endif
-int _pr_intsOff = 0;
+int _pr_intsOff = 0;
_PRInterruptTable _pr_interruptTable[] = { { 0 } };
typedef HRESULT (WINAPI *SETTHREADDESCRIPTION)(HANDLE, PCWSTR);
@@ -51,8 +51,8 @@ _PR_MD_EARLY_INIT()
if (hModule) {
sSetThreadDescription =
(SETTHREADDESCRIPTION) GetProcAddress(
- hModule,
- "SetThreadDescription");
+ hModule,
+ "SetThreadDescription");
}
}
@@ -108,13 +108,13 @@ _PR_MD_INIT_THREAD(PRThread *thread)
** the pseudo handle via DuplicateHandle(...)
*/
BOOL ok = 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 */
if (!ok) {
return PR_FAILURE;
}
@@ -124,10 +124,12 @@ _PR_MD_INIT_THREAD(PRThread *thread)
/* Create the blocking IO semaphore */
thread->md.blocked_sema = CreateSemaphore(NULL, 0, 1, NULL);
- if (thread->md.blocked_sema == NULL)
+ if (thread->md.blocked_sema == NULL) {
return PR_FAILURE;
- else
- return PR_SUCCESS;
+ }
+ else {
+ return PR_SUCCESS;
+ }
}
static unsigned __stdcall
@@ -138,23 +140,23 @@ pr_root(void *arg)
return 0;
}
-PRStatus
-_PR_MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+PRStatus
+_PR_MD_CREATE_THREAD(PRThread *thread,
+ 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) {
return PR_FAILURE;
}
@@ -169,20 +171,21 @@ _PR_MD_CREATE_THREAD(PRThread *thread,
}
/* Activate the thread */
- if ( ResumeThread( thread->md.handle ) != -1)
+ if ( ResumeThread( thread->md.handle ) != -1) {
return PR_SUCCESS;
+ }
return PR_FAILURE;
}
-void
+void
_PR_MD_YIELD(void)
{
/* Can NT really yield at all? */
Sleep(0);
}
-void
+void
_PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
{
int nativePri;
@@ -209,8 +212,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;
}
@@ -220,10 +223,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)
@@ -231,32 +234,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
}
@@ -317,16 +321,17 @@ PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask)
DWORD_PTR system_mask;
rv = GetProcessAffinityMask(GetCurrentProcess(),
- &process_mask, &system_mask);
- if (rv)
+ &process_mask, &system_mask);
+ if (rv) {
*mask = (PRUint32)process_mask;
+ }
return rv?0:-1;
#endif
}
-void
-_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
+void
+_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
{
_PR_MD_SUSPEND_THREAD(cpu->thread);
}
@@ -363,14 +368,14 @@ _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;
}
diff --git a/nsprpub/pr/src/md/windows/win32_errors.c b/nsprpub/pr/src/md/windows/win32_errors.c
index 275792187..b0118146b 100644
--- a/nsprpub/pr/src/md/windows/win32_errors.c
+++ b/nsprpub/pr/src/md/windows/win32_errors.c
@@ -13,7 +13,7 @@
* - GetLastError(): for Win32 functions
* - WSAGetLastError(): for Winsock functions
* - errno: for standard C library functions
- *
+ *
* GetLastError() and WSAGetLastError() return error codes in
* non-overlapping ranges, so their error codes (ERROR_* and
* WSAE*) can be mapped by the same function. On the other hand,
@@ -61,7 +61,7 @@ void _MD_win32_map_default_error(PRInt32 err)
prError = PR_NOT_IMPLEMENTED_ERROR;
break;
case ERROR_DISK_CORRUPT:
- prError = PR_IO_ERROR;
+ prError = PR_IO_ERROR;
break;
case ERROR_DISK_FULL:
prError = PR_NO_DEVICE_SPACE_ERROR;
@@ -518,7 +518,7 @@ void _MD_win32_map_gethostname_error(PRInt32 err)
}
/* Win32 select() only works on sockets. So in this
-** context, WSAENOTSOCK is equivalent to EBADF on Unix.
+** context, WSAENOTSOCK is equivalent to EBADF on Unix.
*/
void _MD_win32_map_select_error(PRInt32 err)
{