Add QFreeList as an internal class
authorBradley T. Hughes <bradley.hughes@nokia.com>
Tue, 19 Jul 2011 13:53:32 +0000 (15:53 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 26 Jul 2011 11:40:07 +0000 (13:40 +0200)
commit6b82798ee73dc8aac6f6a6c4c12ff291d6d7e9e1
treeb815e752da268b5c4e895bbd25d6d920a9d59876
parentb7064513e2b0fc51f5f68d2057047ed30bae6eba
Add QFreeList as an internal class

This is a generic implementation of the lock-free free list found in
qabstracteventdispatcher.cpp. Use next() to get the next free entry in
the list, and release(id) when done with the id.

This version is templated and allows having a payload which can be
accessed using the id returned by next(). The payload is allocated and
deallocated automatically by the free list, but *NOT* when calling
next()/release(). Initialization should be done by code needing it after
next() returns. Likewise, cleanup should happen before calling
release(). It is possible to have use 'void' as the payload type, in
which case the free list only contains indexes to the next free entry.

Autotest included.

Change-Id: Ifd12a961d47f3d76593c45061f72e55c9b80a43b
Reviewed-on: http://codereview.qt.nokia.com/2160
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
src/corelib/tools/qfreelist.cpp [new file with mode: 0644]
src/corelib/tools/qfreelist_p.h [new file with mode: 0644]
src/corelib/tools/tools.pri
tests/auto/corelib.pro
tests/auto/qfreelist/qfreelist.pro [new file with mode: 0644]
tests/auto/qfreelist/tst_qfreelist.cpp [new file with mode: 0644]