PDA

View Full Version : Atomic Integer Support for Desktop and Embedded Platforms (in source format)



bob2oneil
29th June 2013, 21:24
I am developing a small library with both desktop (Linux, Windows, MacOS) and embedded system targets. My library would have to
be provided in binary form for specific platforms, or in source code format for perhaps some embedded platforms where I do not
have the proper build environment. My goals is to have all the required source code as one code base.

This library requires support for a couple of atomic integer operations, atomic increment (QAtomicInt.fetchAndAddStore()) and
test and set (QAtomicInt.testAndSetOrdered()) to implement non-locking non-waiting thread safe access to acquisition memory. In the
current implementation using Qt, the use of QAtomicInt is both non-locking and non-waiting, and fast, which is a fundamental requirement of the
implementation. This is currently implemented for a large application running under Linux/Windows using the Qt framework, staticly linking to the QtCore library.

Since some of the potential target platforms is embedded systems sensitive to library footprint, my goal is to keep the library as small
as possible. Certainly I could link in the QCore library for desktop environments that are not sensitive to size, but I prefer to
embedded just the Atomic APIs in my application code to minimize the footprint.

So my considerations are quite wide and varied.

1. I could pull out the atomic source files from the Qt source repo (e.g. 'qt-everywhere-opensource-src-4.8.4\src\corelib\arch')

2. I could use std:atomic, but this is not supported in legacy compilers (including MSVS2008/MSVC2010), so therefore unlikely for embedded systems.

3. I could use the Boost library, perhaps pull out only the relevant source for atomics.

4. I could use the Intel Thread BUilding Blocks (TBB) atomic, but back again to the issue of footprint when I only need some very
small features and not the entire library. Note that TBB is built for dynamic linking, not static.

5. I could attempt to use the OpenMP atomic statement (#pragma omp atomic), but this does not have support for test and set
(to my knowledge) and requires specific compiler support, so might not be available for some embedded targets.

6. Other?

Anyone attempt to do something similar and have any advise to achieve my goals on small size, code that is part of my
library, no dynamic links, no shared library to redistribute, etc.

Has anyone attempted to build small sections of the QtCore library or embed small sections into their own code base.

wysota
29th June 2013, 22:55
In general I would say that the proper approach depends on the platforms you wish to support. Some architectures support atomic operations directly using CPU instructions, others have to emulate it. Atomic operations are a fundamental part of Qt but only for platforms Qt supports. I think you should assemble a list of platforms you wish to support and then simply find implementations for all of them in the net. If you wish, you can extract needed code from Qt if the licence allows it or just google for alternate (per platform) solutions.