Skip to content

Commit

Permalink
Try atomic
Browse files Browse the repository at this point in the history
Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz committed Apr 16, 2024
1 parent ed15330 commit 91845b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
21 changes: 0 additions & 21 deletions src/libOpenImageIO/imageinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,6 @@ using namespace pvt;
// store an error message per thread, for a specific ImageInput
static thread_local tsl::robin_map<const ImageInput*, std::string>
input_error_messages;

// Helper class that, for any instance thereof, reveals whether any statics in
// the same compilation unit have been initialized or destroyed. If the
// statics are still alive, it looks like true, but it will look like false if
// evaluated before file-scope statics are initialized or after they are
// destroyed.
class LiveStaticSentry {
public:
LiveStaticSentry()
: m_alive(1)
{
}
~LiveStaticSentry() { m_alive = 0; }
// int operator()() const { return m_alive; }
operator bool() const { return m_alive; }
bool alive() const { return m_alive; }

private:
int m_alive = 0;
};

static LiveStaticSentry statics_alive;


Expand Down
24 changes: 24 additions & 0 deletions src/libOpenImageIO/imageio_pvt.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,30 @@ bluenoise_4chan_ptr(int x, int y, int z, int ch = 0, int seed = 0)



// Helper class that, for any instance thereof, reveals whether any statics in
// the same compilation unit have been initialized or destroyed. If the
// statics are still alive, it looks like true, but it will look like false if
// evaluated before file-scope statics are initialized or after they are
// destroyed.
class LiveStaticSentry {
public:
LiveStaticSentry() { m_alive = 1; }
~LiveStaticSentry() { m_alive = 0; }
operator bool() const { return alive(); }
bool alive() const
{
int a = m_alive;
// if (!a)
// print("LiveStaticSentry::alive() called after static destruction\n");
return a;
}

private:
atomic_int m_alive { 0 };
};



struct print_info_options {
bool verbose = false;
bool filenameprefix = false;
Expand Down

0 comments on commit 91845b1

Please sign in to comment.