-
Notifications
You must be signed in to change notification settings - Fork 44
/
mwcas_shm_server.cc
60 lines (48 loc) · 2 KB
/
mwcas_shm_server.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#include <condition_variable>
#include <mutex>
#ifdef WIN32
#include <conio.h>
#endif
#include "mwcas_benchmark.h"
using namespace pmwcas::benchmark;
DEFINE_uint64(array_size, 100, "size of the word array for mwcas benchmark");
DEFINE_uint64(descriptor_pool_size, 262144, "number of total descriptors");
DEFINE_string(shm_segment, "mwcas", "name of the shared memory segment for"
" descriptors and data (for persistent MwCAS only)");
using namespace pmwcas;
// Start a process to create a shared memory segment and sleep
int main(int argc, char* argv[]) {
google::InitGoogleLogging(argv[0]);
google::ParseCommandLineFlags(&argc, &argv, true);
LOG(INFO) << "Array size: " << FLAGS_array_size;
LOG(INFO) << "Descriptor pool size: " << FLAGS_descriptor_pool_size;
LOG(INFO) << "Segment name: " << FLAGS_shm_segment;
#ifdef WIN32
pmwcas::InitLibrary(pmwcas::DefaultAllocator::Create,
pmwcas::DefaultAllocator::Destroy, pmwcas::WindowsEnvironment::Create,
pmwcas::WindowsEnvironment::Destroy);
#else
pmwcas::InitLibrary(pmwcas::DefaultAllocator::Create,
pmwcas::DefaultAllocator::Destroy, pmwcas::LinuxEnvironment::Create,
pmwcas::LinuxEnvironment::Destroy);
#endif
uint64_t size = sizeof(DescriptorPool::Metadata) +
sizeof(Descriptor) * FLAGS_descriptor_pool_size + // descriptors area
sizeof(CasPtr) * FLAGS_array_size; // data area
SharedMemorySegment* segment = nullptr;
auto s = Environment::Get()->NewSharedMemorySegment(FLAGS_shm_segment, size,
false, &segment);
RAW_CHECK(s.ok() && segment, "Error creating memory segment");
s = segment->Attach();
RAW_CHECK(s.ok(), "cannot attach");
memset(segment->GetMapAddress(), 0, size);
segment->Detach();
std::mutex mutex;
std::unique_lock<std::mutex> lock(mutex);
std::condition_variable cv;
std::cout << "Created shared memory segment" << std::endl;
cv.wait(lock);
return 0;
}