Imported Upstream version 1.5.1
This commit is contained in:
48
cpp/include/util/annotations.h
Normal file
48
cpp/include/util/annotations.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2013 by Felix Hupfeld.
|
||||
*
|
||||
* Licensed under the BSD License, see LICENSE file for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __clang__
|
||||
// TODO(fhupfeld): add annotations to synchronization primitives.
|
||||
// Taken from http://www.mail-archive.com/linuxkernelnewbies@googlegroups.com/msg01455.html.
|
||||
#define GUARDED_BY(x) __attribute__ ((guarded_by(x)))
|
||||
#define GUARDED_VAR __attribute__ ((guarded))
|
||||
#define PT_GUARDED_BY(x) __attribute__ ((point_to_guarded_by(x)))
|
||||
#define PT_GUARDED_VAR __attribute__ ((point_to_guarded))
|
||||
#define ACQUIRED_AFTER(...) __attribute__ ((acquired_after(__VA_ARGS__)))
|
||||
#define ACQUIRED_BEFORE(...) __attribute__ ((acquired_before(__VA_ARGS__)))
|
||||
#define LOCKABLE __attribute__ ((lockable))
|
||||
#define SCOPED_LOCKABLE __attribute__ ((scoped_lockable))
|
||||
#define EXCLUSIVE_LOCK_FUNCTION(...) __attribute__ ((exclusive_lock(__VA_ARGS__)))
|
||||
#define SHARED_LOCK_FUNCTION(...) __attribute__ ((shared_lock(__VA_ARGS__)))
|
||||
#define EXCLUSIVE_TRYLOCK_FUNCTION(...) __attribute__ ((exclusive_trylock(__VA_ARGS__)))
|
||||
#define SHARED_TRYLOCK_FUNCTION(...) __attribute__ ((shared_trylock(__VA_ARGS__)))
|
||||
#define UNLOCK_FUNCTION(...) __attribute__ ((unlock(__VA_ARGS__)))
|
||||
#define LOCK_RETURNED(x) __attribute__ ((lock_returned(x)))
|
||||
#define LOCKS_EXCLUDED(...) __attribute__ ((locks_excluded(__VA_ARGS__)))
|
||||
#define EXCLUSIVE_LOCKS_REQUIRED(...) __attribute__ ((exclusive_locks_required(__VA_ARGS__)))
|
||||
#define SHARED_LOCKS_REQUIRED(...) __attribute__ ((shared_locks_required(__VA_ARGS__)))
|
||||
#define NO_THREAD_SAFETY_ANALYSIS __attribute__ ((no_thread_safety_analysis))
|
||||
#else
|
||||
#define GUARDED_BY(x)
|
||||
#define GUARDED_VAR
|
||||
#define PT_GUARDED_BY(x)
|
||||
#define PT_GUARDED_VAR
|
||||
#define ACQUIRED_AFTER(...)
|
||||
#define ACQUIRED_BEFORE(...)
|
||||
#define LOCKABLE
|
||||
#define SCOPED_LOCKABLE
|
||||
#define EXCLUSIVE_LOCK_FUNCTION(...)
|
||||
#define SHARED_LOCK_FUNCTION(...)
|
||||
#define EXCLUSIVE_TRYLOCK_FUNCTION(...)
|
||||
#define SHARED_TRYLOCK_FUNCTION(...)
|
||||
#define UNLOCK_FUNCTION(...)
|
||||
#define LOCK_RETURNED(x)
|
||||
#define LOCKS_EXCLUDED(...)
|
||||
#define EXCLUSIVE_LOCKS_REQUIRED(...)
|
||||
#define SHARED_LOCKS_REQUIRED(...)
|
||||
#define NO_THREAD_SAFETY_ANALYSIS
|
||||
#endif
|
||||
57
cpp/include/util/error_log.h
Normal file
57
cpp/include/util/error_log.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2011 by Bjoern Kolbeck, Zuse Institute Berlin
|
||||
*
|
||||
* Licensed under the BSD License, see LICENSE file for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CPP_INCLUDE_UTIL_ERROR_LOG_H_
|
||||
#define CPP_INCLUDE_UTIL_ERROR_LOG_H_
|
||||
|
||||
#include "boost/thread.hpp"
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
namespace xtreemfs {
|
||||
namespace util {
|
||||
|
||||
/**
|
||||
* A simple class that stores the last max_entries
|
||||
* error messages. Thread safe.
|
||||
*/
|
||||
class ErrorLog {
|
||||
public:
|
||||
static ErrorLog* error_log;
|
||||
|
||||
ErrorLog(int max_entries) : max_entries_(max_entries) {}
|
||||
~ErrorLog() {}
|
||||
|
||||
void AppendError(const std::string& message) {
|
||||
boost::mutex::scoped_lock lock(error_messages_mutex_);
|
||||
if (error_messages_.size() == max_entries_) {
|
||||
error_messages_.pop_front();
|
||||
}
|
||||
error_messages_.push_back(message);
|
||||
}
|
||||
|
||||
std::list<std::string> error_messages() {
|
||||
boost::mutex::scoped_lock lock(error_messages_mutex_);
|
||||
return error_messages_;
|
||||
}
|
||||
|
||||
private:
|
||||
int max_entries_;
|
||||
boost::mutex error_messages_mutex_;
|
||||
std::list<std::string> error_messages_;
|
||||
};
|
||||
|
||||
void initialize_error_log(int max_entries);
|
||||
|
||||
void shutdown_error_log();
|
||||
|
||||
} // namespace util
|
||||
} // namespace xtreemfs
|
||||
|
||||
|
||||
#endif // CPP_INCLUDE_UTIL_ERROR_LOG_H_
|
||||
|
||||
68
cpp/include/util/logging.h
Normal file
68
cpp/include/util/logging.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2010 by Bjoern Kolbeck, Zuse Institute Berlin
|
||||
*
|
||||
* Licensed under the BSD License, see LICENSE file for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CPP_INCLUDE_UTIL_LOGGING_H_
|
||||
#define CPP_INCLUDE_UTIL_LOGGING_H_
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
namespace xtreemfs {
|
||||
namespace util {
|
||||
|
||||
enum LogLevel {
|
||||
LEVEL_EMERG = 0,
|
||||
LEVEL_ALERT = 1,
|
||||
LEVEL_CRIT = 2,
|
||||
LEVEL_ERROR = 3,
|
||||
LEVEL_WARN = 4,
|
||||
LEVEL_NOTICE = 5,
|
||||
LEVEL_INFO = 6,
|
||||
LEVEL_DEBUG = 7
|
||||
};
|
||||
|
||||
class Logging {
|
||||
public:
|
||||
static Logging* log;
|
||||
|
||||
explicit Logging(LogLevel level = LEVEL_ERROR);
|
||||
Logging(LogLevel level, std::ostream* stream);
|
||||
virtual ~Logging();
|
||||
|
||||
std::ostream& getLog(LogLevel level) {
|
||||
return getLog(level, "?", 0);
|
||||
}
|
||||
|
||||
std::ostream& getLog(LogLevel level, const char* file, int line);
|
||||
|
||||
bool loggingActive(LogLevel level);
|
||||
|
||||
private:
|
||||
/** Log stream. */
|
||||
std::ostream& log_stream_;
|
||||
|
||||
/** Contains the pointer to the stream which has to be freed by the shutdown
|
||||
* method. */
|
||||
std::ostream* log_file_stream_;
|
||||
|
||||
LogLevel level_;
|
||||
|
||||
char levelToChar(LogLevel level);
|
||||
};
|
||||
|
||||
LogLevel stringToLevel(std::string stringLevel, LogLevel defaultLevel);
|
||||
void initialize_logger(LogLevel level);
|
||||
void initialize_logger(LogLevel level, std::string logfilePath);
|
||||
void initialize_logger(std::string stringLevel,
|
||||
std::string logfilePath,
|
||||
LogLevel defaultLevel);
|
||||
void shutdown_logger();
|
||||
|
||||
} // namespace util
|
||||
} // namespace xtreemfs
|
||||
|
||||
#endif // CPP_INCLUDE_UTIL_LOGGING_H_
|
||||
61
cpp/include/util/synchronized_queue.h
Normal file
61
cpp/include/util/synchronized_queue.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright (c) 2012 by Matthias Noack, Zuse Institute Berlin
|
||||
*
|
||||
* Licensed under the BSD License, see LICENSE file for details.
|
||||
*
|
||||
* This specific file is based on an example found in this article:
|
||||
* http://www.quantnet.com/cplusplus-multithreading-boost/
|
||||
*/
|
||||
|
||||
#ifndef CPP_INCLUDE_UTIL_SYNCHRONIZED_QUEUE_H_
|
||||
#define CPP_INCLUDE_UTIL_SYNCHRONIZED_QUEUE_H_
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <queue>
|
||||
|
||||
namespace xtreemfs {
|
||||
namespace util {
|
||||
|
||||
/** Queue class that has thread synchronization. Intended to synchronize
|
||||
* threads in a producer consumer scenario.*/
|
||||
template <typename T>
|
||||
class SynchronizedQueue {
|
||||
public:
|
||||
|
||||
/** Add data to the queue and notify others. Never blocks. */
|
||||
void Enqueue(const T& data) {
|
||||
boost::mutex::scoped_lock lock(mutex_);
|
||||
queue_.push(data);
|
||||
// Notify others that data is ready
|
||||
queue_not_empty_cond_.notify_one();
|
||||
}
|
||||
|
||||
/** Get data from the queue. Blocks if no data is available. */
|
||||
T Dequeue() {
|
||||
boost::mutex::scoped_lock lock(mutex_);
|
||||
|
||||
// When there is no data, wait till someone fills it.
|
||||
// Lock is automatically released in the wait and obtained
|
||||
// again after the wait
|
||||
while (queue_.size() == 0) {
|
||||
queue_not_empty_cond_.wait(lock);
|
||||
}
|
||||
|
||||
T result = queue_.front();
|
||||
queue_.pop();
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
/** STL queue for data storage. */
|
||||
std::queue<T> queue_;
|
||||
/** The mutex to synchronize queue access. */
|
||||
boost::mutex mutex_;
|
||||
/** The condition to wait for if the queue is empty. */
|
||||
boost::condition_variable queue_not_empty_cond_;
|
||||
|
||||
};
|
||||
|
||||
} // namespace util
|
||||
} // namespace xtreemfs
|
||||
#endif
|
||||
45
cpp/include/util/zipf_generator.h
Normal file
45
cpp/include/util/zipf_generator.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Juan Gonzalez de Benito.
|
||||
*
|
||||
* Licensed under the BSD License, see LICENSE file for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CPP_INCLUDE_UTIL_ZIPF_GENERATOR_H_
|
||||
#define CPP_INCLUDE_UTIL_ZIPF_GENERATOR_H_
|
||||
|
||||
namespace xtreemfs {
|
||||
namespace util {
|
||||
|
||||
class ZipfGenerator {
|
||||
public:
|
||||
/**
|
||||
* Creates a new ZipfGenerator with the given skewness
|
||||
* skew: Desired skewness
|
||||
*/
|
||||
explicit ZipfGenerator(const double skew);
|
||||
|
||||
/**
|
||||
* Returns a number from [0,this.size)
|
||||
*/
|
||||
int next();
|
||||
|
||||
/**
|
||||
* Modifies the rank of the generated indexes
|
||||
*/
|
||||
void set_size(const int new_size);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Returns the probability (0.0,1.0) to choose a given index
|
||||
*/
|
||||
double get_probability(const int rank);
|
||||
|
||||
int size;
|
||||
double skew;
|
||||
double bottom;
|
||||
};
|
||||
} // namespace util
|
||||
} // namespace xtreemfs
|
||||
|
||||
#endif // CPP_INCLUDE_UTIL_ZIPF_GENERATOR_H_
|
||||
Reference in New Issue
Block a user