Skip to content

[win] Don't build a custom nanosleep() when not needed - #1256

Merged
ddennedy merged 1 commit into
mltframework:masterfrom
dimula73:kazakov/win-fix-build-llvm-mingw
Oct 27, 2026
Merged

ddennedy merged 1 commit into
mltframework:masterfrom
dimula73:kazakov/win-fix-build-llvm-mingw

Conversation

@dimula73

Copy link
Copy Markdown
Contributor

Instead of relying of the includes order we should properly
check if the function is actually provided by our version
of pthread library.

The patch basically reverts an original hack to resolve the
issue in msys2 and implements a proper detection mechanism
for the presence of nanosleep() in the pthread library

@dimula73

dimula73 commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor Author

There is still an unorthodox usage of WIN_PTHREADS_TIME_H in mlt_types.h, which dates back from 2015. Theoretically, it could also be replaced with HAVE_PTHREAD_NANOSLEEP, though we would then have to add a public-interface definition for libmlt, like that:

target_compile_definitions(mlt PUBLIC "HAVE_PTHREAD_NANOSLEEP=${HAVE_PTHREAD_NANOSLEEP}")

Though I'm not sure if such a change is acceptable or not

@ddennedy

Copy link
Copy Markdown
Member

unorthodox usage of WIN_PTHREADS_TIME_H in mlt_types.h

It used to exist even if not in a standard. Google search on it first hit leads me to;
https://github.com/tonytheodore/winpthreads/blob/master/include/pthread_time.h

Since it is unorthodox it is OK to change it IMO.

@ddennedy

Copy link
Copy Markdown
Member

I approve the change but wait to see what you do about mlt_types.h

@dimula73

dimula73 commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi, @ddennedy!

I did a small test here and it seems like it is not easy to add HAVE_PTHREAD_NANOSLEEP into a global definitions interface of the entire library (.pc and Mlt7Config.cmake files will have to be adjusted for that manually).

So, we have three options here:

  1. Merge this patch as it is and ignore the fact that the implementation and prototype for MLT's nanosleep() are guarded by different definitions.

  2. Revert nanosleep()'s implementation to be guarded by the undocumented WIN_PTHREADS_TIME_H and just include pthread_time.h into the translation unit as well (this version will be the nearest to the original implementation)

  3. Add a global mlt_config.h file, which would be generated by CMake and provide this macro for mlt_types.h.

@ddennedy

Copy link
Copy Markdown
Member

nanosleep() for win32 is only supposed to be used internally but was added to mlt_types.h for convenience. We can add a src/win32/mlt_win32.h, but then it needs to be conditionally included wherever nanosleep is called. Or, your option 2 if __MINGW32__

Comment thread src/framework/mlt_types.h Outdated
Comment thread src/win32/win32.c Outdated
Comment thread CMakeLists.txt
Comment on lines -210 to -211
if(MINGW)
string(REPLACE "iconv" "pthread" MLT_PTHREAD_LIBS "${Iconv_LIBRARY}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added for a reason not too long ago. See git blame. Explain why it is no longer needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github lost my long comment that I was writing, so I will be short :(

The commit introducing that is: 64aa543

It has no explanation why it is needed, and what issue it is supposed to fix. Every target having this variable does already link to Threads::Threads so the hack looks unnecessary.

@ddennedy

Copy link
Copy Markdown
Member

Please address the comments.

@dimula73

Copy link
Copy Markdown
Contributor Author

Hi, @ddennedy!

I plan to return to this patch some time soon, I was just busy with other things (and then the vacation came :) )

@dimula73
dimula73 force-pushed the kazakov/win-fix-build-llvm-mingw branch from e2460b7 to 07c247a Compare October 27, 2026 13:58
@ddennedy
ddennedy requested a balanced review from Copilot October 27, 2026 17:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two public-header regressions break installed Windows header lookup and the fallback nanosleep() type declaration for C consumers.

2 open issues
What changed in this PR

This PR replaces MLT’s include-order-dependent Windows nanosleep() workaround with a CMake capability check against the pthread library.

Changes:

  • Detects pthread-provided nanosleep() and generates an installed configuration header.
  • Uses the detected capability to guard compatibility declarations and implementation.
  • Removes inferred pthread library paths and updates thread and SDL2 target linking.
File Description
src/​win32/​win32.c Guards fallback nanosleep() using the detected capability.
src/​modules/​sdl2/​CMakeLists.txt Removes explicit inferred pthread linking.
src/​modules/​avformat/​CMakeLists.txt Removes explicit inferred pthread linking.
src/​melt/​CMakeLists.txt Updates MinGW thread and SDL2 target linking.
src/​framework/​mlt_types.h Uses configuration-based guards for Windows declarations.
src/​framework/​mlt_config.h.in Adds the pthread nanosleep() capability macro template.
src/​framework/​CMakeLists.txt Checks availability and generates and installs the configuration header.
CMakeLists.txt Removes pthread library path inference from the iconv path.

Review effort: Balanced

Comment thread src/framework/mlt_types.h Outdated
Comment thread src/framework/mlt_types.h
Instead of relying of the includes order we should properly
check if the function is actually provided by our version
of pthread library.
@dimula73
dimula73 force-pushed the kazakov/win-fix-build-llvm-mingw branch from 07c247a to 15b2a98 Compare October 27, 2026 17:17
@dimula73

Copy link
Copy Markdown
Contributor Author

Hi, @ddennedy!

I've scraped the previous approach and implemented a full version with mlt_config.h which stores the status of the pthread library available on the host system.

@dimula73

Copy link
Copy Markdown
Contributor Author

I will also check consumption of this package on Windows now... I've check the building only

@dimula73

Copy link
Copy Markdown
Contributor Author

I will also check consumption of this package on Windows now... I've check the building only

Yes, consumption in Krita with on Windows works fine (llvm-mingw toolchain).

@ddennedy ddennedy added this to the v7.44.0 milestone Oct 27, 2026
@ddennedy
ddennedy merged commit 7b6ba22 into mltframework:master Oct 27, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants