本文整理汇总了C++中SharedMemory::writeWithoutLock方法的典型用法代码示例。如果您正苦于以下问题:C++ SharedMemory::writeWithoutLock方法的具体用法?C++ SharedMemory::writeWithoutLock怎么用?C++ SharedMemory::writeWithoutLock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharedMemory
的用法示例。
在下文中一共展示了SharedMemory::writeWithoutLock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: send
void ProcessWork::send(const char* buffer, int32_t length, int32_t pid, CorrespondParam::ProtocolId protocolId)
{
if (pid == 0)
{
LOGERROR("pid == 0");
return;
}
void* data = nullptr;
int32_t sendIndex = 0;
int32_t sendBegin = 0;
{
WriteLock writeLock(*(ProcessMutexManager::instance().positionMutex(pid)));
//修改发送位置
if (!SharedMemoryManager::instance().addDataPosition(pid, length))
{
//如果不成功就申请新共享内存
::ReleaseSemaphore(HandleManager::instance().createDataHandle(pid, true), 1, nullptr);
::WaitForSingleObject(HandleManager::instance().createDataEndHandle(pid, true), INFINITE);
//进入下一段数据内存
if (!SharedMemoryManager::instance().raiseSendData(pid, length))
{
LOGERROR("raiseSendData error");
}
}
//获取发送数据内存,最新
SharedMemory* sendData = SharedMemoryManager::instance().getCurrentSendData(pid);
//修改当前共享内存已使用大小
SharedMemoryManager::instance().addDataAlreadyUsed(pid, length);
data = sendData->writeWithoutLock();
if (data == nullptr)
{
LOGERROR("data == nullptr");
}
sendIndex = SharedMemoryManager::instance().sendDataIndex(pid);
sendBegin = SharedMemoryManager::instance().sendDataPosition(pid) - length;
}
//拷贝
::memcpy((char*)data + sendBegin, buffer, length);
{
WriteLock writeLock(*(ProcessMutexManager::instance().positionMutex(pid)));
//修改钥匙位置
if (!SharedMemoryManager::instance().addKeyPosition(pid))
{
//如果不成功就申请新共享内存
::ReleaseSemaphore(HandleManager::instance().createKeyHandle(pid, true), 1, nullptr);
::WaitForSingleObject(HandleManager::instance().createKeyEndHandle(pid, true), INFINITE);
//切换至当前
//ProcessHelper::changeToCurrentKey(&m_key, m_position);
//进入下一段钥匙内存
if (!SharedMemoryManager::instance().raiseSendKey(pid))
{
LOGERROR("raiseSendKey error");
}
}
//切换至当前
//SharedMemoryManager::instance().changeToCurrentKey(pid);
KeyPackage keyPackage;
keyPackage.m_sendPid = m_processPid;
keyPackage.m_receivePid = pid;
keyPackage.m_length = length;
keyPackage.m_protocal = protocolId;
keyPackage.m_index = sendIndex;
keyPackage.m_begin = sendBegin;
//先切换到当前钥匙内存再写入钥匙
if (!SharedMemoryManager::instance().writeKey(pid, keyPackage))
{
LOGERROR("writeKey false");
}
}
//通知
::ReleaseSemaphore(HandleManager::instance().assignHandle(pid, true), 1, nullptr);
}