⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umc_mutex.h

📁 audio-video-codecs.rar语音编解码器
💻 H
字号:
/*
//
//                  INTEL CORPORATION PROPRIETARY INFORMATION
//     This software is supplied under the terms of a license agreement or
//     nondisclosure agreement with Intel Corporation and may not be copied
//     or disclosed except in accordance with the terms of that agreement.
//       Copyright(c) 2003-2006 Intel Corporation. All Rights Reserved.
//
*/

#ifndef __UMC_MUTEX_H__
#define __UMC_MUTEX_H__

#include "vm_debug.h"
#include "vm_mutex.h"
#include "umc_structures.h"

namespace UMC
{

class Mutex
{
public:
    // Default constructor
    Mutex(void);
    // Destructor
    virtual ~Mutex(void);

    // Initialize mutex
    Status Init(void);
    // Destroy mutex
    void Close(void);
    // Get ownership of mutex
    void Lock(void);
    // Release ownership of mutex
    void Unlock(void);
    // Try to get ownership of mutex
    Status TryLock(void);
    // Get ownership of initialized mutex
    void LockIfInitialized(void);
    // Release ownership of initialized mutex
    void UnlockIfInitialized(void);
    // Is mutex inited
    bool IsInited(void);

    // Extract mutex handle for using in AutomaticMutex class
    vm_mutex &ExtractHandle(void);

protected:
    vm_mutex m_handle;                                          // (vm_mutex) handle to system mutex
};

inline
void Mutex::Lock(void)
{
    Status umcRes = UMC_OK;

    if (!vm_mutex_is_valid(&m_handle))
        umcRes = Init();

    if ((UMC_OK == umcRes) &&
        (VM_OK != vm_mutex_lock(&m_handle)))
        VM_ASSERT(false);

} // void Mutex::Lock(void)

inline
void Mutex::Unlock(void)
{
    if (!vm_mutex_is_valid(&m_handle))
        Init();
    else if (VM_OK != vm_mutex_unlock(&m_handle))
        VM_ASSERT(false);

} // void Mutex::Unlock(void)

inline
Status Mutex::TryLock(void)
{
    Status umcRes = UMC_OK;

    if (!vm_mutex_is_valid(&m_handle))
        umcRes = Init();

    if (UMC_OK == umcRes)
        umcRes = vm_mutex_try_lock(&m_handle);

    return umcRes;

} // Status Mutex::TryLock(void)

inline
void Mutex::LockIfInitialized(void)
{
    if (vm_mutex_is_valid(&m_handle) &&
        (VM_OK != vm_mutex_lock(&m_handle)))
        VM_ASSERT(false);

} // void Mutex::LockIfInitialized(void)

inline
void Mutex::UnlockIfInitialized(void)
{
    if (vm_mutex_is_valid(&m_handle) &&
        (VM_OK != vm_mutex_unlock(&m_handle)))
        VM_ASSERT(false);

} // void Mutex::UnlockIfInitialized(void)

inline
bool Mutex::IsInited(void)
{
    return (0 != vm_mutex_is_valid(&m_handle));

} // bool Mutex::IsInited(void)

inline
vm_mutex &Mutex::ExtractHandle(void)
{
    return m_handle;

} // vm_mutex &Mutex::ExtractHandle(void)

} // namespace UMC

#endif // __UMC_MUTEX_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -