Skip to content

Commit

Permalink
Merge 0988215 into 4b8b1ec
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Aug 5, 2020
2 parents 4b8b1ec + 0988215 commit 327dcfe
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Examples/BasketLosses/BasketLosses.cpp
Expand Up @@ -45,7 +45,7 @@ using namespace boost::assign;

#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {
Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion Examples/BermudanSwaption/BermudanSwaption.cpp
Expand Up @@ -49,7 +49,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Examples/Bonds/Bonds.cpp
Expand Up @@ -49,7 +49,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Examples/CDS/CDS.cpp
Expand Up @@ -52,7 +52,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion Examples/CVAIRS/CVAIRS.cpp
Expand Up @@ -42,7 +42,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Examples/CallableBonds/CallableBonds.cpp
Expand Up @@ -42,7 +42,7 @@ using namespace QuantLib;

#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {
Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion Examples/ConvertibleBonds/ConvertibleBonds.cpp
Expand Up @@ -38,7 +38,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Examples/DiscreteHedging/DiscreteHedging.cpp
Expand Up @@ -66,7 +66,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Examples/EquityOption/EquityOption.cpp
Expand Up @@ -45,7 +45,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Examples/FRA/FRA.cpp
Expand Up @@ -41,7 +41,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Examples/FittedBondCurve/FittedBondCurve.cpp
Expand Up @@ -49,7 +49,7 @@ using namespace QuantLib;

#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {
Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion Examples/Gaussian1dModels/Gaussian1dModels.cpp
Expand Up @@ -51,7 +51,8 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif

Expand Down
2 changes: 1 addition & 1 deletion Examples/GlobalOptimizer/GlobalOptimizer.cpp
Expand Up @@ -38,7 +38,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Examples/LatentModel/LatentModel.cpp
Expand Up @@ -36,7 +36,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Examples/MarketModels/MarketModels.cpp
Expand Up @@ -73,7 +73,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
Expand Up @@ -57,7 +57,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
3 changes: 2 additions & 1 deletion Examples/MultidimIntegral/MultidimIntegral.cpp
Expand Up @@ -24,6 +24,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details.
#include <ql/experimental/math/multidimintegrator.hpp>
#include <ql/experimental/math/multidimquadrature.hpp>
#include <ql/math/integrals/trapezoidintegral.hpp>
#include <ql/patterns/singleton.hpp>
#include <ql/functional.hpp>


Expand All @@ -36,7 +37,7 @@ using namespace std;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Examples/Replication/Replication.cpp
Expand Up @@ -47,7 +47,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Examples/Repo/Repo.cpp
Expand Up @@ -49,7 +49,7 @@ using namespace QuantLib;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down
29 changes: 22 additions & 7 deletions ql/patterns/singleton.hpp
Expand Up @@ -79,9 +79,24 @@

namespace QuantLib {

// This allows to define a different type if needed, while keeping
// backwards compatibility with the current implementation.
// For instance, one might create a file threadkey.hpp with:
//
// #include <pthread.h>
// #define QL_THREAD_KEY pthread_t
//
// and then compile QuantLib with the option -DQL_INCLUDE_FIRST=threadkey.hpp
// to have that file included by qldefines.hpp and thus this one.
#if defined(QL_THREAD_KEY)
typedef QL_THREAD_KEY ThreadKey;
#else
typedef Integer ThreadKey;
#endif

#if defined(QL_ENABLE_SESSIONS)
// definition must be provided by the user
Integer sessionId();
ThreadKey sessionId();
#endif

// this is required on VC++ when CLR support is enabled
Expand Down Expand Up @@ -111,7 +126,7 @@ namespace QuantLib {
class Singleton : private boost::noncopyable {
#if (QL_MANAGED == 1) && !defined(QL_SINGLETON_THREAD_SAFE_INIT)
private:
static std::map<Integer, ext::shared_ptr<T> > instances_;
static std::map<ThreadKey, ext::shared_ptr<T> > instances_;
#endif

#if defined(QL_SINGLETON_THREAD_SAFE_INIT)
Expand All @@ -130,8 +145,8 @@ namespace QuantLib {
// static member definitions

#if (QL_MANAGED == 1) && !defined(QL_SINGLETON_THREAD_SAFE_INIT)
template <class T>
std::map<Integer, ext::shared_ptr<T> > Singleton<T>::instances_;
template <class T>
std::map<ThreadKey, ext::shared_ptr<T> > Singleton<T>::instances_;
#endif

#if defined(QL_SINGLETON_THREAD_SAFE_INIT)
Expand All @@ -145,7 +160,7 @@ namespace QuantLib {
T& Singleton<T>::instance() {

#if (QL_MANAGED == 0) && !defined(QL_SINGLETON_THREAD_SAFE_INIT)
static std::map<Integer, ext::shared_ptr<T> > instances_;
static std::map<ThreadKey, ext::shared_ptr<T> > instances_;
#endif

// thread safe double checked locking pattern with atomic memory calls
Expand All @@ -165,9 +180,9 @@ namespace QuantLib {
#else //this is not thread safe

#if defined(QL_ENABLE_SESSIONS)
Integer id = sessionId();
ThreadKey id = sessionId();
#else
Integer id = 0;
ThreadKey id = 0;
#endif

ext::shared_ptr<T>& instance = instances_[id];
Expand Down
2 changes: 1 addition & 1 deletion test-suite/quantlibbenchmark.cpp
Expand Up @@ -271,7 +271,7 @@ namespace {

#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {
Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion test-suite/quantlibtestsuite.cpp
Expand Up @@ -260,7 +260,7 @@ namespace {
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

Integer sessionId() { return 0; }
ThreadKey sessionId() { return 0; }

}
#endif
Expand Down

0 comments on commit 327dcfe

Please sign in to comment.