* Test for equality of two polynomials.
*/
bool operator == (const Polynomial<number> & p) const;
-
+
/**
* Print coefficients.
*/
void print(std::ostream& out) const;
-
+
/**
- * Write or read the data of this object to or
+ * Write or read the data of this object to or
* from a stream for the purpose of serialization.
- */
+ */
template <class Archive>
void serialize (Archive & ar, const unsigned int version);
static const std::vector<double> &
get_coefficients (const unsigned int p);
- static std::vector<const std::vector<double> *> recursive_coefficients;
+ /**
+ * Vector with already computed
+ * coefficients. For each degree of the
+ * polynomial, we keep one pointer to
+ * the list of coefficients; we do so
+ * rather than keeping a vector of
+ * vectors in order to simplify
+ * programming multithread-safe. In
+ * order to avoid memory leak, we use a
+ * shared_ptr in order to correctly
+ * free the memory of the vectors when
+ * the global destructor is called.
+ */
+ static std::vector<std_cxx1x::shared_ptr<const std::vector<double> > > recursive_coefficients;
};
}
return value;
}
-
+
template <typename number>
// $Id$
// Version: $Name$
//
-// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2010 by the deal.II authors
+// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2010, 2011 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
}
template <typename number >
- bool
+ bool
Polynomial<number>::operator == (const Polynomial<number> & p) const
{
return (p.coefficients == coefficients);
// Reserve space for polynomials up to degree 19. Should be sufficient
// for the start.
- std::vector<const std::vector<double> *>
- Hierarchical::recursive_coefficients(
- 20, static_cast<const std::vector<double>*>(0));
+ std::vector<std_cxx1x::shared_ptr<const std::vector<double> > >
+ Hierarchical::recursive_coefficients(20);
// no, then generate the
// respective coefficients
{
- recursive_coefficients.resize (k+1, 0);
+ recursive_coefficients.resize (k+1);
if (k<=1)
{
// now make these arrays
// const
- recursive_coefficients[0] = c0;
- recursive_coefficients[1] = c1;
+ recursive_coefficients[0] =
+ std_cxx1x::shared_ptr<const std::vector<double> >(c0);
+ recursive_coefficients[1] =
+ std_cxx1x::shared_ptr<const std::vector<double> >(c1);
}
else if (k==2)
{
(*c2)[1] = -4.*a;
(*c2)[2] = 4.*a;
- recursive_coefficients[2] = c2;
+ recursive_coefficients[2] =
+ std_cxx1x::shared_ptr<const std::vector<double> >(c2);
}
else
{
// created vector to the
// const pointer in the
// coefficients array
- recursive_coefficients[k] = ck;
+ recursive_coefficients[k] =
+ std_cxx1x::shared_ptr<const std::vector<double> >(ck);
};
};
}
// then get a pointer to the array
// of coefficients. do that in a MT
- // safe way
- coefficients_lock.acquire ();
- const std::vector<double> *p = recursive_coefficients[k];
- coefficients_lock.release ();
-
- // return the object pointed
- // to. since this object does not
- // change any more once computed,
- // this is MT safe
- return *p;
+ // safe way
+ Threads::ThreadMutex::ScopedLock lock (coefficients_lock);
+ return *recursive_coefficients[k];
}