libzypp  17.38.7
PoolMember.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 ----------------------------------------------------------------------*/
9 #include "PoolMember.h"
10 #include "PoolImpl.h"
11 
12 namespace zypp::sat::detail {
13 
14  static bool & poolDestroyed() {
15  static bool _flag = false; // trivially destructible — never "destroyed"
16  return _flag;
17  }
18 
19  static PoolImpl & globalPool()
20  {
21  struct Guard {
22  Guard() = default;
23  Guard(const Guard &) = delete;
24  Guard(Guard &&) = delete;
25  Guard &operator=(const Guard &) = delete;
26  Guard &operator=(Guard &&) = delete;
27  ~Guard() { poolDestroyed() = true; }
28  };
29 
30  static PoolImpl _global;
31  static Guard _guard;
32  return _global;
33  }
34 
35 
37  //
38  // METHOD NAME : PoolMember::myPool
39  // METHOD TYPE : PoolImpl
40  //
42  {
43  if ( poolDestroyed () )
44  ZYPP_THROW( zypp::Exception("Global PoolImpl instance used after it was destroyed!") );
45  return globalPool ();
46  }
47 
49  {
50  return !poolDestroyed ();
51  }
52 }
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:459
std::unordered_map< std::string, std::string > _global
static PoolImpl & globalPool()
Definition: PoolMember.cc:19
static PoolImpl & myPool()
Definition: PoolMember.cc:41
Base class for Exception.
Definition: Exception.h:152
static bool & poolDestroyed()
Definition: PoolMember.cc:14
TrueBool _guard
Definition: TargetImpl.cc:1725