本文整理汇总了C++中CMutex::lock方法的典型用法代码示例。如果您正苦于以下问题:C++ CMutex::lock方法的具体用法?C++ CMutex::lock怎么用?C++ CMutex::lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMutex
的用法示例。
在下文中一共展示了CMutex::lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getStopFlag
bool CThread::getStopFlag() const
{
mStopFlagMutex.lock();
bool stop = mStopFlag;
mStopFlagMutex.unlock();
return stop;
}
示例2: close
/**
* Close device.
*
* Removes all sessions to a connection. Though, clientLib rejects the closeDevice()
* command if still sessions connected to the device, this is needed to clean up all
* sessions if client dies.
*/
void MobiCoreDevice::close(Connection *connection)
{
trustletSessionList_t::reverse_iterator interator;
static CMutex mutex;
// 1. Iterate through device session to find connection
// 2. Decide what to do with open Trustlet sessions
// 3. Remove & delete deviceSession from vector
// Enter critical section
mutex.lock();
for (interator = trustletSessions.rbegin();
interator != trustletSessions.rend();
interator++) {
TrustletSession *ts = *interator;
if (ts->deviceConnection == connection) {
closeSession(connection, ts->sessionId);
}
}
// Leave critical section
mutex.unlock();
// After the trustlet is done make sure to tell the driver to cleanup
// all the orphaned drivers
cleanupWsmL2();
connection->connectionData = NULL;
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_hardware_samsung_slsi_exynos5,代码行数:35,代码来源:MobiCoreDevice.cpp
示例3: deleteInstance
void CAppManConnectController::deleteInstance()
{
gInstanceMutex.lock();
delete mspInstance;
mspInstance = 0;
gInstanceMutex.unlock();
}
示例4: dyn_lock_callback
static void dyn_lock_callback(int mode, CRYPTO_dynlock_value *dlock, const char *file, int line) {
CMutex *mtx = (CMutex*)dlock;
if(mode & CRYPTO_LOCK) {
mtx->lock();
} else {
mtx->unlock();
}
}
示例5: mcCloseDevice
//------------------------------------------------------------------------------
__MC_CLIENT_LIB_API mcResult_t mcCloseDevice(
uint32_t deviceId
)
{
mcResult_t mcResult = MC_DRV_OK;
#ifndef WIN32
devMutex.lock();
LOG_I("===%s(%i)===", __FUNCTION__, deviceId);
do {
Device *device = resolveDeviceId(deviceId);
CHECK_DEVICE_CLOSED(device, deviceId);
Connection *devCon = device->connection;
if (device->openCount != 1) {
device->openCount--;
break;
}
// Check if daemon is still alive
if (!devCon->isConnectionAlive()) {
removeDevice(deviceId);
LOG_E("Daemon is dead removing device");
mcResult = MC_DRV_ERR_DAEMON_UNREACHABLE;
break;
}
// Return if not all sessions have been closed
// TODO-2012-08-31-haenellu: improve check, if device connection is dead, this makes no more sense.
if (device->hasSessions()) {
LOG_E("Trying to close device while sessions are still pending.");
mcResult = MC_DRV_ERR_SESSION_PENDING;
break;
}
SEND_TO_DAEMON(devCon, MC_DRV_CMD_CLOSE_DEVICE);
RECV_FROM_DAEMON(devCon, &mcResult);
if (mcResult != MC_DRV_OK) {
LOG_W(" %s(): Request at Daemon failed, respId=%d ", __FUNCTION__, mcResult);
break;
}
removeDevice(deviceId);
} while (false);
devMutex.unlock();
#endif /* WIN32 */
return mcResult;
}
示例6: deleteInstance
void CTimeoutManager::deleteInstance()
{
gsInstanceMutex.lock();
if (msInstance)
{
msInstance->finish();
delete msInstance;
msInstance = 0;
}
gsInstanceMutex.unlock();
}
示例7: generateUid
iviLink::BaseUid iviLink::generateUid()
{
std::stringstream ss;
gMutex.lock();
{
ss << gCounter;
++gCounter;
}
gMutex.unlock();
return BaseUid(ss.str());
}
示例8: mcCloseSession
//------------------------------------------------------------------------------
__MC_CLIENT_LIB_API mcResult_t mcCloseSession(mcSessionHandle_t *session)
{
mcResult_t mcResult = MC_DRV_OK;
#ifndef WIN32
LOG_I("===%s()===", __FUNCTION__);
devMutex.lock();
do {
CHECK_NOT_NULL(session);
LOG_I(" Closing session %03x.", session->sessionId);
Device *device = resolveDeviceId(session->deviceId);
CHECK_DEVICE(device);
Connection *devCon = device->connection;
Session *nqSession = device->resolveSessionId(session->sessionId);
CHECK_SESSION(nqSession, session->sessionId);
SEND_TO_DAEMON(devCon, MC_DRV_CMD_CLOSE_SESSION, session->sessionId);
RECV_FROM_DAEMON(devCon, &mcResult);
if (mcResult != MC_DRV_OK) {
LOG_E("CMD_CLOSE_SESSION failed, respId=%d", mcResult);
// TODO-2012-08-03-haenellu: Remove once tests can handle it.
mcResult = MC_DRV_ERR_UNKNOWN_DEVICE;
break;
}
bool r = device->removeSession(session->sessionId);
if (!r)
{
LOG_E("removeSession failed");
assert(0);
}
} while (false);
if (mcResult == MC_DRV_ERR_SOCKET_WRITE || mcResult == MC_DRV_ERR_SOCKET_READ) {
LOG_E("Connection is dead, removing device.");
removeDevice(session->deviceId);
}
devMutex.unlock();
#endif /* WIN32 */
return mcResult;
}
示例9: CTimeoutManager
CTimeoutManager * CTimeoutManager::getInstance()
{
if (0 == CTimeoutManager::msInstance)
{
gsInstanceMutex.lock();
if (0 == CTimeoutManager::msInstance)
{
CTimeoutManager::msInstance = new CTimeoutManager();
}
gsInstanceMutex.unlock();
}
return CTimeoutManager::msInstance;
}
示例10: CAppManConnectController
CAppManConnectController * CAppManConnectController::instance()
{
LOG4CPLUS_TRACE(msLogger,"instance()");
if (!mspInstance)
{
gInstanceMutex.lock();
if (!mspInstance)
{
mspInstance = new CAppManConnectController();
}
gInstanceMutex.unlock();
}
return mspInstance;
}
示例11: mcGetMobiCoreVersion
//------------------------------------------------------------------------------
__MC_CLIENT_LIB_API mcResult_t mcGetMobiCoreVersion(
uint32_t deviceId,
mcVersionInfo_t *versionInfo
)
{
mcResult_t mcResult = MC_DRV_OK;
#ifndef WIN32
devMutex.lock();
LOG_I("===%s()===", __FUNCTION__);
do {
Device *device = resolveDeviceId(deviceId);
// Is the device known
CHECK_DEVICE(device);
// Is the device opened.
CHECK_DEVICE_CLOSED(device, deviceId)
CHECK_NOT_NULL(versionInfo);
Connection *devCon = device->connection;
SEND_TO_DAEMON(devCon, MC_DRV_CMD_GET_MOBICORE_VERSION);
// Read GET MOBICORE VERSION response.
RECV_FROM_DAEMON(devCon, &mcResult);
if (mcResult != MC_DRV_OK) {
LOG_E("MC_DRV_CMD_GET_MOBICORE_VERSION bad response, respId=%d", mcResult);
// TODO-2012-09-06-haenellu: Remove once tests can handle it.
mcResult = MC_DRV_ERR_DAEMON_UNREACHABLE;
break;
}
// Read payload.
mcVersionInfo_t versionInfo_socket;
RECV_FROM_DAEMON(devCon, &versionInfo_socket);
*versionInfo = versionInfo_socket;
} while (0);
devMutex.unlock();
#endif /* WIN32 */
return mcResult;
}
示例12: CAppManConnectController
CAppManConnectController * CAppManConnectController::instance(Android::AppInfo appInfo)
{
LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
if (!mspInstance)
{
gInstanceMutex.lock();
if (!mspInstance)
{
mspInstance = new CAppManConnectController(appInfo);
}
gInstanceMutex.unlock();
}
return mspInstance;
}
示例13: mcFreeWsm
//------------------------------------------------------------------------------
__MC_CLIENT_LIB_API mcResult_t mcFreeWsm(
uint32_t deviceId,
uint8_t *wsm
)
{
mcResult_t mcResult = MC_DRV_ERR_UNKNOWN;
#ifndef WIN32
Device *device;
devMutex.lock();
LOG_I("===%s(%p)===", __FUNCTION__, wsm);
do {
// Get the device associated wit the given session
device = resolveDeviceId(deviceId);
// Is the device known
CHECK_DEVICE(device);
// Is the device opened.
CHECK_DEVICE_CLOSED(device, deviceId)
// find WSM object
CWsm_ptr pWsm = device->findContiguousWsm(wsm);
if (pWsm == NULL) {
LOG_E("address is unknown to mcFreeWsm");
mcResult = MC_DRV_ERR_WSM_NOT_FOUND;
break;
}
// Free the given virtual address
mcResult = device->freeContiguousWsm(pWsm);
if (mcResult != MC_DRV_OK) {
LOG_E("Free of virtual address failed");
break;
}
mcResult = MC_DRV_OK;
} while (false);
devMutex.unlock();
#endif /* WIN32 */
return mcResult;
}
示例14: mcFreeWsm
//------------------------------------------------------------------------------
__MC_CLIENT_LIB_API mcResult_t mcFreeWsm(
uint32_t deviceId,
uint8_t *wsm
) {
mcResult_t mcResult = MC_DRV_ERR_UNKNOWN;
Device *device;
static CMutex mutex;
LOG_I("===%s()===", __func__);
mutex.lock(); // Enter critical section
do {
// Get the device associated wit the given session
device = resolveDeviceId(deviceId);
if (NULL == device)
{
LOG_E("mcFreeWsm(): Device not found");
mcResult = MC_DRV_ERR_UNKNOWN_DEVICE;
break;
}
// find WSM object
CWsm_ptr pWsm = device->findContiguousWsm(wsm);
if (NULL == pWsm)
{
LOG_E("mcFreeWsm(): unknown address");
mcResult = MC_DRV_ERR_INVALID_PARAMETER;
break;
}
// Free the given virtual address
if (!device->freeContiguousWsm(pWsm))
{
LOG_E("mcFreeWsm(): Free of virtual address failed");
mcResult = MC_DRV_ERR_FREE_MEMORY_FAILED;
break;
}
mcResult = MC_DRV_OK;
} while (false);
mutex.unlock(); // Exit critical section
return mcResult;
}
示例15: mcMallocWsm
//------------------------------------------------------------------------------
__MC_CLIENT_LIB_API mcResult_t mcMallocWsm(
uint32_t deviceId,
uint32_t align,
uint32_t len,
uint8_t **wsm,
uint32_t wsmFlags
) {
mcResult_t mcResult = MC_DRV_ERR_UNKNOWN;
static CMutex mutex;
LOG_I("===%s()===", __func__);
mutex.lock(); // Enter critical section
do
{
Device *device = resolveDeviceId(deviceId);
if (NULL == device)
{
LOG_E("mcMallocWsm(): Device not found");
mcResult = MC_DRV_ERR_UNKNOWN_DEVICE;
break;
}
if(NULL == wsm)
{
mcResult = MC_DRV_ERR_INVALID_PARAMETER;
break;
}
CWsm_ptr pWsm = device->allocateContiguousWsm(len);
if (NULL == pWsm)
{
LOG_E("mcMallocWsm(): Allocation of WSM failed");
mcResult = MC_DRV_ERR_NO_FREE_MEMORY;
break;
}
*wsm = (uint8_t*)pWsm->virtAddr;
mcResult = MC_DRV_OK;
} while (false);
mutex.unlock(); // Exit critical section
return mcResult;
}