Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/threads/ThreadDelay.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#include "mozilla/Assertions.h"
8
#include "mozilla/ChaosMode.h"
9
10
#if defined(XP_WIN)
11
#include <windows.h>
12
#else
13
#include <unistd.h>
14
#endif
15
16
namespace mozilla {
17
18
void
19
DelayForChaosMode(ChaosFeature aFeature, const uint32_t aMicrosecondLimit)
20
156
{
21
156
  if (!ChaosMode::isActive(aFeature)) {
22
156
    return;
23
156
  }
24
0
25
0
  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 anything
30
  // here for now until we have found a good way to sleep more precisely here.
31
#else
32
  const uint32_t duration = ChaosMode::randomUint32LessThan(aMicrosecondLimit);
33
0
  ::usleep(duration);
34
0
#endif
35
0
}
36
37
} // namespace mozilla