Fix tabs introduced in latest commits...

This commit is contained in:
vsonnier
2017-05-21 09:58:45 +02:00
parent e0af609224
commit 41c7dd231b
4 changed files with 180 additions and 181 deletions
+41 -41
View File
@@ -37,15 +37,15 @@ public:
/*! Create safe blocking queue. */
ThreadBlockingQueue() {
//at least 1 (== Exchanger)
m_circular_buffer.resize(MIN_ITEM_NB + 1); //there is one slot more than the size for internal management.
m_circular_buffer.resize(MIN_ITEM_NB + 1); //there is one slot more than the size for internal management.
};
//Copy constructor
ThreadBlockingQueue(const ThreadBlockingQueue& sq) {
std::lock_guard < std::mutex > lock(sq.m_mutex);
m_circular_buffer = sq.m_circular_buffer;
m_head = sq.m_head;
m_tail = sq.m_tail;
m_head = sq.m_head;
m_tail = sq.m_tail;
}
/*! Destroy safe queue. */
@@ -64,7 +64,7 @@ public:
if (max_num_items > (unsigned int)privateMaxNumElements()) {
//Only raise the existing max size, never reduce it
//for simplification sake at runtime.
m_circular_buffer.resize(max_num_items + 1); // there is 1 extra allocated slot.
m_circular_buffer.resize(max_num_items + 1); // there is 1 extra allocated slot.
//m_head and m_tail stays valid.
m_cond_not_full.notify_all();
}
@@ -100,11 +100,11 @@ public:
return false;
}
//m_tail is already the next valid place an item can be put
m_circular_buffer[m_tail] = item;
m_tail = nextIndex(m_tail, (int)m_circular_buffer.size());
//m_tail is already the next valid place an item can be put
m_circular_buffer[m_tail] = item;
m_tail = nextIndex(m_tail, (int)m_circular_buffer.size());
m_cond_not_empty.notify_all();
m_cond_not_empty.notify_all();
return true;
}
@@ -120,9 +120,9 @@ public:
return false;
}
//m_tail is already the next valid place an item can be put
m_circular_buffer[m_tail] = item;
m_tail = nextIndex(m_tail, (int)m_circular_buffer.size());
//m_tail is already the next valid place an item can be put
m_circular_buffer[m_tail] = item;
m_tail = nextIndex(m_tail, (int)m_circular_buffer.size());
m_cond_not_empty.notify_all();
return true;
@@ -156,7 +156,7 @@ public:
}
item = m_circular_buffer[m_head];
m_head = nextIndex(m_head, (int)m_circular_buffer.size());
m_head = nextIndex(m_head, (int)m_circular_buffer.size());
m_cond_not_full.notify_all();
return true;
@@ -174,8 +174,8 @@ public:
return false;
}
item = m_circular_buffer[m_head];
m_head = nextIndex(m_head, (int)m_circular_buffer.size());
item = m_circular_buffer[m_head];
m_head = nextIndex(m_head, (int)m_circular_buffer.size());
m_cond_not_full.notify_all();
return true;
@@ -214,8 +214,8 @@ public:
*/
void flush() {
std::lock_guard < std::mutex > lock(m_mutex);
m_head = 0;
m_tail = 0;
m_head = 0;
m_tail = 0;
m_cond_not_full.notify_all();
}
@@ -231,7 +231,7 @@ public:
m_circular_buffer.swap(sq.m_circular_buffer);
std::swap(m_head, sq.m_head);
std::swap(m_tail, sq.m_tail);
std::swap(m_tail, sq.m_tail);
if (privateSize() > 0) {
m_cond_not_empty.notify_all();
@@ -257,10 +257,10 @@ public:
std::lock_guard < std::mutex > lock1(m_mutex);
std::lock_guard < std::mutex > lock2(sq.m_mutex);
m_circular_buffer = sq.m_circular_buffer;
m_circular_buffer = sq.m_circular_buffer;
m_head = sq.m_head;
m_tail = sq.m_tail;
m_head = sq.m_head;
m_tail = sq.m_tail;
if (privateSize() > 0) {
m_cond_not_empty.notify_all();
@@ -277,31 +277,31 @@ private:
/// use a circular buffer structure to prevent allocations / reallocations (fixed array + modulo)
std::vector<T> m_circular_buffer;
/**
* The 'head' index of the element at the head of the deque, 'tail'
* the next (valid !) index at which an element can be pushed.
* m_head == m_tail means empty.
*/
int m_head = 0, m_tail = 0;
/**
* The 'head' index of the element at the head of the deque, 'tail'
* the next (valid !) index at which an element can be pushed.
* m_head == m_tail means empty.
*/
int m_head = 0, m_tail = 0;
//
inline int nextIndex(int index, int modulus) const {
return (index + 1 == modulus) ? 0 : index + 1;
}
//
inline int nextIndex(int index, int modulus) const {
return (index + 1 == modulus) ? 0 : index + 1;
}
//
inline int privateSize() const {
if (m_head <= m_tail) {
return m_tail - m_head;
}
//
inline int privateSize() const {
if (m_head <= m_tail) {
return m_tail - m_head;
}
return (m_tail - m_head + (int)m_circular_buffer.size());
}
return (m_tail - m_head + (int)m_circular_buffer.size());
}
//
inline int privateMaxNumElements() const {
return (int)m_circular_buffer.size() - 1;
}
//
inline int privateMaxNumElements() const {
return (int)m_circular_buffer.size() - 1;
}
mutable std::mutex m_mutex;
std::condition_variable m_cond_not_empty;
+62 -62
View File
@@ -4,7 +4,7 @@
#include "Timer.h"
#ifdef _WIN32
#include <windows.h>
#include <windows.h>
#endif
#include <iostream>
@@ -12,167 +12,167 @@
Timer::Timer(void) : time_elapsed(0), system_milliseconds(0), start_time(0), end_time(0), last_update(0), num_updates(0), paused_time(0), offset(0), paused_state(false), lock_state(false), lock_rate(0)
{
#ifdef _WIN32
// According to Microsoft, QueryPerformanceXXX API is perfectly
//fine for Windows 7+ systems, and use the highest appropriate counter.
//this only need to be done once.
::QueryPerformanceFrequency(&win_frequency);
// According to Microsoft, QueryPerformanceXXX API is perfectly
//fine for Windows 7+ systems, and use the highest appropriate counter.
//this only need to be done once.
::QueryPerformanceFrequency(&win_frequency);
#endif;
}
void Timer::start(void)
{
update();
num_updates = 0;
start_time = system_milliseconds;
last_update = start_time;
paused_state = false;
lock_state = false;
lock_rate = 0;
paused_time = 0;
offset = 0;
update();
num_updates = 0;
start_time = system_milliseconds;
last_update = start_time;
paused_state = false;
lock_state = false;
lock_rate = 0;
paused_time = 0;
offset = 0;
}
void Timer::stop(void)
{
end_time = system_milliseconds;
end_time = system_milliseconds;
}
void Timer::reset(void)
{
start();
start();
}
void Timer::lockFramerate(float f_rate)
{
lock_rate = 1.0f/f_rate;
lock_state = true;
lock_rate = 1.0f/f_rate;
lock_state = true;
}
void Timer::unlock()
{
unsigned long msec_tmp = system_milliseconds;
lock_state = false;
unsigned long msec_tmp = system_milliseconds;
lock_state = false;
update();
last_update = system_milliseconds-(unsigned long)lock_rate;
offset += msec_tmp-system_milliseconds;
lock_rate = 0;
update();
last_update = system_milliseconds-(unsigned long)lock_rate;
offset += msec_tmp-system_milliseconds;
lock_rate = 0;
}
bool Timer::locked()
{
return lock_state;
return lock_state;
}
void Timer::update(void)
{
num_updates++;
last_update = system_milliseconds;
if (lock_state)
{
system_milliseconds += (unsigned long)(lock_rate*1000.0);
}
else
{
num_updates++;
last_update = system_milliseconds;
if (lock_state)
{
system_milliseconds += (unsigned long)(lock_rate*1000.0);
}
else
{
#ifdef _WIN32
//Use QuaryPerformanceCounter, imune to problems sometimes
//multimedia timers have.
LARGE_INTEGER win_current_count;
::QueryPerformanceCounter(&win_current_count);
//Use QuaryPerformanceCounter, imune to problems sometimes
//multimedia timers have.
LARGE_INTEGER win_current_count;
::QueryPerformanceCounter(&win_current_count);
system_milliseconds = (unsigned long)(win_current_count.QuadPart * 1000.0 / win_frequency.QuadPart);
system_milliseconds = (unsigned long)(win_current_count.QuadPart * 1000.0 / win_frequency.QuadPart);
#else
gettimeofday(&time_val,&time_zone);
gettimeofday(&time_val,&time_zone);
system_milliseconds = (unsigned long)time_val.tv_usec;
system_milliseconds /= 1000;
system_milliseconds += (unsigned long)(time_val.tv_sec*1000);
system_milliseconds = (unsigned long)time_val.tv_usec;
system_milliseconds /= 1000;
system_milliseconds += (unsigned long)(time_val.tv_sec*1000);
#endif
}
}
if (paused_state) paused_time += system_milliseconds-last_update;
if (paused_state) paused_time += system_milliseconds-last_update;
time_elapsed = system_milliseconds-start_time-paused_time+offset;
time_elapsed = system_milliseconds-start_time-paused_time+offset;
}
unsigned long Timer::getMilliseconds(void)
{
return time_elapsed;
return time_elapsed;
}
double Timer::getSeconds(void)
{
return ((double)getMilliseconds())/1000.0;
return ((double)getMilliseconds())/1000.0;
}
void Timer::setMilliseconds(unsigned long milliseconds_in)
{
offset -= (system_milliseconds-start_time-paused_time+offset)-milliseconds_in;
offset -= (system_milliseconds-start_time-paused_time+offset)-milliseconds_in;
}
void Timer::setSeconds(double seconds_in)
{
setMilliseconds((long)(seconds_in*1000.0));
setMilliseconds((long)(seconds_in*1000.0));
}
double Timer::lastUpdateSeconds(void)
{
return ((double)lastUpdateMilliseconds())/1000.0;
return ((double)lastUpdateMilliseconds())/1000.0;
}
unsigned long Timer::lastUpdateMilliseconds(void)
{
return system_milliseconds-last_update;
return system_milliseconds-last_update;
}
unsigned long Timer::totalMilliseconds()
{
return system_milliseconds-start_time;
return system_milliseconds-start_time;
}
double Timer::totalSeconds(void)
{
return totalMilliseconds()/1000.0;
return totalMilliseconds()/1000.0;
}
unsigned long Timer::getNumUpdates(void)
{
return num_updates;
return num_updates;
}
void Timer::paused(bool pause_in)
{
paused_state = pause_in;
paused_state = pause_in;
}
bool Timer::paused()
{
return paused_state;
return paused_state;
}
void Timer::timerTestFunc() {
+1 -2
View File
@@ -18,7 +18,6 @@
class Timer {
private:
//units are microsecs:
unsigned long time_elapsed;
unsigned long system_milliseconds;
unsigned long start_time;
@@ -32,7 +31,7 @@ private:
struct timeval time_val;
struct timezone time_zone;
#else
LARGE_INTEGER win_frequency;
LARGE_INTEGER win_frequency;
#endif;
bool paused_state;