1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef SANDBOX_LINUX_SERVICES_THREAD_HELPERS_H_
6 #define SANDBOX_LINUX_SERVICES_THREAD_HELPERS_H_
8 #include "base/macros.h"
9 #include "sandbox/sandbox_export.h"
11 namespace base
{ class Thread
; }
15 class SANDBOX_EXPORT ThreadHelpers
{
17 // Checks whether the current process is single threaded. |proc_fd|
18 // must be a file descriptor to /proc/ and remains owned by the
20 static bool IsSingleThreaded(int proc_fd
);
21 static bool IsSingleThreaded();
23 // Crashes if the current process is not single threaded. This will wait
24 // on /proc to be updated. In the case where this doesn't crash, this will
25 // return promptly. In the case where this does crash, this will first wait
26 // for a few ms in Debug mode, a few seconds in Release mode.
27 static void AssertSingleThreaded(int proc_fd
);
28 static void AssertSingleThreaded();
30 // Starts |thread| and ensure that it has an entry in /proc/self/task/ from
31 // the point of view of the current thread.
32 static bool StartThreadAndWatchProcFS(int proc_fd
, base::Thread
* thread
);
34 // Stops |thread| and ensure that it does not have an entry in
35 // /proc/self/task/ from the point of view of the current thread. This is
36 // the way to stop threads before calling IsSingleThreaded().
37 static bool StopThreadAndWatchProcFS(int proc_fd
, base::Thread
* thread
);
39 static const char* GetAssertSingleThreadedErrorMessageForTests();
42 DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadHelpers
);
45 } // namespace sandbox
47 #endif // SANDBOX_LINUX_SERVICES_THREAD_HELPERS_H_