another directory rename: failstar -> fail

"failstar" sounds like a name for a cruise liner from the 80s.  As "*" isn't a
desirable part of directory names, just name the whole thing "fail/", the core
parts being stored in "fail/core/".

Additionally fixing two build system dependency issues:
 - missing jobserver -> protomessages dependency
 - broken bochs -> fail dependency (add_custom_target DEPENDS only allows plain
   file dependencies ... cmake for the win)


git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@956 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
hsc
2012-03-08 19:43:02 +00:00
commit b70b6fb43a
921 changed files with 473161 additions and 0 deletions

7
core/util/CMakeLists.txt Normal file
View File

@ -0,0 +1,7 @@
set(SRCS
SynchronizedCounter.cc
Logger.hpp
Logger.cc
)
add_library(util ${SRCS})

29
core/util/Logger.cc Normal file
View File

@ -0,0 +1,29 @@
// Author: Adrian Böckenkamp
// Date: 21.11.2011
#include <sstream>
#include <fstream>
#include <cassert>
#include <time.h>
#include "Logger.hpp"
using std::endl;
void Logger::add(const std::string& what, const std::string& descr)
{
(*m_pDest) << "[" << descr;
if(m_showTime)
{
time_t rawtime;
struct tm* timeinfo;
char buffer [80];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 80, "%H:%M:%S", timeinfo);
(*m_pDest) << " " << buffer;
}
(*m_pDest) << "] " << what;
}

67
core/util/Logger.hpp Normal file
View File

@ -0,0 +1,67 @@
#ifndef __LOGGER_HPP__
#define __LOGGER_HPP__
// Author: Adrian Böckenkamp
// Date: 21.11.2011
#include <iostream>
#include <sstream>
/**
* \class Logger
* Provides logging mechanisms.
*/
class Logger
{
private:
std::ostream* m_pDest;
std::string m_description;
bool m_showTime;
public:
/**
* Constructor.
* @param description Description shown alongside each log entry in
* square brackets [ ]. Can be overridden in single add() calls.
* @param show_time Show a timestamp with each log entry.
* @param dest Stream to log into.
*/
Logger(const std::string& description = "Fail*", bool show_time = true,
std::ostream& dest = std::cout)
: m_pDest(&dest), m_description(description), m_showTime(show_time) { }
/**
* Change the default description which is shown alongside each log
* entry in square brackets [ ].
* @param descr The description text.
*/
void setDescription(const std::string& descr)
{
m_description = descr;
}
/**
* Add a new log entry.
* @param what Message for log entry.
* @param descr Description shown alongside this log entry in square
* brackets [ ].
*/
void add(const std::string& what, const std::string& descr);
/**
* Add a new log entry.
* @param what Message for log entry. The default description is
* being used in square brackets [ ].
*/
void add(const std::string& what) { add(what, m_description); }
/**
* Simplifies the logging.
* @param v data to log
*/
template<class T>
inline std::ostream& operator <<(const T& v)
{
std::stringstream ss;
ss << v;
add(ss.str());
return (*m_pDest);
}
};
#endif /* __LOGGER_HPP__ */

50
core/util/MemoryMap.hpp Normal file
View File

@ -0,0 +1,50 @@
#ifndef __MEMORYMAP_HPP__
#define __MEMORYMAP_HPP__
#ifdef BOOST_1_46_OR_NEWER
#include <boost/icl/interval_set.hpp>
using namespace boost::icl;
#endif
#include <set>
#include "SAL/SALConfig.hpp"
/**
* \class MemoryMap
* An efficient container for memory maps with holes.
*/
class MemoryMap
{
#ifdef BOOST_1_46_OR_NEWER
typedef interval<sal::address_t>::type address_interval;
typedef interval_set<sal::address_t>::type address_set;
address_set as;
public:
MemoryMap() {}
void clear() { as.clear(); }
void add(sal::address_t addr, int size) { as.add(address_interval(addr, addr+size-1)); }
void isMatching(sal::address_t addr, int size) { return intersects(as, address_interval(addr, addr+size-1)); }
#endif
std::set<sal::address_t> as;
public:
MemoryMap() {}
void clear() { as.clear(); }
void add(sal::address_t addr, int size = 1)
{
for (int i = 0; i < size; ++i) {
as.insert(addr + i);
}
}
bool isMatching(sal::address_t addr, int size = 1)
{
for (int i = 0; i < size; ++i) {
if (as.find(addr + i) != as.end()) {
return true;
}
}
return false;
}
};
#endif

View File

@ -0,0 +1,30 @@
#include "SynchronizedCounter.hpp"
int SynchronizedCounter::increment()
{
// Acquire lock on the queue
#ifndef __puma
boost::unique_lock<boost::mutex> lock(m_mutex);
#endif
return ++m_counter;
} // Lock is automatically released here
int SynchronizedCounter::decrement()
{
// Acquire lock on the queue
#ifndef __puma
boost::unique_lock<boost::mutex> lock(m_mutex);
#endif
return --m_counter;
} // Lock is automatically released here
int SynchronizedCounter::getValue()
{
// Acquire lock on the queue
#ifndef __puma
boost::unique_lock<boost::mutex> lock(m_mutex);
#endif
return m_counter;
} // Lock is automatically released here

View File

@ -0,0 +1,26 @@
// Thread safe counter
#ifndef __SYNCHRONIZED_COUNTER_HPP__
#define __SYNCHRONIZED_COUNTER_HPP__
#ifndef __puma
#include <boost/thread.hpp>
#include <sys/types.h>
#endif
class SynchronizedCounter
{
private:
int m_counter;
#ifndef __puma
boost::mutex m_mutex; // The mutex to synchronise on
#endif
public:
SynchronizedCounter() : m_counter(0) {};
int increment();
int decrement();
int getValue();
};
#endif

View File

@ -0,0 +1,75 @@
// Map class that has thread synchronisation
// TODO We should consider to use Aspects for synchronisation primitives..
#ifndef __SYNCHRONIZED_MAP_HPP__
#define __SYNCHRONIZED_MAP_HPP__
#include <map>
#ifndef __puma
#include <boost/thread.hpp>
#endif
template <typename Tkey, typename Tvalue>
class SynchronizedMap
{
private:
typedef std::map< Tkey, Tvalue > Tmap;
typedef typename Tmap::iterator Tit;
Tmap m_map; // Use STL map to store data
#ifndef __puma
boost::mutex m_mutex; // The mutex to synchronise on
#endif
public:
int Size(){
#ifndef __puma
boost::unique_lock<boost::mutex> lock(m_mutex);
#endif
return m_map.size();
}
/**
* Add data to the map, return false if already present
* @param key Map key
* @param value value according to key
* @return false if key already present
*/
bool insert(const Tkey& key, const Tvalue& value )
{
// Acquire lock on the queue
#ifndef __puma
boost::unique_lock<boost::mutex> lock(m_mutex);
#endif
if( m_map.find(key) == m_map.end() ){ // not present, add it
m_map[key] = value;
return true;
}else{ // item is already in, oops
return false;
}
} // Lock is automatically released here
/**
* Remove value from the map.
* @param key The Map key to remove
* @return false if key was not present
*
*/
bool remove(const Tkey& key, Tvalue& value)
{
// Acquire lock on the queue
#ifndef __puma
boost::unique_lock<boost::mutex> lock(m_mutex);
#endif
Tit iterator;
if ( (iterator = m_map.find(key)) != m_map.end() ) {
value = iterator->second;
m_map.erase(iterator);
return true;
}else{
return false;
}
} // Lock is automatically released here
};
#endif

View File

@ -0,0 +1,90 @@
// Queue class that has thread synchronisation
// from: http://www.quantnet.com/cplusplus-multithreading-boost/
#ifndef __SYNCHRONIZED_QUEUE_HPP__
#define __SYNCHRONIZED_QUEUE_HPP__
#include <queue>
#ifndef __puma
#include <boost/thread.hpp>
#endif
template <typename T>
class SynchronizedQueue
{
private:
std::queue<T> m_queue; // Use STL queue to store data
#ifndef __puma
boost::mutex m_mutex; // The mutex to synchronise on
boost::condition_variable m_cond; // The condition to wait for
#endif
public:
int Size(){
#ifndef __puma
boost::unique_lock<boost::mutex> lock(m_mutex);
#endif
return m_queue.size();
}
// Add data to the queue and notify others
void Enqueue(const T& data)
{
// Acquire lock on the queue
#ifndef __puma
boost::unique_lock<boost::mutex> lock(m_mutex);
#endif
// Add the data to the queue
m_queue.push(data);
// Notify others that data is ready
#ifndef __puma
m_cond.notify_one();
#endif
} // Lock is automatically released here
/**
* Get data from the queue. Wait for data if not available
*/
T Dequeue()
{
// Acquire lock on the queue
#ifndef __puma
boost::unique_lock<boost::mutex> lock(m_mutex);
#endif
// When there is no data, wait till someone fills it.
// Lock is automatically released in the wait and obtained
// again after the wait
#ifndef __puma
while (m_queue.size()==0) m_cond.wait(lock);
#endif
// Retrieve the data from the queue
T result=m_queue.front(); m_queue.pop();
return result;
} // Lock is automatically released here
/**
* Get data from the queue. Non blocking variant.
* @param d Pointer to copy queue element to
* @return false if no element in queue
*
*/
bool Dequeue_nb(T& d)
{
// Acquire lock on the queue
#ifndef __puma
boost::unique_lock<boost::mutex> lock(m_mutex);
#endif
// When there is no data, return false.
// Lock is automatically released in the wait and obtained
// again after the wait
if (m_queue.size() > 0){
// Retrieve the data from the queue
d = m_queue.front(); m_queue.pop();
return true;
}else{
return false;
}
} // Lock is automatically released here
};
#endif