define LIBSHARED_PAL_THREAD_RETURN_TYPE

From liblfds.org
Revision as of 07:43, 27 May 2016 by Admin (talk | contribs) (→‎Notes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Source File

└───test_and_benchmark
    └───libshared
        └───inc
            └───libshared
                    libshared_porting_abstraction_layer_compiler.h

Define

#define LIBSHARED_PAL_THREAD_RETURN_TYPE  libshared_pal_thread_return_t

or

#define LIBSHARED_PAL_THREAD_RETURN_TYPE  int

Example

#define LIBSHARED_PAL_THREAD_RETURN_TYPE  libshared_pal_thread_return_t

Optionality

This define is mandatory and the library cannot compile if it is not set.

Notes

Windows kernel mode threads are unique in that the thread function returns void. As such, two problems are presented; firstly, the existing code, which is cross-platform and so has thread functions which return a variable, often attempts to declare on the stack a variable of the type libshared_pal_thread_return_t, which is set to a value during the course of operation and then returned. However, if libshared_pal_thread_return_t is void, then the compiler throws an error, because it is not possible to declare variables of type void. Secondly, the return from the thread function must be empty - where all the existing threads are returning a value or variable.

To solve this, one define (this define) and one macro (LIBSHARED_PAL_THREAD_RETURN_CAST) are provided. This define provides for Windows kernel a harmless type which will permit the thread function code to compile. The macro LIBSHARED_PAL_THREAD_RETURN_CAST wraps the return argument and on Windows kernel, consumes it - makes it disappear - by being an empty macro. On other platforms, the macro itself disappears, leaving just its argument, which then gives us what we want in both cases.

See Also