当前位置: 首页>>代码示例>>C++>>正文


C++ SharedMemoryProcessDataHeader::GetData方法代码示例

本文整理汇总了C++中SharedMemoryProcessDataHeader::GetData方法的典型用法代码示例。如果您正苦于以下问题:C++ SharedMemoryProcessDataHeader::GetData方法的具体用法?C++ SharedMemoryProcessDataHeader::GetData怎么用?C++ SharedMemoryProcessDataHeader::GetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SharedMemoryProcessDataHeader的用法示例。


在下文中一共展示了SharedMemoryProcessDataHeader::GetData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ENTRY

PAL_ERROR
CorUnix::InternalReleaseMutex(
    CPalThread *pthr,
    HANDLE hMutex
    )
{
    PAL_ERROR palError = NO_ERROR;
    IPalObject *pobjMutex = NULL;
    ISynchStateController *pssc = NULL;
    PalObjectTypeId objectTypeId;

    _ASSERTE(NULL != pthr);

    ENTRY("InternalReleaseMutex(pthr=%p, hMutex=%p)\n",
        pthr,
        hMutex
        );

    palError = g_pObjectManager->ReferenceObjectByHandle(
        pthr,
        hMutex,
        &aotAnyMutex,
        0, // should be MUTEX_MODIFY_STATE -- current ignored (no Win32 security)
        &pobjMutex
        );

    if (NO_ERROR != palError)
    {
        ERROR("Unable to obtain object for handle %p (error %d)!\n", hMutex, palError);
        goto InternalReleaseMutexExit;
    }

    objectTypeId = pobjMutex->GetObjectType()->GetId();
    if (objectTypeId == otiMutex)
    {
        palError = pobjMutex->GetSynchStateController(
            pthr,
            &pssc
            );

        if (NO_ERROR != palError)
        {
            ASSERT("Error %d obtaining synch state controller\n", palError);
            goto InternalReleaseMutexExit;
        }

        palError = pssc->DecrementOwnershipCount();

        if (NO_ERROR != palError)
        {
            ERROR("Error %d decrementing mutex ownership count\n", palError);
            goto InternalReleaseMutexExit;
        }
    }
    else
    {
        _ASSERTE(objectTypeId == otiNamedMutex);

        SharedMemoryProcessDataHeader *processDataHeader =
            SharedMemoryProcessDataHeader::PalObject_GetProcessDataHeader(pobjMutex);
        _ASSERTE(processDataHeader != nullptr);
        try
        {
            static_cast<NamedMutexProcessData *>(processDataHeader->GetData())->ReleaseLock();
        }
        catch (SharedMemoryException ex)
        {
            palError = ex.GetErrorCode();
            goto InternalReleaseMutexExit;
        }
    }

InternalReleaseMutexExit:

    if (NULL != pssc)
    {
        pssc->ReleaseController();
    }

    if (NULL != pobjMutex)
    {
        pobjMutex->ReleaseReference(pthr);
    }

    LOGEXIT("InternalReleaseMutex returns %i\n", palError);

    return palError;
}
开发者ID:jamesqo,项目名称:coreclr,代码行数:88,代码来源:mutex.cpp

示例2: InternalWaitForMultipleObjectsEx

DWORD CorUnix::InternalWaitForMultipleObjectsEx(
    CPalThread * pThread,
    DWORD nCount,
    CONST HANDLE *lpHandles,
    BOOL bWaitAll,
    DWORD dwMilliseconds,
    BOOL bAlertable)
{
    DWORD dwRet = WAIT_FAILED;
    PAL_ERROR palErr = NO_ERROR;
    int i, iSignaledObjCount, iSignaledObjIndex = -1;
    bool fWAll = (bool)bWaitAll, fNeedToBlock  = false;    
    bool fAbandoned = false;
    WaitType wtWaitType;

    IPalObject            * pIPalObjStackArray[MAXIMUM_STACK_WAITOBJ_ARRAY_SIZE] = { NULL };
    ISynchWaitController  * pISyncStackArray[MAXIMUM_STACK_WAITOBJ_ARRAY_SIZE] = { NULL };
    IPalObject           ** ppIPalObjs = pIPalObjStackArray;
    ISynchWaitController ** ppISyncWaitCtrlrs = pISyncStackArray;
  
    if ((nCount == 0) || (nCount > MAXIMUM_WAIT_OBJECTS))
    {
        ppIPalObjs = NULL;        // make delete at the end safe
        ppISyncWaitCtrlrs = NULL; // make delete at the end safe       
        ERROR("Invalid object count=%d [range: 1 to %d]\n", 
               nCount, MAXIMUM_WAIT_OBJECTS)
        pThread->SetLastError(ERROR_INVALID_PARAMETER);
        goto WFMOExIntExit;
    }
    else if (nCount == 1)
    {
        fWAll = false;  // makes no difference when nCount is 1
        wtWaitType = SingleObject;                                  
    }
    else 
    {
        wtWaitType = fWAll ? MultipleObjectsWaitAll : MultipleObjectsWaitOne;
        if (nCount > MAXIMUM_STACK_WAITOBJ_ARRAY_SIZE)
        {
            ppIPalObjs = InternalNewArray<IPalObject*>(nCount);
            ppISyncWaitCtrlrs = InternalNewArray<ISynchWaitController*>(nCount);
            if ((NULL == ppIPalObjs) || (NULL == ppISyncWaitCtrlrs))
            {
                ERROR("Out of memory allocating internal structures\n");
                pThread->SetLastError(ERROR_NOT_ENOUGH_MEMORY);
                goto WFMOExIntExit;
            }
        }
    }
   
    palErr = g_pObjectManager->ReferenceMultipleObjectsByHandleArray(pThread,
                                                                     (VOID **)lpHandles, 
                                                                     nCount,
                                                                     &sg_aotWaitObject,
                                                                     SYNCHRONIZE,
                                                                     ppIPalObjs);
    if (NO_ERROR != palErr)
    {
        ERROR("Unable to obtain object for some or all of the handles [error=%u]\n",
              palErr);
        if (palErr == ERROR_INVALID_HANDLE)
            pThread->SetLastError(ERROR_INVALID_HANDLE);
        else
            pThread->SetLastError(ERROR_INTERNAL_ERROR);
        goto WFMOExIntExit;
    }

    if (nCount > 1)
    {
        // Check for any cross-process sync objects. "Wait for any" and "wait for all" operations are not supported on
        // cross-process sync objects in the PAL.
        for (DWORD i = 0; i < nCount; ++i)
        {
            if (ppIPalObjs[i]->GetObjectType()->GetId() == otiNamedMutex)
            {
                ERROR("Attempt to wait for any or all handles including a cross-process sync object", ERROR_NOT_SUPPORTED);
                pThread->SetLastError(ERROR_NOT_SUPPORTED);
                goto WFMOExIntCleanup;
            }
        }
    }
    else if (ppIPalObjs[0]->GetObjectType()->GetId() == otiNamedMutex)
    {
        SharedMemoryProcessDataHeader *processDataHeader =
            SharedMemoryProcessDataHeader::PalObject_GetProcessDataHeader(ppIPalObjs[0]);
        _ASSERTE(processDataHeader != nullptr);
        try
        {
            MutexTryAcquireLockResult tryAcquireLockResult =
                static_cast<NamedMutexProcessData *>(processDataHeader->GetData())->TryAcquireLock(dwMilliseconds);
            switch (tryAcquireLockResult)
            {
                case MutexTryAcquireLockResult::AcquiredLock:
                    dwRet = WAIT_OBJECT_0;
                    break;

                case MutexTryAcquireLockResult::AcquiredLockButMutexWasAbandoned:
                    dwRet = WAIT_ABANDONED_0;
                    break;

//.........这里部分代码省略.........
开发者ID:ROOTU,项目名称:coreclr,代码行数:101,代码来源:wait.cpp

示例3: SharedMemoryException


//.........这里部分代码省略.........

    SharedMemoryManager::AcquireCreationDeletionProcessLock();
    autoCleanup.m_acquiredCreationDeletionProcessLock = true;

    // Create or open the shared memory
    bool created;
    SharedMemoryProcessDataHeader *processDataHeader =
        SharedMemoryProcessDataHeader::CreateOrOpen(
            name,
            SharedMemorySharedDataHeader(SharedMemoryType::Mutex, SyncSystemVersion),
            sizeof(NamedMutexSharedData),
            createIfNotExist,
            &created);
    if (createdRef != nullptr)
    {
        *createdRef = created;
    }
    if (created)
    {
        // If the shared memory file was created, the creation/deletion file lock would have been acquired so that we can
        // initialize the shared data
        autoCleanup.m_acquiredCreationDeletionFileLock = true;
    }
    if (processDataHeader == nullptr)
    {
        _ASSERTE(!createIfNotExist);
        return nullptr;
    }
    autoCleanup.m_processDataHeader = processDataHeader;

    if (created)
    {
        // Initialize the shared data
        new(processDataHeader->GetSharedDataHeader()->GetData()) NamedMutexSharedData;
    }

    if (processDataHeader->GetData() == nullptr)
    {
    #if !NAMED_MUTEX_USE_PTHREAD_MUTEX
        // Create the lock files directory
        char lockFilePath[SHARED_MEMORY_MAX_FILE_PATH_CHAR_COUNT + 1];
        SIZE_T lockFilePathCharCount =
            SharedMemoryHelpers::CopyString(lockFilePath, 0, SHARED_MEMORY_LOCK_FILES_DIRECTORY_PATH);
        if (created)
        {
            SharedMemoryHelpers::EnsureDirectoryExists(lockFilePath, true /* isGlobalLockAcquired */);
        }

        // Create the session directory
        lockFilePath[lockFilePathCharCount++] = '/';
        SharedMemoryId *id = processDataHeader->GetId();
        lockFilePathCharCount = id->AppendSessionDirectoryName(lockFilePath, lockFilePathCharCount);
        if (created)
        {
            SharedMemoryHelpers::EnsureDirectoryExists(lockFilePath, true /* isGlobalLockAcquired */);
            autoCleanup.m_lockFilePath = lockFilePath;
            autoCleanup.m_sessionDirectoryPathCharCount = lockFilePathCharCount;
        }

        // Create or open the lock file
        lockFilePath[lockFilePathCharCount++] = '/';
        lockFilePathCharCount =
            SharedMemoryHelpers::CopyString(lockFilePath, lockFilePathCharCount, id->GetName(), id->GetNameCharCount());
        int lockFileDescriptor = SharedMemoryHelpers::CreateOrOpenFile(lockFilePath, created);
        if (lockFileDescriptor == -1)
        {
开发者ID:jamesqo,项目名称:coreclr,代码行数:67,代码来源:mutex.cpp


注:本文中的SharedMemoryProcessDataHeader::GetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。