28#ifndef MPQC_CHEMISTRY_QC_BASIS_INTEGRALENGINEPOOL_HPP_
29#define MPQC_CHEMISTRY_QC_BASIS_INTEGRALENGINEPOOL_HPP_
32#include <mpqc/utility/mutex.hpp>
33#include <chemistry/qc/basis/integral.h>
35#include <util/misc/scexception.h>
48 template<
typename RefEngType>
51 pthread_key_t engine_key_;
52 RefEngType prototype_;
54 std::vector<void*> tls_ptrs;
58 typedef RefEngType engine_type;
66 if (pthread_key_create(&engine_key_,
nullptr) != 0)
68 "IntegralEnginePool::IntegralEnginePool() "
69 "Unable to register thread local storage key. "
70 "Likely due to a limited number of keys.",
83 for(
void *ptr : tls_ptrs){
84 destroy_thread_object(ptr);
87 pthread_key_delete(engine_key_);
99 RefEngType *RefEngine =
100 reinterpret_cast<RefEngType*
>(pthread_getspecific(engine_key_));
102 if (RefEngine ==
nullptr) {
103 RefEngine =
new RefEngType;
108 mutex::global::lock();
109 *RefEngine = prototype_->clone();
110 mutex::global::unlock();
113 pthread_setspecific(engine_key_, RefEngine);
116 tls_ptrs.push_back(pthread_getspecific(engine_key_));
126 static void destroy_thread_object(
void* p) {
127 RefEngType* ptr =
reinterpret_cast<RefEngType*
>(p);
IntegralEnginePool is a class that will take a Ref<Engine> as a prototype and then clone it multiple ...
Definition integralenginepool.hpp:49
This is thrown when a system problem occurs.
Definition scexception.h:194
IntegralEnginePool(const RefEngType engine)
IntegralEnginePool constructor it takes a sc::Ref<sc::IntegralEngine> and sets that as the prototype ...
Definition integralenginepool.hpp:64
~IntegralEnginePool()
Delete the Engines that we allocated for TLS.
Definition integralenginepool.hpp:77
RefEngType instance()
Function that returns a clone of the prototype engine.
Definition integralenginepool.hpp:96
Contains new MPQC code since version 3.
Definition integralenginepool.hpp:37