mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
TemporaryFile: Stopping use a LockedRandom now that system random is thread safe
This commit is contained in:
parent
655d18b721
commit
f98bf8434a
1 changed files with 2 additions and 19 deletions
|
|
@ -35,23 +35,6 @@
|
|||
namespace juce
|
||||
{
|
||||
|
||||
// Using Random::getSystemRandom() can be a bit dangerous in multithreaded contexts!
|
||||
class LockedRandom
|
||||
{
|
||||
public:
|
||||
int nextInt()
|
||||
{
|
||||
const ScopedLock lock (mutex);
|
||||
return random.nextInt();
|
||||
}
|
||||
|
||||
private:
|
||||
CriticalSection mutex;
|
||||
Random random;
|
||||
};
|
||||
|
||||
static LockedRandom lockedRandom;
|
||||
|
||||
static File createTempFile (const File& parentDirectory, String name,
|
||||
const String& suffix, int optionFlags)
|
||||
{
|
||||
|
|
@ -63,7 +46,7 @@ static File createTempFile (const File& parentDirectory, String name,
|
|||
|
||||
TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
|
||||
: temporaryFile (createTempFile (File::getSpecialLocation (File::tempDirectory),
|
||||
"temp_" + String::toHexString (lockedRandom.nextInt()),
|
||||
"temp_" + String::toHexString (Random::getSystemRandom().nextInt()),
|
||||
suffix, optionFlags)),
|
||||
targetFile()
|
||||
{
|
||||
|
|
@ -72,7 +55,7 @@ TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
|
|||
TemporaryFile::TemporaryFile (const File& target, const int optionFlags)
|
||||
: temporaryFile (createTempFile (target.getParentDirectory(),
|
||||
target.getFileNameWithoutExtension()
|
||||
+ "_temp" + String::toHexString (lockedRandom.nextInt()),
|
||||
+ "_temp" + String::toHexString (Random::getSystemRandom().nextInt()),
|
||||
target.getFileExtension(), optionFlags)),
|
||||
targetFile (target)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue