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:
29ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy    Signal(Condition::WakeUpType type = Condition::WAKE_UP_ALL) : mType(type), mSignaled(false) { }
30ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy    ~Signal() { }
31ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy
32ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy    void signal() {
33ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy        Mutex::Autolock l(mLock);
34ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy        mSignaled = true;
35ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy        mCondition.signal(mType);
36ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy    }
37ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy
38ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy    void wait() {
39ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy        Mutex::Autolock l(mLock);
40ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy        while (!mSignaled) {
41ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy            mCondition.wait(mLock);
42ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy        }
43ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy        mSignaled = false;
44ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy    }
45ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy
46ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guyprivate:
47ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy    Condition::WakeUpType mType;
48ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy    volatile bool mSignaled;
49ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy    mutable Mutex mLock;
50ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy    mutable Condition mCondition;
51ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy};
52ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy
53ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy}; // namespace uirenderer
54ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy}; // namespace android
55ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy
56ca89e2a68703bd428e8b66547d033a6ed35b3595Romain Guy#endif // ANDROID_HWUI_SIGNAL_H
57