Bug 1755481: correct documentation of `nsIClipboard::getData`. r=mccr8
[gecko.git] / xpcom / threads / ThreadDelay.cpp
blob1c38e255100b2fdeb385b5fb1c94338ce0747357
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "ThreadDelay.h"
8 #include "mozilla/Assertions.h"
9 #include "mozilla/ChaosMode.h"
11 #if defined(XP_WIN)
12 # include <windows.h>
13 #else
14 # include <unistd.h>
15 #endif
17 namespace mozilla {
19 void DelayForChaosMode(ChaosFeature aFeature,
20 const uint32_t aMicrosecondLimit) {
21 if (!ChaosMode::isActive(aFeature)) {
22 return;
25 MOZ_ASSERT(aMicrosecondLimit <= 1000);
26 #if defined(XP_WIN)
27 // Windows doesn't support sleeping at less than millisecond resolution.
28 // We could spin here, or we could just sleep for one millisecond.
29 // Sleeping for a full millisecond causes heavy delays, so we don't do
30 // anything here for now until we have found a good way to sleep more
31 // precisely here.
32 #else
33 const uint32_t duration = ChaosMode::randomUint32LessThan(aMicrosecondLimit);
34 ::usleep(duration);
35 #endif
38 } // namespace mozilla