| Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
|  | 19 | using namespace android; | 
| Robert Delgado | cb12994 | 2019-07-23 16:28:20 -0700 | [diff] [blame] | 20 | using Increment = surfaceflinger::Increment; | 
| Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 21 |  | 
|  | 22 | Event::Event(Increment::IncrementCase type) : mIncrementType(type) {} | 
|  | 23 |  | 
|  | 24 | void Event::readyToExecute() { | 
|  | 25 | changeState(Event::EventState::Waiting); | 
|  | 26 | waitUntil(Event::EventState::Signaled); | 
|  | 27 | changeState(Event::EventState::Running); | 
|  | 28 | } | 
|  | 29 |  | 
|  | 30 | void Event::complete() { | 
|  | 31 | waitUntil(Event::EventState::Waiting); | 
|  | 32 | changeState(Event::EventState::Signaled); | 
|  | 33 | waitUntil(Event::EventState::Running); | 
|  | 34 | } | 
|  | 35 |  | 
|  | 36 | void Event::waitUntil(Event::EventState state) { | 
|  | 37 | std::unique_lock<std::mutex> lock(mLock); | 
|  | 38 | mCond.wait(lock, [this, state] { return (mState == state); }); | 
|  | 39 | } | 
|  | 40 |  | 
|  | 41 | void 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 |  | 
|  | 49 | Increment::IncrementCase Event::getIncrementType() { | 
|  | 50 | return mIncrementType; | 
|  | 51 | } |