2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "SurfaceFlingerSynchro"
25 #include <sys/types.h>
28 #include <utils/IPCThreadState.h>
29 #include <utils/Log.h>
31 #include <private/ui/SurfaceFlingerSynchro.h>
35 // ---------------------------------------------------------------------------
37 SurfaceFlingerSynchro::Barrier::Barrier()
41 SurfaceFlingerSynchro::Barrier::~Barrier() {
44 void SurfaceFlingerSynchro::Barrier::open() {
45 asm volatile ("":::"memory");
46 Mutex::Autolock _l(lock);
51 void SurfaceFlingerSynchro::Barrier::close() {
52 Mutex::Autolock _l(lock);
56 void SurfaceFlingerSynchro::Barrier::waitAndClose()
58 Mutex::Autolock _l(lock);
59 while (state == CLOSED) {
60 // we're about to wait, flush the binder command buffer
61 IPCThreadState::self()->flushCommands();
67 status_t SurfaceFlingerSynchro::Barrier::waitAndClose(nsecs_t timeout)
69 Mutex::Autolock _l(lock);
70 while (state == CLOSED) {
71 // we're about to wait, flush the binder command buffer
72 IPCThreadState::self()->flushCommands();
73 int err = cv.waitRelative(lock, timeout);
81 // ---------------------------------------------------------------------------
83 SurfaceFlingerSynchro::SurfaceFlingerSynchro(const sp<ISurfaceComposer>& flinger)
84 : mSurfaceComposer(flinger)
88 SurfaceFlingerSynchro::SurfaceFlingerSynchro()
92 SurfaceFlingerSynchro::~SurfaceFlingerSynchro()
96 status_t SurfaceFlingerSynchro::signal()
98 mSurfaceComposer->signal();
102 status_t SurfaceFlingerSynchro::wait()
104 mBarrier.waitAndClose();
108 status_t SurfaceFlingerSynchro::wait(nsecs_t timeout)
111 return SurfaceFlingerSynchro::wait();
112 return mBarrier.waitAndClose(timeout);
115 void SurfaceFlingerSynchro::open()
120 // ---------------------------------------------------------------------------
122 }; // namespace android