mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Keep thread-local instances of sf::err() backing implementation (WIP)
This commit is contained in:
parent
43b2e9dc12
commit
cfdba14e35
@ -26,6 +26,8 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/System/Err.hpp>
|
#include <SFML/System/Err.hpp>
|
||||||
|
#include <SFML/System/ThreadLocalPtr.hpp>
|
||||||
|
#include <SFML/System/NonCopyable.hpp>
|
||||||
#include <streambuf>
|
#include <streambuf>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
@ -93,6 +95,23 @@ private:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Groups a std::ostream with its std::streambuf
|
||||||
|
struct ThreadLocalErr : sf::NonCopyable
|
||||||
|
{
|
||||||
|
DefaultErrStreamBuf buffer;
|
||||||
|
std::ostream stream;
|
||||||
|
|
||||||
|
ThreadLocalErr() :
|
||||||
|
buffer(),
|
||||||
|
stream(&buffer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// This per-thread variable holds the current instance of DefaultErrStreamBuf
|
||||||
|
sf::ThreadLocalPtr<ThreadLocalErr> currentErr(NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
@ -100,11 +119,12 @@ namespace sf
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::ostream& err()
|
std::ostream& err()
|
||||||
{
|
{
|
||||||
static DefaultErrStreamBuf buffer;
|
if (currentErr == NULL)
|
||||||
static std::ostream stream(&buffer);
|
{
|
||||||
|
currentErr = new ThreadLocalErr();
|
||||||
|
}
|
||||||
|
|
||||||
return stream;
|
return currentErr->stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
Loading…
Reference in New Issue
Block a user