mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 14:21:04 +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
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <SFML/System/ThreadLocalPtr.hpp>
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <streambuf>
|
||||
#include <cstdio>
|
||||
|
||||
@ -93,6 +95,23 @@ private:
|
||||
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
|
||||
@ -100,11 +119,12 @@ namespace sf
|
||||
////////////////////////////////////////////////////////////
|
||||
std::ostream& err()
|
||||
{
|
||||
static DefaultErrStreamBuf buffer;
|
||||
static std::ostream stream(&buffer);
|
||||
if (currentErr == NULL)
|
||||
{
|
||||
currentErr = new ThreadLocalErr();
|
||||
}
|
||||
|
||||
return stream;
|
||||
return currentErr->stream;
|
||||
}
|
||||
|
||||
|
||||
} // namespace sf
|
||||
|
Loading…
Reference in New Issue
Block a user