macro LIBSHARED_PAL_THREAD_RETURN_CAST

From liblfds.org
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_CAST( return_value )  return_value

or

#define LIBSHARED_PAL_THREAD_RETURN_CAST( return_value )

Example

#define LIBSHARED_PAL_THREAD_RETURN_CAST( return_value )

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 (LIBSHARED_PAL_THREAD_RETURN_TYPE) and this macro are provided. This define provides for Windows kernel a harmless type which will permit the thread function code to compile. This macro 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