Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove <Windows.h> include from headers #573

Open
Chronial opened this issue Sep 13, 2021 · 9 comments · May be fixed by #576
Open

Remove <Windows.h> include from headers #573

Chronial opened this issue Sep 13, 2021 · 9 comments · May be fixed by #576
Assignees

Comments

@Chronial
Copy link
Contributor

Chronial commented Sep 13, 2021

The tbb currently includes Windows.h in enumerable_thread_specific.h. Through transitive includes, this also affects combinable.h, concurrent_map.h and concurrent_set.h.

Since windows.h is massive and declares thousands of symbols, this include has a negative impact on build times. The windows include does not need to be in a public header. We should either:

  • Copy the declarations of the few required symbols from windows.h or
  • Move the calls to the Win32 API to a cpp
@Chronial Chronial linked a pull request Sep 14, 2021 that will close this issue
13 tasks
@vlserov vlserov self-assigned this Sep 27, 2021
@anton-potapov
Copy link
Contributor

to notice :
detail/_machine.h includes windows.h as well, however only for TBB Malloc build (#ifdef __TBBMALLOC_BUILD).

@emmenlau
Copy link

emmenlau commented Nov 9, 2021

Two thumbs up from my side for reducing the use of windows.h in headers...

@zmajeed
Copy link

zmajeed commented Nov 9, 2021

Please remove windows.h from shared header files for tests in test/common. Its presence has created difficulties for the cygwin port that needs Win32 versions of certain functions while mostly defaulting to Linux and Unix code. A particular example is GetMemoryUsage in test/common/memory_usage.h as described in #156 (comment)

@alexey-katranov
Copy link
Contributor

We are in the process of internal agreement. Sorry for the delay.

@zmajeed
Copy link

zmajeed commented Nov 10, 2021

@Chronial notes in their PR #576 (comment) that this issue is about usability

I'll point out that oneTBB is a portable library that provides cross-platform abstractions and interfaces. C++ headers basically define these interfaces. Including windows.h in a header file unfortunately violates these portable abstractions in the worst possible way - by polluting the global namespace with macros that have nothing to do with oneTBB interfaces.

Also it's not like oneTBB is a header-only library that does not separate implementation from interface - this request is just along the same lines as what oneTBB has been doing all along. It's simply that one needs to think of windows.h as an implementation detail that oneTBB needs to encapsulate within its abstraction layer - any other considerations are secondary

@akukanov
Copy link
Contributor

akukanov commented Nov 29, 2021

oneTBB is a mix of header-only and binary-based APIs; many class templates are header-only at least by default (if no tool support is requested via a macro, etc.). Typically these templates, including enumerable_thread_specific and concurrent containers, can be used not only in oneTBB parallel constructs but in any thread. IIRC in the past there were requests to allow using such APIs without linking with TBB binaries. which is also about usability.

Therefore, even though the use of windows.h is an implementation detail, whether to include it in public headers or not is an important tradeoff that needs to be carefully evaluated. This is what the team is doing now.

One possible solution I can think of is to provide an opt-out macro that precludes the use of windows.h at the cost of making ets_key_per_instance storage type unavailable (as simply changing the behavior of that would create risk of ODR violation).

@Alexandr-Konovalov
Copy link
Contributor

Probably NOMINMAX can decrease the overhead of Windows.h inclusion, while this is the solution for a different issue.

@emmenlau
Copy link

Probably NOMINMAX can decrease the overhead of Windows.h inclusion, while this is the solution for a different issue.

This preprocessor define is certainly helpful. In case someone has this problem, there are even more related macros, see http://web.archive.org/web/20121219084749/http://support.microsoft.com/kb/166474:

   VC_EXTRALEAN
   WIN32_LEAN_AND_MEAN

However, this does not really solve all the problems that can be caused by including windows.h. For example, the MSVC header will still add defines for a number of common names. For example, a number of file API methods are using preprocessor defines: CreateFile, DeleteFile, etc from https://learn.microsoft.com/en-us/windows/win32/api/fileapi/. After including windows.h, these names can no longer be used as class or method names.

In summary, its always very good to avoid including windows.h in any headers, if somehow possible. No problem to include it in implementation files, though.

@arunparkugan
Copy link

@alexey-katranov is this issue is still relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants