• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_RUNTIME_SIGNAL_SET_H_
18 #define ART_RUNTIME_SIGNAL_SET_H_
19 
20 #include <signal.h>
21 
22 #include <android-base/logging.h>
23 
24 namespace art {
25 
26 class SignalSet {
27  public:
SignalSet()28   SignalSet() {
29     if (sigemptyset(&set_) == -1) {
30       PLOG(FATAL) << "sigemptyset failed";
31     }
32   }
33 
Add(int signal)34   void Add(int signal) {
35     if (sigaddset(&set_, signal) == -1) {
36       PLOG(FATAL) << "sigaddset " << signal << " failed";
37     }
38   }
39 
Block()40   void Block() {
41     if (pthread_sigmask(SIG_BLOCK, &set_, nullptr) != 0) {
42       PLOG(FATAL) << "pthread_sigmask failed";
43     }
44   }
45 
Wait()46   int Wait() {
47     // Sleep in sigwait() until a signal arrives. gdb causes EINTR failures.
48     int signal_number;
49     int rc = TEMP_FAILURE_RETRY(sigwait(&set_, &signal_number));
50     if (rc != 0) {
51       PLOG(FATAL) << "sigwait failed";
52     }
53     return signal_number;
54   }
55 
56  private:
57   sigset_t set_;
58 };
59 
60 }  // namespace art
61 
62 #endif  // ART_RUNTIME_SIGNAL_SET_H_
63