本文整理汇总了C++中SharedMemory::SetArea方法的典型用法代码示例。如果您正苦于以下问题:C++ SharedMemory::SetArea方法的具体用法?C++ SharedMemory::SetArea怎么用?C++ SharedMemory::SetArea使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharedMemory
的用法示例。
在下文中一共展示了SharedMemory::SetArea方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
// This program exercises the Message class.
int main(int argc, char ** argv)
{
bool deleteArea = ((argc > 1)&&(strncmp(argv[1], "del", 3) == 0));
uint8 base = 0;
LogTime(MUSCLE_LOG_INFO, deleteArea ? "Deleting shared memory area!\n" : "Beginning shared memory test!\n");
SharedMemory m;
if (m.SetArea(TEST_KEY, TEST_AREA_SIZE, true) == B_NO_ERROR)
{
if (deleteArea) LogTime(MUSCLE_LOG_INFO, "Deletion of area %s %s\n", m.GetAreaName()(), (m.DeleteArea() == B_NO_ERROR) ? "succeeded" : "failed");
else
{
uint8 * a = m.GetAreaPointer();
uint32 s = m.GetAreaSize();
if (m.IsCreatedLocally())
{
LogTime(MUSCLE_LOG_INFO, "Created new shared memory area %s\n", m.GetAreaName()());
for (uint32 i=0; i<s; i++) a[i] = base;
}
else LogTime(MUSCLE_LOG_INFO, "Found existing shared memory area %s\n", m.GetAreaName()());
LogTime(MUSCLE_LOG_INFO, "Area is " UINT32_FORMAT_SPEC " bytes long, starting at address %p\n", s, a);
m.UnlockArea();
uint64 lastTime = 0;
while(1)
{
if (OnceEvery(MICROS_PER_SECOND, lastTime)) LogTime(MUSCLE_LOG_INFO, "Still going... base=%u\n", base);
// Test out the read/write exclusive lock
if (m.LockAreaReadWrite() == B_NO_ERROR)
{
uint32 s = m.GetAreaSize();
if (s > 0)
{
uint8 * a = m.GetAreaPointer();
{for (uint32 i=1; i<s; i++) if (a[i-1] != a[i]) LogTime(MUSCLE_LOG_ERROR, "A. [email protected]" UINT32_FORMAT_SPEC "\n",i);}
{for (uint32 i=0; i<s; i++) a[i] = base;}
{for (uint32 i=0; i<s; i++) if (a[i] != base) LogTime(MUSCLE_LOG_ERROR, "B. [email protected]" UINT32_FORMAT_SPEC "\n",i);}
}
else LogTime(MUSCLE_LOG_ERROR, "Area size is zero!?\n");
m.UnlockArea();
}
else
{
LogTime(MUSCLE_LOG_ERROR, "Exclusive Lock failed! Maybe the area was deleted!\n");
break;
}
// Also test out the read-only lock
if (m.LockAreaReadOnly() == B_NO_ERROR)
{
uint32 s = m.GetAreaSize();
if (s > 0)
{
const uint8 * a = m.GetAreaPointer();
{for (uint32 i=1; i<s; i++) if (a[i-1] != a[i]) LogTime(MUSCLE_LOG_ERROR, "C. [email protected]" UINT32_FORMAT_SPEC "\n",i);}
}
else LogTime(MUSCLE_LOG_ERROR, "Area size is zero!?\n");
m.UnlockArea();
}
else
{
LogTime(MUSCLE_LOG_ERROR, "Read-Only Lock failed! Maybe the area was deleted!\n");
break;
}
base++;
}
}
}
else LogTime(MUSCLE_LOG_ERROR, "SetArea() failed, exiting!\n");
return 0;
}