The shared memory region

Updated: April 19, 2023

Finally, the main thread sets up a shared memory region.

Note: If we find that there's already a shared memory region present, we invalidate its signature block and unlink it. The rationale here is that a previous ADIOS manager created one, and was killed (or died). By invalidating the signature, we're telling any users of that shared memory region that it's no longer valid.

Creating the shared memory region (and setting up various pointers and data areas) is done by the function create_shmem() in daq.c. Since it's a fairly large function (about 100 lines), I'll present the steps it performs first, and then we'll look at the details in smaller chunks:

  1. Calculate sizes of various data structures.
  2. Open the shared memory via shm_open().
  3. If it already exists, invalidate its signature, close it, unlink it, and attempt to reopen it.
  4. If that second open fails, we abort.
  5. Truncate the shared memory region to the correct (calculated) size.
  6. Using mmap(), map the shared memory region into our address space.
  7. Set up our utility pointers.
  8. Clear the signature, and initialize the other fields in the signature structure.
  9. Set the head member to point to the last entry in the buffer, so that when we add our first entry, head will point to 0.
  10. Fill the card information structure (CIS) for all the cards that we are polling.