Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
9.4 kB · 332 lines
C++
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- *//* * Main authors: * Christian Schulte <schulte@gecode.org> * * Copyright: * Christian Schulte, 2016 * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */
namespace Gecode {
/// Class to provide synchronization class TracerBase : public HeapAllocated { protected: /// Mutex to provide synchronization GECODE_KERNEL_EXPORT static Support::Mutex m; };
template<class View> class ViewTraceRecorder;
/** * \brief Tracer that process view trace information * \ingroup TaskTrace */ template<class View> class ViewTracer : public TracerBase { template<class ViewForTraceRecorder> friend class ViewTraceRecorder; private: /** * \brief Init function synchronization * * Just calls the actual init function protected by a mutex. * */ void _init(const Space& home, const ViewTraceRecorder<View>& t); /** * \brief Prune function synchronization * * Just calls the actual prune function protected by a mutex. * */ void _prune(const Space& home, const ViewTraceRecorder<View>& t, const ViewTraceInfo& vti, int i, typename TraceTraits<View>::TraceDelta& d); /** * \brief Fail function synchronization * * Just calls the actual fail function protected by a mutex. * */ void _fail(const Space& home, const ViewTraceRecorder<View>& t); /** * \brief Fixpoint function synchronization * * Just calls the actual fixpoint function protected by a mutex. */ void _fix(const Space& home, const ViewTraceRecorder<View>& t); /** * \brief Done function synchronization * * Just calls the actual done function protected by a mutex. */ void _done(const Space& home, const ViewTraceRecorder<View>& t); public: /// Constructor ViewTracer(void); /** * \brief Init function * * The init function is called when the trace collector has * been initialized. */ virtual void init(const Space& home, const ViewTraceRecorder<View>& t) = 0; /** * \brief Prune function * * The variable at position \a i has been modified where * the modification is described by \a d. Additional * information about how the variable has been changed is * provided by the trace collector \a t and execution * information \a ei. */ virtual void prune(const Space& home, const ViewTraceRecorder<View>& t, const ViewTraceInfo& vti, int i, typename TraceTraits<View>::TraceDelta& d) = 0; /** * \brief Fail function * * The fail function is called whenever \a home containing the * trace collector \a t has been failed. */ virtual void fail(const Space& home, const ViewTraceRecorder<View>& t) = 0; /** * \brief Fixpoint function * * The fixpoint function is called whenever \a home containing * the trace collector \a t reaches a fixpoint (and fixpoint * tracing is enabled). */ virtual void fix(const Space& home, const ViewTraceRecorder<View>& t) = 0; /** * \brief Done function * * The done function is called whenever the trace collector \a t * is done and will terminate. */ virtual void done(const Space& home, const ViewTraceRecorder<View>& t) = 0; /// Destructor virtual ~ViewTracer(void); };
/** * \brief Tracer * \ingroup TaskTrace */ class Tracer : public TracerBase { friend class Space; friend class PostInfo; private: /** * \brief Propagate function synchronization * * Just calls the actual propagate function protected by a mutex. * */ void _propagate(const Space& home, const PropagateTraceInfo& pti); /** * \brief Commit function synchronization * * Just calls the actual commit function protected by a mutex. * */ void _commit(const Space& home, const CommitTraceInfo& cti); /** * \brief Post function synchronization * * Just calls the actual post function protected by a mutex. * */ void _post(const Space& home, const PostTraceInfo& pti); public: /// Constructor Tracer(void); /** * \brief Propagate function * * The propagate function is called when a propagator has been * executed. */ virtual void propagate(const Space& home, const PropagateTraceInfo& pti) = 0; /** * \brief Commit function * * The commit function is called when a brancher has executed * a commit operation. */ virtual void commit(const Space& home, const CommitTraceInfo& cti) = 0; /** * \brief Post function * * The post function is called when an attempt to post a propagator * has been executed. */ virtual void post(const Space& home, const PostTraceInfo& pti) = 0; /// Destructor virtual ~Tracer(void); };
/** * \brief Default tracer * \ingroup TaskTrace */ class GECODE_KERNEL_EXPORT StdTracer : public Tracer { protected: /// Output stream to use std::ostream& os; public: /// Initialize with output stream \a os StdTracer(std::ostream& os = std::cerr); /** * \brief Propagate function * * The propagate function is called when a propagator has been * executed. */ virtual void propagate(const Space& home, const PropagateTraceInfo& pti); /** * \brief Commit function * * The commit function is called when a brancher has executed * a commit operation. */ virtual void commit(const Space& home, const CommitTraceInfo& cti); /** * \brief Post function * * The post function is called when an attempt to post a propagator * has been executed. */ virtual void post(const Space& home, const PostTraceInfo& pti); /// Default tracer (printing to std::cerr) static StdTracer def; };
/* * View tracer */
template<class View> forceinline ViewTracer<View>::ViewTracer(void) { }
template<class View> forceinline void ViewTracer<View>::_init(const Space& home, const ViewTraceRecorder<View>& t) { Support::Lock l(m); init(home,t); } template<class View> forceinline void ViewTracer<View>::_prune(const Space& home, const ViewTraceRecorder<View>& t, const ViewTraceInfo& vti, int i, typename TraceTraits<View>::TraceDelta& d) { Support::Lock l(m); prune(home,t,vti,i,d); } template<class View> forceinline void ViewTracer<View>::_fail(const Space& home, const ViewTraceRecorder<View>& t) { Support::Lock l(m); fail(home,t); } template<class View> forceinline void ViewTracer<View>::_fix(const Space& home, const ViewTraceRecorder<View>& t) { Support::Lock l(m); fix(home,t); } template<class View> forceinline void ViewTracer<View>::_done(const Space& home, const ViewTraceRecorder<View>& t) { Support::Lock l(m); done(home,t); }
template<class View> forceinline ViewTracer<View>::~ViewTracer(void) { }
/* * Tracer */
forceinline Tracer::Tracer(void) { }
forceinline void Tracer::_propagate(const Space& home, const PropagateTraceInfo& pti) { Support::Lock l(m); propagate(home,pti); } forceinline void Tracer::_commit(const Space& home, const CommitTraceInfo& cti) { Support::Lock l(m); commit(home,cti); } forceinline void Tracer::_post(const Space& home, const PostTraceInfo& pti) { Support::Lock l(m); post(home,pti); }
forceinline Tracer::~Tracer(void) { }
}
// STATISTICS: kernel-trace