}
#endif // HAVE_SHM
+
+void
+Ipc::Mem::RegisteredRunner::run(const RunnerRegistry &r)
+{
+ // If Squid is built with real segments, we create() real segments
+ // in the master process only. Otherwise, we create() fake
+ // segments in each worker process. We assume that only workers
+ // need and can work with fake segments.
+#if HAVE_SHM
+ if (IamMasterProcess())
+#else
+ if (IamWorker())
+#endif
+ create(r);
+
+ // we assume that master process does not need shared segments
+ // unless it is also a worker
+ if (!InDaemonMode() || !IamMasterProcess())
+ open(r);
+}
#ifndef SQUID_IPC_MEM_SEGMENT_H
#define SQUID_IPC_MEM_SEGMENT_H
+#include "base/RunnersRegistry.h"
#include "SquidString.h"
namespace Ipc
bool doUnlink; ///< whether the segment should be unlinked on destruction
};
+/// Base class for runners that create and open shared memory segments.
+/// First may run create() method and then open().
+class RegisteredRunner: public ::RegisteredRunner
+{
+public:
+ /* RegisteredRunner API */
+ virtual void run(const RunnerRegistry &r);
+
+protected:
+ /// called when the runner should create a new memory segment
+ virtual void create(const RunnerRegistry &) = 0;
+ /// called when the runner should open a previously created segment,
+ /// not needed if segments are opened in constructor or init methods
+ virtual void open(const RunnerRegistry &) {}
+};
+
} // namespace Mem
} // namespace Ipc