CSyncCollection v1.17 A templatized
collection with thread synchronization
Welcome to CSyncCollection, a C++ class which implements a templatized
collection which implements Windows thread synchronisation with timeouts for both
adding and removing. In other words when you "Add", you can specify a
timeout to wait for if the collection is full and when you "Remove"
data from the collection you can specify a timeout to wait for if the collection
is empty. Making the class templatized means that you can store any type of data
you want in it. In addition templates are used to define various collection types.
The code comes with predefined templates for both a stack and queue collection
using STL containers.
The enclosed zip file contains source
for the class and a VC2017 test program which implements a simulation of the classic
consumer / producer thread synchronisation example.
Copyright
- You are allowed to include the source code in any product (commercial, shareware,
freeware or otherwise) when your product is released in binary form.
- You are allowed to modify the source code in any way you want except you
cannot modify the copyright details at the top of each module.
- If you want to distribute source code with your application, then you are
only allowed to distribute versions released by the author. This is to maintain
a single distribution point for the source code.
Updates
v1.17 (30 March 2022)
- Updated copyright details.
- Updated the code to use C++ uniform initialization for all variable
declarations.
v1.16 (31 October 2021)
- Updated copyright details
v1.15 (13 April 2020)
- Fixed more Clang-Tidy static code analysis warnings in the code.
v1.14 (3 June 2019)
- Updated copyright details
- Updated the code to clean compile on VC 2019
v1.13 (1 October 2018)
- Updated copyright details.
- Fixed a number of C++ core guidelines compiler warnings. These changes
mean that the code will now only compile on VC 2017 or later.
- Removed MFC code path from the classes
- Changed CSyncQueueDataSTL class to be CSyncQueueData.
- Changed CSyncStackDataSTL class to be CSyncStackData.
- Removed ARG_TYPE template parameter from CSyncCollection class
- Replaced BOOL with bool throughout codebase
v1.12 (20 February 2016)
- Updated copyright details
- Updated the code to clean compile in VC 2015
- Added SAL annotations to all the code.
- Replaced all calls to assert with ATLASSERT.
- Code now uses ATL::CSemaphore instead of raw HANDLE's for the semaphore
member variables
- Code now uses ATL::CComCriticalSection instead of raw CRITICAL_SECTION for
the critical section member variable
- Code now uses ATL::CEvent instead of raw HANDLE for the event member variable
- CSyncCollection::Create now returns a HRESULT instead of a BOOL
- The data is removed from the collection before the synchronization objects
are destroyed in CSyncCollection::Close
- CSyncCollection::Lock and Unlock methods now return void instead of a BOOL
v1.11 (4 January 2015)
- Updated copyright details.
- Updated the code to clean compile in VC 2010 - VC 2013.
v1.10 (10 December 2011)
- Removed the unnecessary "CSyncData" class.
- Two new container classes have now been provided which use STL containers.
They are CSyncQueueDataSTL and CSyncStackDataSTL. To make these classes available
you need to define the processor value "CSYNCCOLLECTION_USE_STL" before
you include SyncCollection.h.
- Replaced MFC CCriticalSection usage with direct Win32 equivalent. Removed
all occurences of CSingleLock from source code. Replaced all occurrences of
TRACE with ATLTRACE. All these changes allows the code to now operate in non
MFC/ATL Windows projects.
v1.09 (27 May 2011)
- Updated copyright details
- Removed usage of CSingleLock m_sl member variable as "CSingleLock"
class is not designed to be used across multiple threads. Thanks to Serhiy Pavlov
for reporting this issue.
v1.08 (7 July 2008)
- Updated copyright details.
- Removed the CSYNCCOLLECTION_EXT_CLASS proprocessor value as it is not required
since the class is template based.
- The code has now been updated to support VC 2005 or later only.
- Updated the sample app to clean compile on VC 2008
- Code now compiles cleanly using Code Analysis (/analyze)
- Code now uses newer C++ style casts instead of C style casts.
v1.07 (2 May 2006)
- Removed the need to have the collection class methods virtual. After all
you can think of C++ templates as compile time polymorphism while virtual functions
give you runtime polymorphism.
v1.06 (10 April 2006)
- The CSyncCollection class now provides Lock and unlock methods to allow
external synchronisation.
- CSyncCollection::GetSize, Add, Remove & Close now includes a parameter
which decides if internal locking should be done. Again this allows more fine
tuned external synchronisation of the class
- Addition of a CCSYNCCOLLECTION_EXT_CLASS macro to make it more easier to
use the class in an extension dll.
- Updated the documentation to use the same style as the web site.
- Did a spell check of the documentation.
v1.06 (10 April 2006)
- The CSyncCollection class now provides Lock and unlock methods to allow
external synchronisation.
v1.05 (30 May 2005)
- Now uses a auto-reset event to signal that items are available instead of
a manual reset. Also the event is now created using the Win32 API rather than
using the MFC CEvent wrapper class.
- Updated the text in some of the TRACE statements.
v1.04 (26 November 2004)
- Fixed a number of compiler warnings when the code is compiled on VC .Net
2003
v1.03 (23 November 2003)
- Fixed a potential thread race condition in CSyncCollection::Remove
v1.02 (7 April 2002)
- Added a CEvent to the main class to allow synchronisation with data becoming
available in the collection without actually having to remove it.
v1.01 (6 April 2002)
- Sorted out some linker problems for the Win32 Debug and Win32 Release build
configurations.
v1.0 (26 January 2002)