diff options
author | Andreas Huber <andih@google.com> | 2011-01-26 11:19:19 -0800 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2011-01-26 11:20:42 -0800 |
commit | 01f394247f3d5851f5bb12c2786b5fee265b6357 (patch) | |
tree | 8fb13813062b563324f9b47f4f9741897fde7f98 /include | |
parent | b656f3592332cebfad8944e8692003cf3688d586 (diff) | |
download | frameworks_av-01f394247f3d5851f5bb12c2786b5fee265b6357.zip frameworks_av-01f394247f3d5851f5bb12c2786b5fee265b6357.tar.gz frameworks_av-01f394247f3d5851f5bb12c2786b5fee265b6357.tar.bz2 |
Protect notification callback parameters with a mutex.
This avoids the race condition where notifications are dispatched to a NULL receiver
after notifications have been disabled.
Change-Id: I6d351ffbee97616e2c35559c132a6c5e6a66948a
related-to-bug: 3394139
Diffstat (limited to 'include')
-rw-r--r-- | include/media/MediaPlayerInterface.h | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h index c0963a6..048f041 100644 --- a/include/media/MediaPlayerInterface.h +++ b/include/media/MediaPlayerInterface.h @@ -126,8 +126,6 @@ public: virtual status_t setLooping(int loop) = 0; virtual player_type playerType() = 0; - virtual void setNotifyCallback(void* cookie, notify_callback_f notifyFunc) { - mCookie = cookie; mNotify = notifyFunc; } // Invoke a generic method on the player by using opaque parcels // for the request and reply. // @@ -149,9 +147,21 @@ public: return INVALID_OPERATION; }; - virtual void sendEvent(int msg, int ext1=0, int ext2=0) { if (mNotify) mNotify(mCookie, msg, ext1, ext2); } + void setNotifyCallback( + void* cookie, notify_callback_f notifyFunc) { + Mutex::Autolock autoLock(mNotifyLock); + mCookie = cookie; mNotify = notifyFunc; + } -protected: + void sendEvent(int msg, int ext1=0, int ext2=0) { + Mutex::Autolock autoLock(mNotifyLock); + if (mNotify) mNotify(mCookie, msg, ext1, ext2); + } + +private: + friend class MediaPlayerService; + + Mutex mNotifyLock; void* mCookie; notify_callback_f mNotify; }; |