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

[core] Added srt::sync::genRandomInt(..) #1997

Merged
merged 2 commits into from
May 18, 2021

Conversation

maxsharabayko
Copy link
Collaborator

@maxsharabayko maxsharabayko commented May 12, 2021

1. Fixed MinGW Build

Commit no. 1.
Previously a custom definition __MINGW__ was defined in udt.h. However, udt.h. was not included in every source file, which uses __MINGW__ preprocessor definition, including srt.h.

According to this table MinGW defines __MINGW32__ preprocessor definition.
Now simply using __MINGW32__ preprocessor definition in relevant places.

2. Thread-Safe Random

Commit no. 2.
POSIX rand() is not thread safe.
This PR makes use of rand_r(unsigned int *seed) instead.

  • C++11 enabled: std::random_device and std::uniform_ditribution;
  • C++03 mode: a thread-safe rand_r(unsigned int *seed) is used instead.
  • MinGW: still uses rand() as there is no rand_r(..) available.

TODO

  • Maybe use thread-local seed? - Not using as random is not called that often. The most often series of calls would happen in case of congestion in file transfer configuration.
  • No rand_r on MinGW? - using rand().

Fixes #1825.
Maybe improves the situation with #1838.

@maxsharabayko maxsharabayko added Type: Enhancement Indicates new feature requests [core] Area: Changes in SRT library core labels May 12, 2021
@maxsharabayko maxsharabayko added this to the v1.4.4 milestone May 12, 2021
maxsharabayko and others added 2 commits May 18, 2021 14:26
Previously a custom __MINGW__ preprocessor definition was used. It was defined in udt.h, and not included everywhere.
for a uniform way to get a random integer from the range.
If C++11 is enabled, uniform_int_distribution
and random_device are used.
@maxsharabayko maxsharabayko force-pushed the develop/cxx11-random branch from 3fdc26c to d2f7ac1 Compare May 18, 2021 12:28
@maxsharabayko maxsharabayko marked this pull request as ready for review May 18, 2021 12:41
@maxsharabayko maxsharabayko merged commit 393a6c7 into Haivision:master May 18, 2021
@maxsharabayko maxsharabayko deleted the develop/cxx11-random branch May 18, 2021 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[core] Area: Changes in SRT library core Type: Enhancement Indicates new feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MAINT] Use C++11 std::uniform_int_distribution where possible
1 participant