Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: terminator.h

Issue 5104007: AU: Add unit tests for the Terminator class. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: unnecessary header file Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « SConstruct ('k') | terminator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_TERMINATOR_H__ 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_TERMINATOR_H__
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_TERMINATOR_H__ 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_TERMINATOR_H__
7 7
8 #include <signal.h> 8 #include <signal.h>
9 9
10 #include <gtest/gtest_prod.h> // for FRIEND_TEST
11
10 namespace chromeos_update_engine { 12 namespace chromeos_update_engine {
11 13
12 // A class allowing graceful delayed exit. 14 // A class allowing graceful delayed exit.
13 class Terminator { 15 class Terminator {
14 public: 16 public:
15 // Initializes the terminator and sets up signal handlers. 17 // Initializes the terminator and sets up signal handlers.
16 static void Init(); 18 static void Init();
17 19
18 // Terminates the current process. 20 // Terminates the current process.
19 static void Exit(); 21 static void Exit();
20 22
21 // Set to true if the terminator should block termination requests in an 23 // Set to true if the terminator should block termination requests in an
22 // attempt to block exiting. 24 // attempt to block exiting.
23 static void set_exit_blocked(bool block) { exit_blocked_ = block ? 1 : 0; } 25 static void set_exit_blocked(bool block) { exit_blocked_ = block ? 1 : 0; }
26 static bool exit_blocked() { return exit_blocked_ != 0; }
24 27
25 // Returns true if the system is trying to terminate the process, false 28 // Returns true if the system is trying to terminate the process, false
26 // otherwise. Returns true only if exit was blocked when the termination 29 // otherwise. Returns true only if exit was blocked when the termination
27 // request arrived. 30 // request arrived.
28 static bool exit_requested() { return exit_requested_ != 0; } 31 static bool exit_requested() { return exit_requested_ != 0; }
29 32
30 private: 33 private:
34 FRIEND_TEST(TerminatorTest, HandleSignalTest);
35 FRIEND_TEST(TerminatorDeathTest, ScopedTerminatorExitUnblockerExitTest);
36
31 // The signal handler. 37 // The signal handler.
32 static void HandleSignal(int signum); 38 static void HandleSignal(int signum);
33 39
34 static volatile sig_atomic_t exit_blocked_; 40 static volatile sig_atomic_t exit_blocked_;
35 static volatile sig_atomic_t exit_requested_; 41 static volatile sig_atomic_t exit_requested_;
36 }; 42 };
37 43
38 class ScopedTerminatorExitUnblocker { 44 class ScopedTerminatorExitUnblocker {
39 public: 45 public:
40 ~ScopedTerminatorExitUnblocker(); 46 ~ScopedTerminatorExitUnblocker();
41 }; 47 };
42 48
43 } // namespace chromeos_update_engine 49 } // namespace chromeos_update_engine
44 50
45 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_TERMINATOR_H__ 51 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_TERMINATOR_H__
OLDNEW
« no previous file with comments | « SConstruct ('k') | terminator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698