blob: 64db5f07b106cc0b32bf4b0047df99e9e019caa6 [file] [log] [blame]
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001/*
2 * Copyright 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#include "Event.h"
18
19using namespace android;
Robert Delgadocb129942019-07-23 16:28:20 -070020using Increment = surfaceflinger::Increment;
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -070021
22Event::Event(Increment::IncrementCase type) : mIncrementType(type) {}
23
24void Event::readyToExecute() {
25 changeState(Event::EventState::Waiting);
26 waitUntil(Event::EventState::Signaled);
27 changeState(Event::EventState::Running);
28}
29
30void Event::complete() {
31 waitUntil(Event::EventState::Waiting);
32 changeState(Event::EventState::Signaled);
33 waitUntil(Event::EventState::Running);
34}
35
36void Event::waitUntil(Event::EventState state) {
37 std::unique_lock<std::mutex> lock(mLock);
38 mCond.wait(lock, [this, state] { return (mState == state); });
39}
40
41void Event::changeState(Event::EventState state) {
42 std::unique_lock<std::mutex> lock(mLock);
43 mState = state;
44 lock.unlock();
45
46 mCond.notify_one();
47}
48
49Increment::IncrementCase Event::getIncrementType() {
50 return mIncrementType;
51}