diff options
author | 2017-05-17 18:15:15 -0700 | |
---|---|---|
committer | 2017-05-17 18:27:26 -0700 | |
commit | 5577d39c380c63ad02a5ca2d7cc5f08c3ebee533 (patch) | |
tree | fbe99483740cebb34f35472a53c0fdf033035bfd /services/displayservice/DisplayEventReceiver.cpp | |
parent | 5c580eaeb6510fee596825d2435182cf9895ae10 (diff) |
Fix race condition in displayservice.
Also addressed a couple of format nits and added copyright headers.
Note, this race condition wouldn't have occured as is because the
service is only being served on one thread.
Test: no race condition still
Bug: 38311538
Change-Id: I7516c800eb89280a16468934677fa978daa5dcec
Diffstat (limited to 'services/displayservice/DisplayEventReceiver.cpp')
-rw-r--r-- | services/displayservice/DisplayEventReceiver.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/services/displayservice/DisplayEventReceiver.cpp b/services/displayservice/DisplayEventReceiver.cpp index a7fd3c5cba..5993e443e6 100644 --- a/services/displayservice/DisplayEventReceiver.cpp +++ b/services/displayservice/DisplayEventReceiver.cpp @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #define LOG_TAG "libdisplayservicehidl" #include <displayservice/DisplayEventReceiver.h> @@ -43,12 +44,14 @@ sp<Looper> getLooper() { return looper; } -DisplayEventReceiver::AttachedEvent::AttachedEvent(const sp<IEventCallback> &callback) : mCallback(callback) { +DisplayEventReceiver::AttachedEvent::AttachedEvent(const sp<IEventCallback> &callback) + : mCallback(callback) +{ mLooperAttached = getLooper()->addFd(mFwkReceiver.getFd(), - Looper::POLL_CALLBACK, - Looper::EVENT_INPUT, - this, - nullptr); + Looper::POLL_CALLBACK, + Looper::EVENT_INPUT, + this, + nullptr); } DisplayEventReceiver::AttachedEvent::~AttachedEvent() { @@ -86,7 +89,7 @@ int DisplayEventReceiver::AttachedEvent::handleEvent(int fd, int events, void* / return 1; // keep the callback } - const static size_t SIZE = 1; + constexpr size_t SIZE = 1; ssize_t n; FwkReceiver::Event buf[SIZE]; @@ -149,11 +152,11 @@ Return<Status> DisplayEventReceiver::requestNextVsync() { } Return<Status> DisplayEventReceiver::close() { + std::unique_lock<std::mutex> lock(mMutex); if (mAttached == nullptr) { return Status::BAD_VALUE; } - std::unique_lock<std::mutex> lock(mMutex); bool success = mAttached->detach(); mAttached = nullptr; |