]> git.ipfire.org Git - thirdparty/squid.git/commit
Rework shared object design and management API.
authorDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Mon, 25 Apr 2011 15:14:10 +0000 (19:14 +0400)
committerDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Mon, 25 Apr 2011 15:14:10 +0000 (19:14 +0400)
commit68353d5a4eac7ec0c6afaa40e0bc36df8cd14176
tree0b8b782424b436f4b95d7d9a1518c1a6ade20629
parent09c552d621d0398f8078a4ebea6b16631981a8ce
Rework shared object design and management API.

Before the patch, each shared object was responsible for allocating
and deallocating shared memory it uses.  As a result each object had a
shared and non shared portion.  Shared classes provided a pair of
static methods for creating and attaching to existing shared segments.

This is against how normal objects behave: normal objects are not
responsible for managing memory they use, they use the memory they are
given.  Besides the old approach mixes shared memory management and
object initialization logic.  The patch tries to improve this.

On the user side, the patch provides two functions for managing shared
objects:

* shm_new - allocates/deallocates shared memory, initializes the object
* shm_old - gives refcounted access to the object created by shm_new

Shm_new function returns so called Owner object.  It is not used for
working with the shared object, but to do shared memory
allocation/deallocation and object initialization.  This function will
be typically used in Squid master process to allocate shared memory on
startup.  On exit, the Owner object is deleted and shared object is
deallocated.

Shm_old function returns a refcounted smart pointer to the shared
object.  It does not allocate shared memory or initialize the object,
but just points to the object owned by the Owner.  Smart pointer
provides a simple way for working with the shared object.

On the internal side, the patch removes shared memory
allocation/deallocation from shared object class.  There is no more
local/shared parts.  Shared object class implementation is now similar
to an ordinary class.  The additional requirements for "shared"
classes are: the object must be a POD with no pointers to or
references; provides a static SharedMemorySize method for shared
memory size calculation; may need to use atomic primitives for safe
updates of data members.

All existing "shared" classes and code were converted to the new API.
26 files changed:
src/DiskIO/IpcIo/IpcIoFile.cc
src/DiskIO/IpcIo/IpcIoFile.h
src/Makefile.am
src/MemStore.cc
src/MemStore.h
src/MemStoreMap.cc [deleted file]
src/MemStoreMap.h [deleted file]
src/fs/Makefile.am
src/fs/rock/RockDirMap.cc [deleted file]
src/fs/rock/RockDirMap.h [deleted file]
src/fs/rock/RockSwapDir.cc
src/fs/rock/RockSwapDir.h
src/ipc/Makefile.am
src/ipc/Queue.cc
src/ipc/Queue.h
src/ipc/StoreMap.cc
src/ipc/StoreMap.h
src/ipc/mem/PagePool.cc
src/ipc/mem/PagePool.h
src/ipc/mem/PageStack.cc
src/ipc/mem/PageStack.h
src/ipc/mem/Pages.cc
src/ipc/mem/Pointer.h [new file with mode: 0644]
src/ipc/mem/Segment.cc
src/ipc/mem/Segment.h
src/main.cc