Florian Mayer | b433400 | 2018-02-01 11:10:36 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | #include "perfetto/base/watchdog.h" |
| 18 | |
| 19 | #include "perfetto/base/logging.h" |
| 20 | |
| 21 | #include <signal.h> |
| 22 | #include <stdint.h> |
| 23 | |
| 24 | namespace perfetto { |
| 25 | namespace base { |
| 26 | |
| 27 | WatchDog::WatchDog(time_t millisecs) { |
| 28 | struct sigevent sev; |
| 29 | sev.sigev_notify = SIGEV_SIGNAL; |
| 30 | sev.sigev_signo = SIGABRT; |
| 31 | sev.sigev_value.sival_ptr = &timerid_; |
| 32 | PERFETTO_CHECK(timer_create(CLOCK_MONOTONIC, &sev, &timerid_) != -1); |
| 33 | struct itimerspec its; |
| 34 | its.it_value.tv_sec = millisecs / 1000; |
| 35 | its.it_value.tv_nsec = 1000000L * (millisecs % 1000); |
| 36 | its.it_interval.tv_sec = 0; |
| 37 | its.it_interval.tv_nsec = 0; |
| 38 | PERFETTO_CHECK(timer_settime(timerid_, 0, &its, nullptr) != -1); |
| 39 | } |
| 40 | |
| 41 | WatchDog::~WatchDog() { |
| 42 | PERFETTO_CHECK(timer_delete(timerid_) != -1); |
| 43 | } |
| 44 | |
| 45 | } // namespace base |
| 46 | } // namespace perfetto |