Skip to content

Use FlsAlloc/FlsFree/FlsGetValue/FlsSetValue instead of TlsAlloc/TlsFree/TlsGetValue/TlsSetValue to implment TLS value cleanup when thread has been terminated on Windows Vista and above - #15812

Merged
alalek merged 5 commits into
opencv:3.4from
yuriyluxriot:fls_replaces_tls
Nov 1, 2019

Conversation

@yuriyluxriot

@yuriyluxriot yuriyluxriot commented Oct 30, 2019 •

Copy link
Copy Markdown
Contributor
System information (version)
  • OpenCV => 4.1.2-dev
  • Operating System / Platform => Windows 7 64-bit
  • Compiler => Visual Studio 2015
Detailed description

Use FlsAlloc/FlsFree/FlsGetValue/FlsSetValue instead of TlsAlloc/TlsFree/TlsGetValue/TlsSetValue to implment TLS operations and cleanup of value when thread has been terminated on Windows Vista and above.
Fls-functions operates on fiber local storage (FLS) and FlsAlloc allows to specify application-defined callback function. If the FLS slot is in use, then callback is called on fiber deletion, thread exit, and when an FLS index is freed. For more information see https://docs.microsoft.com/en-us/windows/win32/api/fibersapi/nf-fibersapi-flsalloc

In orer to use Fls-functions need to define _WIN32_WINNT to 0x0600 or above.

Comment thread modules/core/src/system.cpp Resolved

@alalek alalek left a comment

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.

What is about DllMain() THREAD_DETACH calls?

Comment thread modules/core/src/system.cpp Resolved

@alalek alalek left a comment

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.

Right! Static builds can't work through DllMain notifications.

Please move this patch into 3.4 branch first. We will merge changes from 3.4 into master regularly (weekly/bi-weekly).

So, please:

  • change "base" branch of this PR: master => 3.4 (use "Edit" button near PR title)
  • rebase your commits from master onto 3.4 branch. For example:
    git rebase -i --onto upstream/3.4 upstream/master
    (check list of your commits, save and quit (Esc + "wq" + Enter)
    where upstream is configured by following this GitHub guide and fetched (git fetch upstream).
  • push rebased commits into source branch of your fork (with --force option)

Note: no needs to re-open PR, apply changes "inplace".

Comment thread modules/core/src/system.cpp Resolved
Comment thread modules/core/src/system.cpp Resolved
@yuriyluxriot
yuriyluxriot changed the base branch from master to 3.4 November 1, 2019 13:37
@alalek

alalek commented Nov 1, 2019

Copy link
Copy Markdown
Member

Do not merge.
I will rebase your commits.

@alalek alalek left a comment

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.

Thank you for contribution!

@alalek
alalek merged commit 4e156a1 into opencv:3.4 Nov 1, 2019
@alalek alalek mentioned this pull request Nov 4, 2019
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
* Use FlsAlloc/FlsFree/FlsGetValue/FlsSetValue instead of TlsAlloc/TlsFree/TlsGetValue/TlsSetValue to implment TLS value cleanup when thread has been terminated on Windows Vista and above

* Fix 32-bit build

* Fixed calling convention of cleanup callback

* WINAPI changed to NTAPI

* Use proper guard macro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants