blob: 3da7a3dc6fad8bb7440a895bb05fbb3d2a881cb3 [file] [log] [blame]
Eric Laurent82f5b812016-08-17 13:53:12 +02001/*
2 * Copyright (C) 2016 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#define LOG_TAG "LockWatch"
18//#define LOG_NDEBUG 0
19
20#include <utils/Log.h>
21#include "LockWatch.h"
22
23namespace android {
24
25void LockWatch::onFirstRef()
26{
27 run("lock watch", ANDROID_PRIORITY_URGENT_AUDIO);
28}
29
30bool LockWatch::threadLoop()
31{
32 while (!exitPending()) {
33 // we neglect previous lock time effect on period
34 usleep(mPeriodMs * 1000);
Andy Hung51a63192016-08-23 18:29:04 -070035 if (mLock.timedLock(ms2ns(mTimeOutMs)) != NO_ERROR) {
36 // FIXME: Current implementation of timedLock uses CLOCK_REALTIME which
37 // increments even during CPU suspend. Check twice to be sure.
38 if (mLock.timedLock(ms2ns(mTimeOutMs)) != NO_ERROR) {
39 LOG_ALWAYS_FATAL("LockWatch timeout for: %s", mTag.string());
40 }
Eric Laurent82f5b812016-08-17 13:53:12 +020041 }
42 mLock.unlock();
43 }
44 return false;
45}
46
47} // namespace android
48