AutoMutex _l(mLock)
http://www.baidu.com/s?wd=android+AutoMutex&ie=UTF-8D:\linux\linuxkernel\src\cm10.1\frameworks\base\services\jni\com_android_server_input_InputManagerService.cppNativeInputManager::NativeInputMana
http://www.baidu.com/s?wd=android+AutoMutex&ie=UTF-8
http://blog.csdn.net/evilcode/article/details/8291934
http://blog.csdn.net/batoom/article/details/8314144
AutoMutex is defined in D:\linux\linuxkernel\src\cm10.1\frameworks\native\include\utils\Mutex.h
/*
* Automatic mutex. Declare one of these at the top of a function.
* When the function returns, it will go out of scope, and release the
* mutex.
*/
typedef Mutex::Autolock AutoMutex;
// Manages the mutex automatically. It'll be locked when Autolock is
// constructed and released when Autolock goes out of scope.
class Autolock {
public:
inline Autolock(Mutex& mutex) : mLock(mutex) { mLock.lock(); }
inline Autolock(Mutex* mutex) : mLock(*mutex) { mLock.lock(); }
inline ~Autolock() { mLock.unlock(); }
private:
Mutex& mLock;
};
example:
D:\linux\linuxkernel\src\cm10.1\frameworks\av\include\media\IMediaDeathNotifier.h
class IMediaDeathNotifier: virtual public RefBase
{
static Mutex sServiceLock;
D:\linux\linuxkernel\src\cm10.1\frameworks\av\media\libmedia\IMediaDeathNotifier.cpp
// client singleton for binder interface to services
Mutex IMediaDeathNotifier::sServiceLock;
IMediaDeathNotifier::getMediaPlayerService()
{
ALOGV("getMediaPlayerService");
Mutex::Autolock _l(sServiceLock);
.......
D:\linux\linuxkernel\src\cm10.1\frameworks\base\services\jni\com_android_server_input_InputManagerService.cpp
NativeInputManager::NativeInputManager(jobject contextObj,
jobject serviceObj, const sp<Looper>& looper) :
mLooper(looper) {
JNIEnv* env = jniEnv();
mContextObj = env->NewGlobalRef(contextObj);
mServiceObj = env->NewGlobalRef(serviceObj);
{
AutoMutex _l(mLock);
mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
mLocked.pointerSpeed = 0;
mLocked.pointerGesturesEnabled = true;
mLocked.showTouches = false;
mLocked.stylusIconEnabled = false;
}
sp<EventHub> eventHub = new EventHub();
mInputManager = new InputManager(eventHub, this, this);
}
frameworks/base/libs/binder/IServiceManager.cpp
[cpp] view plaincopy
sp<IServiceManager> defaultServiceManager()
{
if (gDefaultServiceManager != NULL) return gDefaultServiceManager;
{
AutoMutex _l(gDefaultServiceManagerLock);
if (gDefaultServiceManager == NULL) {
gDefaultServiceManager = interface_cast<IServiceManager>(
ProcessState::self()->getContextObject(NULL));
}
}
return gDefaultServiceManager;
}
更多推荐
所有评论(0)