1ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy/* 2ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * Copyright (C) 2013 The Android Open Source Project 3ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * 4ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * Licensed under the Apache License, Version 2.0 (the "License"); 5ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * you may not use this file except in compliance with the License. 6ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * You may obtain a copy of the License at 7ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * 8ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * http://www.apache.org/licenses/LICENSE-2.0 9ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * 10ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * Unless required by applicable law or agreed to in writing, software 11ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * distributed under the License is distributed on an "AS IS" BASIS, 12ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * See the License for the specific language governing permissions and 14ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy * limitations under the License. 15ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy */ 16ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy 17ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy#ifndef ANDROID_HWUI_SIGNAL_H 18ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy#define ANDROID_HWUI_SIGNAL_H 19ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy 20ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy#include <stdint.h> 21ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy#include <sys/types.h> 22ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy#include <utils/threads.h> 23ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy 24ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guynamespace android { 25ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guynamespace uirenderer { 26ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy 27ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guyclass Signal { 28ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guypublic: 29faecb78a6b11c780db47bc940ca7662899ab5d5eChih-Hung Hsieh explicit Signal(Condition::WakeUpType type = Condition::WAKE_UP_ALL) : mType(type), mSignaled(false) { } 30ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy ~Signal() { } 31ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy 32ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy void signal() { 33bf29ee2a49cfa6e87e535dcb1476ff1336f8bdf9John Reck { 34bf29ee2a49cfa6e87e535dcb1476ff1336f8bdf9John Reck Mutex::Autolock l(mLock); 35bf29ee2a49cfa6e87e535dcb1476ff1336f8bdf9John Reck mSignaled = true; 36bf29ee2a49cfa6e87e535dcb1476ff1336f8bdf9John Reck } 37ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy mCondition.signal(mType); 38ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy } 39ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy 40ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy void wait() { 41ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy Mutex::Autolock l(mLock); 42ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy while (!mSignaled) { 43ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy mCondition.wait(mLock); 44ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy } 45ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy mSignaled = false; 46ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy } 47ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy 48ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guyprivate: 49ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy Condition::WakeUpType mType; 50ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy volatile bool mSignaled; 51ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy mutable Mutex mLock; 52ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy mutable Condition mCondition; 53ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy}; 54ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy 55ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy}; // namespace uirenderer 56ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy}; // namespace android 57ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy 58ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy#endif // ANDROID_HWUI_SIGNAL_H 59