1

Porting an OS abstraction layer (from an embedded environment) to windows platform I end up with the following situation:

/* demo.c is a simple application working with some tasks */

#include "os.h"
/* os.h is needed as it has many required defines. Unfortunately it also contains */
/* extern FUNC(StatusType, OS_CODE) SetEvent(TaskType TaskID, EventMaskType Mask) */

#include <Windows.h>     /* new target platform */

/* several productive code pieces call this function to signal tasks */
FUNC(StatusType, OS_CODE) SetEvent(TaskType TaskID, EventMaskType Mask)
{
    if((TaskID == ...) && (Mask == ...))
    {
        HANDLE evNotify = ...;
        SetEvent(evNotify);        <-- WinAPI
    }
}

Before the OS wrapper called functions like "xTaskNotify". It is now the Windows port where the abstracted function has the same name. What expectedly results in a compile error.

Are there any easy means (or ideas) how to handle this? [before I start using anonymous function pointers, etc.]

NB: of course I cannot change the OS wrapper code as user code is relying on OS wrapper "SetEvent". And also it's generated.

vl106
  • 11
  • 2

2 Answers2

0

The key is conditional compilation.

I recommend to write your own variant of an os.h header (ideally choose an appropriate differing name) that you then can include everywhere you now include the original variant of:

#if [whatever test matches your concrete target MCU]

#include <os.h>
// additional definitions you might require for compatiblity with windows

#elif defined _WIN32 || defined _WIN64

#include <Windows.h>
// additional definitions you might require for compatibility with the other OS

#else
#error not implemented for current platform
#endif
Aconcagua
  • 24,880
  • 4
  • 34
  • 59
0

Thanks for your feedback.

Unfortunately, this will not work. As I described, I need both header files included in the OS wrapper. The os.h header is the interface description to the upper application layer(s), e.g. there will be a SetEvent() in it. While Windows.h, in this particular case, is the imported interface from the lower implementation layer.

Best solution would be to use C11's threads.h instead of NT native APIs. Unfortunately, MSVC doesn't support it.

Another solution: use Pthreads. As all of its API has a pthread_ prefix, there also are no name collisions anymore.

Marco Pagliaricci
  • 1,366
  • 17
  • 31
vl106
  • 11
  • 2