sharedreadme7bobcat
Description of bobcat’s shared memory classes
Overview
The following shared memory classes are available:
- o
-
SharedBlock(3bobcat)
-
The class SharedBlock(3bobcat) defines a small object consisting of a
SharedMutexand a (shared segment) id. If offers functionality to set and retrieve the id, and to lock and unlock theSharedMutex.SharedBlockobjects are used by SharedSegment(3bobcat) objects to keep track of which segments actually contain the shared memory data. It’s a bookkeeping helper class.
- o
-
SharedSegment(3bobcat)
-
The class
SharedSegment(cf. figure images/sharedsegment1.jpg) interfaces to actual shared memory. Its main member function is the static member create, returning a pointer to a newly allocated SharedMemory object.
-
The member create receives as its input parameters the number of blocks, the size of the segments allocated by
SharedSegment, and the segment’s access mode (as used by, e.g., chmod(1)). It returns a pointer to the allocated SharedSegment, and its ID (set using a pointer to an int, passed as its first parameter).
-
Although the
SharedSegmentclass defines an array of a single SharedBlock(3bobcat) object, in fact it will contain d_nBlocksSharedBlockobjects. The member create first allocates a block of raw memory of the required total size. Next it initializes the first part of this raw, shared memory, using the SharedSegment constructor and placement new. Next, the remaining amount of raw shared memory is initialized with d_nBlocks - 1SharedBlockobjects, again using placement new (cf. figure images/sharedsegment2.jpg).
- o
-
SharedPos(3bobcat)
-
The class SharedPos(3bobcat) monitors position information in the shared memory segments managed by
SharedSegmentobjects.SharedPosonly has a default constructor, but offers aresetmember receiving at construction time a pointer to aSharedSegmentobject.
- o
-
SharedMemory(3bobcat)
-
The class SharedMemory(3bobcat) offers the standard interface to shared memory, defining members like read, get, write and put. It interfaces to a SharedSegment object, and uses a SharedPos object to keep track of the SharedMemory’s offsets.
-
A
SharedMemoryobject itself resides in a program’s working memory, and not in the computer’s shared memory area. At any time theSharedMemoryobject only loads at most one actual block of the shared memory block managed bySharedSegment. The current position in the shared memory managed bySharedSegmentis monitored by theSharedMemory’s SharedBlock d_pos member.
-
Following read/write operations the offset is updated accordingly. There’s only one offset, which is used by [IO]?SharedStream objects when requesting or updating offsets. a
SharedMemoryobject offers safeguards against inappropriate use. E.g., if no memory has been allocated yet it may thow exceptions. Also, offsets can never exceed the SharedMemory’s maximum possible offset.
- o
-
SharedMutex(3bobcat)
-
The class
SharedMuteximplements a non-recursive mutex that can be stored in shared memory. It merely offers lock and unlock members. Within one thread lock should never be called repeatedly unless unlock is called first. The unlock member may safely repeatedly be called; once the mutex has been unlocked, repeated requests to unlock the mutex are simply ignored. When aSharedMutexis destroyed it calls unlock. Use SharedMemory’s install member to define aSharedMutexobject in shared memory, and use ptr->~SharedMutex() (with SharedMutex *ptr pointing at the SharedMutex object) to destroy it again.
- o
-
SharedCondition(3bobcat)
-
The class
SharedConditionimplements a condition variable and an associated mutex, both created in shared memory controlled by aSharedMemoryobject. It offers all the functionality of std::condition_variable. ASharedConditionobject itself is defined in a thread’s working memory, but interfaces to a `Condition’ object containing a condition variable and a mutex which are installed in shared memory. The size of this `Condition’ object is returned by the static member SharedCondition::size.SharedConditionmembers ensure that the thread has access to the `Condition’ object, and that the shared memory’s offset has not changed when returning from theSharedCondition’smembers.
- o
-
SharedBuf(3bobcat)
-
The class
SharedBufimplements a std::streambuf specialization interfacing to a SharedMemory object. In addition to a default constructor which is an empty stub the class offers constructors which immediately interface to a SharedMemory object, as well as a member to (re)associate aSharedBufobject with a SharedMemory object.
- o
-
SharedStream, ISharedStream, OSharedStream(3bobcat)
-
These stream classes offer stream-facilities operating on shared memory maintained by a SharedMemory object. The
SharedStreamclass uses the SharedMemory’s seek member for both seekp and seekg, and uses SharedMemory’s offset member for both tellp and tellg. All shared stream objects, includingISharedStream, offer a member to initialize a SharedCondition
-
An overview of currently defined shared memory segments is shown by the command ipcs -ma. To remove a defined shared memory segment the command ipcrm -m <id> can be used, where <id> is the shared memory segment’s ID.
Examples
See the sharedstream(3bobcat) man page.
Files
Images referred to in this man-page are located in the source distribution in bobcat/documents/images, or they can be found in the standard location of documentation files in your distribution (e.g., they are located in /usr/share/doc/libbobcat6/images).
Bobcat project files
- o
-
https://fbb-git.gitlab.io/bobcat/: gitlab project page;
Debian Bobcat project files:
- o
-
libbobcat6: debian package containing the shared library, changelog and copyright note;
- o
-
libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;
Bobcat
Bobcat is an acronym of `Brokken’s Own Base Classes And Templates’.
Releases
6 releases since Debian 8 (Jessie); the text changed 5 times.