AutoMutex _l(mLock)

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值