Bug 1325986 - Use ScopeExit in a few more places, r=luke,lth

--HG--
extra : rebase_source : eb5bc132b01a6114b493d68f02e1e2b5f6ee7cf6
extra : amend_source : 4c0761ab650a3a44ce4615f4cec563b51d115d67
This commit is contained in:
Steve Fink 2015-08-27 15:53:52 -07:00
parent d233e8d386
commit bd752b7e5b
2 changed files with 21 additions and 19 deletions

View File

@ -50,6 +50,7 @@
#include "mozilla/Atomics.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/Maybe.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/Unused.h"
#include "jsapi.h"
@ -972,6 +973,11 @@ js::FutexRuntime::wait(JSContext* cx, js::UniqueLock<js::Mutex>& locked,
return false;
}
// Go back to Idle after returning.
auto onFinish = mozilla::MakeScopeExit([&] {
state_ = Idle;
});
const bool isTimed = timeout.isSome();
auto finalEnd = timeout.map([](mozilla::TimeDuration& timeout) {
@ -983,8 +989,6 @@ js::FutexRuntime::wait(JSContext* cx, js::UniqueLock<js::Mutex>& locked,
// work cross-platform.
auto maxSlice = mozilla::TimeDuration::FromSeconds(4000.0);
bool retval = true;
for (;;) {
// If we are doing a timed wait, calculate the end time for this wait
// slice.
@ -1010,14 +1014,14 @@ js::FutexRuntime::wait(JSContext* cx, js::UniqueLock<js::Mutex>& locked,
auto now = mozilla::TimeStamp::Now();
if (now >= *finalEnd) {
*result = FutexTimedOut;
goto finished;
return true;
}
}
break;
case FutexRuntime::Woken:
*result = FutexOK;
goto finished;
return true;
case FutexRuntime::WaitingNotifiedForInterrupt:
// The interrupt handler may reenter the engine. In that case
@ -1052,13 +1056,12 @@ js::FutexRuntime::wait(JSContext* cx, js::UniqueLock<js::Mutex>& locked,
state_ = WaitingInterrupted;
{
UnlockGuard<Mutex> unlock(locked);
retval = cx->runtime()->handleInterrupt(cx);
if (!cx->runtime()->handleInterrupt(cx))
return false;
}
if (!retval)
goto finished;
if (state_ == Woken) {
*result = FutexOK;
goto finished;
return true;
}
break;
@ -1066,9 +1069,6 @@ js::FutexRuntime::wait(JSContext* cx, js::UniqueLock<js::Mutex>& locked,
MOZ_CRASH("Bad FutexState in wait()");
}
}
finished:
state_ = Idle;
return retval;
}
void

View File

@ -20,6 +20,7 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/PodOperations.h"
#include "mozilla/ScopeExit.h"
#include "jit/AtomicOperations.h"
#include "jit/Disassembler.h"
@ -1075,17 +1076,21 @@ MachExceptionHandler::install(JSRuntime* rt)
kern_return_t kret;
mach_port_t thread;
auto onFailure = mozilla::MakeScopeExit([] {
uninstall();
});
// Get a port which can send and receive data.
kret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port_);
if (kret != KERN_SUCCESS)
goto error;
return false;
kret = mach_port_insert_right(mach_task_self(), port_, port_, MACH_MSG_TYPE_MAKE_SEND);
if (kret != KERN_SUCCESS)
goto error;
return false;
// Create a thread to block on reading port_.
if (!thread_.init(MachExceptionHandlerThread, rt))
goto error;
return false;
// Direct exceptions on this thread to port_ (and thus our handler thread).
// Note: we are totally clobbering any existing *thread* exception ports and
@ -1100,14 +1105,11 @@ MachExceptionHandler::install(JSRuntime* rt)
THREAD_STATE_NONE);
mach_port_deallocate(mach_task_self(), thread);
if (kret != KERN_SUCCESS)
goto error;
return false;
installed_ = true;
onFailure.release();
return true;
error:
uninstall();
return false;
}
#else // If not Windows or Mac, assume Unix