Remove condvar, mutex and time from libmediation
This commit is contained in:
parent
a49263716f
commit
b098a6de41
@ -10,19 +10,15 @@ FILE(GLOB mediation_sources RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"fs/logstream.h"
|
||||
"fs/systemlog.h"
|
||||
"fs/textfile.h"
|
||||
"system/condvar.h"
|
||||
"system/mutex.h"
|
||||
"system/terminatablethread.h"
|
||||
"time/time.cpp"
|
||||
"time/time.h"
|
||||
"types/types.cpp"
|
||||
"types/types.h"
|
||||
)
|
||||
|
||||
IF(MSVC OR MINGW)
|
||||
LIST(APPEND mediation_sources "fs/osdep/file_win32.cpp" "system/osdep/common_win32.cpp" "system/osdep/condvar_win32.cpp" "system/osdep/mutex_win32.cpp" "system/osdep/terminatablethread_win32.cpp")
|
||||
LIST(APPEND mediation_sources "fs/osdep/file_win32.cpp" "system/osdep/common_win32.cpp" "system/osdep/terminatablethread_win32.cpp")
|
||||
ELSE()
|
||||
LIST(APPEND mediation_sources "fs/osdep/file_unix.cpp" "system/osdep/condvar_linux.cpp" "system/osdep/mutex_linux.cpp" "system/osdep/terminatablethread_linux.cpp")
|
||||
LIST(APPEND mediation_sources "fs/osdep/file_unix.cpp" "system/osdep/terminatablethread_linux.cpp")
|
||||
ENDIF()
|
||||
|
||||
add_library (mediation ${mediation_sources})
|
||||
|
@ -1,12 +1,10 @@
|
||||
|
||||
#ifndef _SAFE_QUEUE_H
|
||||
#define _SAFE_QUEUE_H
|
||||
#ifndef SAFE_QUEUE_H
|
||||
#define SAFE_QUEUE_H
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include <system/condvar.h>
|
||||
#include <system/mutex.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
template< typename T >
|
||||
class SafeQueue
|
||||
@ -18,29 +16,29 @@ public:
|
||||
:
|
||||
m_maxSize( maxSize )
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
virtual ~SafeQueue()
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
Mutex::ScopedLock lk(&m_mtx);
|
||||
std::lock_guard<std::mutex> lk(m_mtx);
|
||||
|
||||
return m_queue.empty();
|
||||
};
|
||||
}
|
||||
|
||||
size_type size() const
|
||||
{
|
||||
Mutex::ScopedLock lk(&m_mtx);
|
||||
std::lock_guard<std::mutex> lk(m_mtx);
|
||||
|
||||
return m_queue.size();
|
||||
};
|
||||
}
|
||||
|
||||
bool push(const T& val)
|
||||
{
|
||||
Mutex::ScopedLock lk(&m_mtx);
|
||||
std::lock_guard<std::mutex> lk(m_mtx);
|
||||
|
||||
if ( m_queue.size()>=m_maxSize )
|
||||
return false;
|
||||
@ -51,7 +49,7 @@ public:
|
||||
|
||||
T pop()
|
||||
{
|
||||
Mutex::ScopedLock lk(&m_mtx);
|
||||
std::lock_guard<std::mutex> lk(m_mtx);
|
||||
|
||||
T val = m_queue.front();
|
||||
m_queue.pop();
|
||||
@ -60,7 +58,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
mutable Mutex m_mtx;
|
||||
mutable std::mutex m_mtx;
|
||||
std::queue<T> m_queue;
|
||||
const size_type m_maxSize;
|
||||
|
||||
@ -76,30 +74,30 @@ class SafeQueueWithNotification : public SafeQueue<T>
|
||||
public:
|
||||
SafeQueueWithNotification(
|
||||
const uint32_t maxSize,
|
||||
Mutex* const mtx,
|
||||
ConditionVariable* const cond )
|
||||
std::mutex& mtx,
|
||||
std::condition_variable& cond )
|
||||
:
|
||||
SafeQueue<T>( maxSize ),
|
||||
m_mtx( mtx ),
|
||||
m_cond( cond )
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
bool push( const T& val )
|
||||
{
|
||||
Mutex::ScopedLock lk( m_mtx );
|
||||
std::lock_guard<std::mutex> lk( m_mtx );
|
||||
|
||||
if( !SafeQueue<T>::push( val ) )
|
||||
return false;
|
||||
|
||||
m_cond->notify_one();
|
||||
m_cond.notify_one();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
Mutex* const m_mtx;
|
||||
ConditionVariable* const m_cond;
|
||||
std::mutex& m_mtx;
|
||||
std::condition_variable& m_cond;
|
||||
|
||||
SafeQueueWithNotification( const SafeQueueWithNotification<T>& );
|
||||
SafeQueueWithNotification& operator= ( const SafeQueueWithNotification<T>& );
|
||||
@ -114,20 +112,20 @@ public:
|
||||
:
|
||||
SafeQueueWithNotification<T>(
|
||||
maxSize,
|
||||
&m_mtx,
|
||||
&m_cond )
|
||||
m_mtx,
|
||||
m_cond )
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
virtual ~WaitableSafeQueue() {};
|
||||
virtual ~WaitableSafeQueue() {}
|
||||
|
||||
T pop()
|
||||
{
|
||||
Mutex::ScopedLock lk( &m_mtx );
|
||||
std::unique_lock<std::mutex> lk( m_mtx );
|
||||
|
||||
while( SafeQueue<T>::empty() )
|
||||
{
|
||||
m_cond.wait(&lk);
|
||||
m_cond.wait(lk);
|
||||
}
|
||||
|
||||
T val = SafeQueue<T>::pop();
|
||||
@ -136,8 +134,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
Mutex m_mtx;
|
||||
ConditionVariable m_cond;
|
||||
std::mutex m_mtx;
|
||||
std::condition_variable m_cond;
|
||||
|
||||
WaitableSafeQueue( const WaitableSafeQueue<T>& );
|
||||
WaitableSafeQueue& operator= ( const WaitableSafeQueue<T>& );
|
||||
|
@ -1,26 +0,0 @@
|
||||
#ifndef IPSOFT_COND_VAR_H
|
||||
#define IPSOFT_COND_VAR_H
|
||||
|
||||
#include "system/mutex.h"
|
||||
#include "time/time.h"
|
||||
|
||||
|
||||
class ConditionVariable
|
||||
{
|
||||
public:
|
||||
ConditionVariable();
|
||||
~ConditionVariable();
|
||||
|
||||
void notify_one();
|
||||
void notify_all();
|
||||
|
||||
void wait( Mutex::ScopedLock* const lock );
|
||||
private:
|
||||
void* const m_impl;
|
||||
|
||||
ConditionVariable( const ConditionVariable& );
|
||||
ConditionVariable& operator=( const ConditionVariable& );
|
||||
|
||||
};
|
||||
|
||||
#endif// IPSOFT_COND_VAR_H
|
@ -1,40 +0,0 @@
|
||||
#ifndef IPSOFT_MUTEX_H
|
||||
#define IPSOFT_MUTEX_H
|
||||
|
||||
class Mutex
|
||||
{
|
||||
friend class ScopedLock;
|
||||
public:
|
||||
//! This class should be used only in one stream.
|
||||
class ScopedLock
|
||||
{
|
||||
friend class ConditionVariable;
|
||||
public:
|
||||
ScopedLock( Mutex* const );
|
||||
~ScopedLock();
|
||||
|
||||
private:
|
||||
friend class ConditionVariableImpl;
|
||||
|
||||
ScopedLock( const ScopedLock& );
|
||||
ScopedLock& operator=( const ScopedLock& );
|
||||
|
||||
Mutex* const m_mtx;
|
||||
};
|
||||
|
||||
Mutex();
|
||||
~Mutex();
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
private:
|
||||
friend class ConditionVariableImpl;
|
||||
|
||||
Mutex( const Mutex& );
|
||||
Mutex& operator=( const Mutex& );
|
||||
|
||||
void* m_mtxImpl;
|
||||
};
|
||||
|
||||
#endif// IPSOFT_MUTEX_H
|
@ -1,106 +0,0 @@
|
||||
/***********************************************************************
|
||||
* File: system/condvar_linux.cpp
|
||||
* Author: Andrey Kolesnikov
|
||||
* Date: 28 dec 2005
|
||||
***********************************************************************/
|
||||
|
||||
/*
|
||||
$Log: condvar_linux.cpp,v $
|
||||
Revision 1.4 2007/03/07 10:07:36 andreyk
|
||||
|
||||
Fixed GCC compile errors
|
||||
|
||||
Revision 1.3 2007/03/07 09:16:30 andreyk
|
||||
Добавлена функция timed_wait для ожидания с точностью до миллисекунд
|
||||
|
||||
Revision 1.2 2007/02/02 16:39:23 andreyk
|
||||
*** empty log message ***
|
||||
|
||||
Revision 1.1 2006/04/19 17:00:03 mike
|
||||
*** empty log message ***
|
||||
|
||||
Revision 1.4 2006/03/03 17:19:34 andreyk
|
||||
В область видимости private классов добавлены конструктор копирования и оператор присваивания, не имеющие реализации.
|
||||
|
||||
Revision 1.3 2006/02/15 12:11:47 andreyk
|
||||
Исправления в коде, вызывавшем warning при компиляции
|
||||
|
||||
Revision 1.2 2006/02/06 08:40:28 andreyk
|
||||
В файле теперь используются юниксовые окончания строк.
|
||||
|
||||
Revision 1.1 2005/12/28 14:34:34 andreyk
|
||||
|
||||
Building project under Linux
|
||||
|
||||
*/
|
||||
|
||||
#include "../condvar.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
class ConditionVariableImpl
|
||||
{
|
||||
|
||||
public:
|
||||
ConditionVariableImpl()
|
||||
{
|
||||
pthread_cond_init( &m_cond, NULL );
|
||||
}
|
||||
|
||||
~ConditionVariableImpl()
|
||||
{
|
||||
pthread_cond_destroy( &m_cond );
|
||||
}
|
||||
|
||||
void notify_one()
|
||||
{
|
||||
pthread_cond_signal( &m_cond );
|
||||
}
|
||||
|
||||
void notify_all()
|
||||
{
|
||||
pthread_cond_broadcast( &m_cond );
|
||||
}
|
||||
|
||||
void wait( Mutex::ScopedLock* const lock )
|
||||
{
|
||||
pthread_cond_wait(
|
||||
&m_cond,
|
||||
reinterpret_cast<pthread_mutex_t*>( lock->m_mtx->m_mtxImpl ) );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
pthread_cond_t m_cond;
|
||||
|
||||
};
|
||||
|
||||
|
||||
ConditionVariable::ConditionVariable()
|
||||
:
|
||||
m_impl( new ConditionVariableImpl() )
|
||||
{
|
||||
}
|
||||
|
||||
ConditionVariable::~ConditionVariable()
|
||||
{
|
||||
delete reinterpret_cast<ConditionVariableImpl*>(m_impl);
|
||||
}
|
||||
|
||||
void ConditionVariable::notify_one()
|
||||
{
|
||||
reinterpret_cast<ConditionVariableImpl*>(m_impl)->notify_one();
|
||||
}
|
||||
|
||||
void ConditionVariable::notify_all()
|
||||
{
|
||||
reinterpret_cast<ConditionVariableImpl*>(m_impl)->notify_all();
|
||||
}
|
||||
|
||||
void ConditionVariable::wait( Mutex::ScopedLock* const lock )
|
||||
{
|
||||
reinterpret_cast<ConditionVariableImpl*>(m_impl)->wait( lock );
|
||||
}
|
||||
|
@ -1,109 +0,0 @@
|
||||
#include "system/condvar.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
SIGNAL = 0,
|
||||
BROADCAST = 1,
|
||||
MAX_EVENTS = 2
|
||||
};
|
||||
|
||||
class ConditionVariableImpl
|
||||
{
|
||||
public:
|
||||
ConditionVariableImpl()
|
||||
:
|
||||
m_waitersCount( 0 )
|
||||
{
|
||||
m_events[SIGNAL] = CreateEvent(
|
||||
NULL, // no security
|
||||
FALSE, // auto-reset event
|
||||
FALSE, // non-signaled initially
|
||||
NULL ); // unnamed
|
||||
|
||||
m_events[BROADCAST] = CreateEvent(
|
||||
NULL, // no security
|
||||
TRUE, // manual-reset
|
||||
FALSE, // non-signaled initially
|
||||
NULL ); // unnamed
|
||||
}
|
||||
|
||||
~ConditionVariableImpl()
|
||||
{
|
||||
CloseHandle( m_events[SIGNAL] );
|
||||
CloseHandle( m_events[BROADCAST] );
|
||||
}
|
||||
|
||||
void notify_one()
|
||||
{
|
||||
Mutex::ScopedLock sl( &m_waitersCountLock );
|
||||
|
||||
if( m_waitersCount > 0 )
|
||||
SetEvent( m_events[SIGNAL] );
|
||||
}
|
||||
|
||||
void notify_all()
|
||||
{
|
||||
Mutex::ScopedLock sl( &m_waitersCountLock );
|
||||
|
||||
if( m_waitersCount > 0 )
|
||||
SetEvent( m_events[BROADCAST] );
|
||||
}
|
||||
|
||||
void do_wait( Mutex* const mtx )
|
||||
{
|
||||
{
|
||||
Mutex::ScopedLock sl( &m_waitersCountLock );
|
||||
m_waitersCount++;
|
||||
}
|
||||
|
||||
mtx->unlock();
|
||||
|
||||
int result = WaitForMultipleObjects( 2, m_events, FALSE, INFINITE );
|
||||
|
||||
{
|
||||
Mutex::ScopedLock sl( &m_waitersCountLock );
|
||||
|
||||
m_waitersCount--;
|
||||
if( (result == WAIT_OBJECT_0 + BROADCAST) && (m_waitersCount == 0) )
|
||||
ResetEvent( m_events[BROADCAST] );
|
||||
}
|
||||
|
||||
mtx->lock();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
HANDLE m_events[MAX_EVENTS];
|
||||
unsigned int m_waitersCount;
|
||||
Mutex m_waitersCountLock;
|
||||
};
|
||||
|
||||
ConditionVariable::ConditionVariable()
|
||||
:
|
||||
m_impl( new ConditionVariableImpl() )
|
||||
{
|
||||
}
|
||||
|
||||
ConditionVariable::~ConditionVariable()
|
||||
{
|
||||
delete ((ConditionVariableImpl*)m_impl);
|
||||
}
|
||||
|
||||
void ConditionVariable::notify_all()
|
||||
{
|
||||
((ConditionVariableImpl*)m_impl)->notify_all();
|
||||
}
|
||||
|
||||
void ConditionVariable::notify_one()
|
||||
{
|
||||
((ConditionVariableImpl*)m_impl)->notify_one();
|
||||
}
|
||||
|
||||
void ConditionVariable::wait( Mutex::ScopedLock* const lock )
|
||||
{
|
||||
((ConditionVariableImpl*)m_impl)->do_wait( lock->m_mtx );
|
||||
}
|
||||
|
@ -1,78 +0,0 @@
|
||||
/***********************************************************************
|
||||
* File: system/mutex_linux.cpp
|
||||
* Author: Andrey Kolesnikov
|
||||
* Date: 28 dec 2005
|
||||
***********************************************************************/
|
||||
|
||||
/*
|
||||
$Log: mutex_linux.cpp,v $
|
||||
Revision 1.4 2007/06/22 14:20:19 andreyk
|
||||
*** empty log message ***
|
||||
|
||||
Revision 1.3 2007/02/25 13:35:27 andreyk
|
||||
Внесены небольшие изменения в интерфейс общих классов.
|
||||
|
||||
Revision 1.2 2006/09/21 10:56:10 andreyk
|
||||
Исправлена ошибка в классе Mutex::ScopedLock: Если мютекс отпущен функцией unlock, то функция ScopedLock::~ScopedLock всё равно пыталась его отпустить, что приводило к исключению.
|
||||
|
||||
Revision 1.1 2006/04/19 17:00:03 mike
|
||||
*** empty log message ***
|
||||
|
||||
Revision 1.3 2006/02/06 08:38:39 andreyk
|
||||
В реализацию класса Mutex добавлена проверка на существавание системного объекта перед каждым его использованием.
|
||||
|
||||
Revision 1.2 2006/02/02 11:22:11 andreyk
|
||||
|
||||
Building mediation under linux
|
||||
|
||||
Revision 1.1 2005/12/28 14:34:34 andreyk
|
||||
|
||||
Building project under Linux
|
||||
|
||||
*/
|
||||
|
||||
#include "../mutex.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
Mutex::ScopedLock::ScopedLock( Mutex* mtx )
|
||||
:
|
||||
m_mtx( mtx )
|
||||
{
|
||||
m_mtx->lock();
|
||||
}
|
||||
|
||||
Mutex::ScopedLock::~ScopedLock()
|
||||
{
|
||||
m_mtx->unlock();
|
||||
}
|
||||
|
||||
|
||||
Mutex::Mutex()
|
||||
:
|
||||
m_mtxImpl( new pthread_mutex_t )
|
||||
{
|
||||
pthread_mutex_init( reinterpret_cast<pthread_mutex_t*>(m_mtxImpl), NULL );
|
||||
}
|
||||
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
pthread_mutex_destroy( reinterpret_cast<pthread_mutex_t*>(m_mtxImpl) );
|
||||
delete reinterpret_cast<pthread_mutex_t*>(m_mtxImpl);
|
||||
m_mtxImpl = 0;
|
||||
}
|
||||
|
||||
void Mutex::lock()
|
||||
{
|
||||
if( m_mtxImpl )
|
||||
pthread_mutex_lock( reinterpret_cast<pthread_mutex_t*>(m_mtxImpl) );
|
||||
}
|
||||
|
||||
|
||||
void Mutex::unlock()
|
||||
{
|
||||
if( m_mtxImpl )
|
||||
pthread_mutex_unlock( reinterpret_cast<pthread_mutex_t*>(m_mtxImpl) );
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
|
||||
#include "../mutex.h"
|
||||
|
||||
#ifndef _WIN32_WINNT
|
||||
# define _WIN32_WINNT 0x400
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
Mutex::Mutex()
|
||||
:
|
||||
m_mtxImpl( new CRITICAL_SECTION() )
|
||||
{
|
||||
InitializeCriticalSection( (CRITICAL_SECTION*)m_mtxImpl );
|
||||
}
|
||||
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
DeleteCriticalSection( (CRITICAL_SECTION*)m_mtxImpl );
|
||||
delete (LPCRITICAL_SECTION)m_mtxImpl;
|
||||
m_mtxImpl = 0;
|
||||
}
|
||||
|
||||
void Mutex::lock()
|
||||
{
|
||||
if( !m_mtxImpl )
|
||||
return;
|
||||
EnterCriticalSection( (CRITICAL_SECTION*)m_mtxImpl );
|
||||
}
|
||||
|
||||
void Mutex::unlock()
|
||||
{
|
||||
if( !m_mtxImpl )
|
||||
return;
|
||||
LeaveCriticalSection( (CRITICAL_SECTION*)m_mtxImpl );
|
||||
}
|
||||
|
||||
//#endif
|
||||
|
||||
Mutex::ScopedLock::ScopedLock( Mutex* const mtx )
|
||||
:
|
||||
m_mtx( mtx )
|
||||
{
|
||||
m_mtx->lock();
|
||||
}
|
||||
|
||||
Mutex::ScopedLock::~ScopedLock()
|
||||
{
|
||||
m_mtx->unlock();
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
#include "time.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <ctime>
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#include <sys/types.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef LINUX
|
||||
#include <sys/time.h>
|
||||
#include <sys/timex.h>
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SOLARIS
|
||||
//extern time_t timezone;
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifdef MAC
|
||||
//extern time_t timezone;
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include "../system/mutex.h"
|
||||
|
||||
|
||||
namespace mtime
|
||||
{
|
||||
|
||||
uint32_t clockGetTime()
|
||||
{
|
||||
#ifdef WIN32
|
||||
return (uint32_t)GetTickCount();
|
||||
#else
|
||||
// POSIX
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, 0);
|
||||
return (uint32_t) (tv.tv_sec * 1000ull + tv.tv_usec/1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t clockGetTimeEx()
|
||||
{
|
||||
#ifdef WIN32
|
||||
|
||||
static uint32_t prevTics = 0;
|
||||
static uint64_t cycleCount = 0;
|
||||
static Mutex timeMutex;
|
||||
Mutex::ScopedLock lock(&timeMutex);
|
||||
uint32_t tics = (uint32_t) timeGetTime();
|
||||
if (tics < prevTics)
|
||||
cycleCount+= 0x100000000ull;
|
||||
prevTics = tics;
|
||||
return ((uint64_t) tics + cycleCount) * 1000ull;
|
||||
|
||||
|
||||
/*
|
||||
static uint64_t freq = 0;
|
||||
if( freq == 0 )
|
||||
{
|
||||
LARGE_INTEGER timerFrequency;
|
||||
QueryPerformanceFrequency( &timerFrequency );
|
||||
freq = timerFrequency.QuadPart / 1000000ull;
|
||||
}
|
||||
|
||||
LARGE_INTEGER t;
|
||||
QueryPerformanceCounter( &t );
|
||||
return (t.QuadPart+500000l) / freq;
|
||||
*/
|
||||
#else
|
||||
// POSIX
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, 0);
|
||||
return tv.tv_sec * 1000000ull + tv.tv_usec;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
#ifndef __T_MTime_H
|
||||
#define __T_MTime_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "types/types.h"
|
||||
|
||||
|
||||
namespace mtime
|
||||
{
|
||||
class TimeInterval;
|
||||
class DayTimeInterval;
|
||||
};
|
||||
|
||||
namespace mtime
|
||||
{
|
||||
|
||||
// returns the number of milliseconds which have passed since the system started (under Windows) or
|
||||
// since an unspecified point in time under Linux.
|
||||
uint32_t clockGetTime();
|
||||
|
||||
// returns the number of microseconds which have passed since an unspecified point in time.
|
||||
uint64_t clockGetTimeEx();
|
||||
|
||||
};
|
||||
|
||||
#endif //__T_MTime_H
|
@ -15,7 +15,7 @@
|
||||
#include "fs/directory.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <random>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -514,5 +514,7 @@ uint16_t my_ntohs( const uint16_t val )
|
||||
|
||||
uint32_t random32()
|
||||
{
|
||||
return ((uint32_t) rand() << 16) + rand();
|
||||
static std::random_device dev;
|
||||
static std::minstd_rand raand(dev());
|
||||
return static_cast<std::uint32_t>(raand());
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <map>
|
||||
#include <types/types.h>
|
||||
#include <system/terminatablethread.h>
|
||||
#include <system/mutex.h>
|
||||
#include <containers/safequeue.h>
|
||||
#include "abstractreader.h"
|
||||
#include "abstractDemuxer.h"
|
||||
@ -99,16 +98,16 @@ protected:
|
||||
bool m_terminated;
|
||||
WaitableSafeQueue<uint32_t> m_readQueue;
|
||||
ReaderData* getReader(uint32_t readerID);
|
||||
ConditionVariable m_readCond;
|
||||
Mutex m_readMtx;
|
||||
std::condition_variable m_readCond;
|
||||
std::mutex m_readMtx;
|
||||
|
||||
private:
|
||||
int m_id;
|
||||
Mutex m_readersMtx;
|
||||
std::mutex m_readersMtx;
|
||||
std::map<uint32_t, ReaderData*> m_readers;
|
||||
static uint32_t m_newReaderID;
|
||||
static uint32_t createNewReaderID();
|
||||
static Mutex m_genReaderMtx;
|
||||
static std::mutex m_genReaderMtx;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -11,7 +11,7 @@
|
||||
using namespace std;
|
||||
|
||||
uint32_t BufferedReader::m_newReaderID = 0;
|
||||
Mutex BufferedReader::m_genReaderMtx;
|
||||
std::mutex BufferedReader::m_genReaderMtx;
|
||||
const unsigned QUEUE_MAX_SIZE = 4096;
|
||||
|
||||
BufferedReader::BufferedReader (uint32_t blockSize, uint32_t allocSize, uint32_t prereadThreshold):
|
||||
@ -30,14 +30,14 @@ BufferedReader::BufferedReader (uint32_t blockSize, uint32_t allocSize, uint32_t
|
||||
|
||||
ReaderData* BufferedReader::getReader(uint32_t readerID)
|
||||
{
|
||||
Mutex::ScopedLock lock(&m_readersMtx);
|
||||
std::lock_guard<std::mutex> lock(m_readersMtx);
|
||||
map<uint32_t, ReaderData*>::iterator itr = m_readers.find(readerID);
|
||||
return itr != m_readers.end() ? itr->second : 0;
|
||||
}
|
||||
|
||||
bool BufferedReader::incSeek(uint32_t readerID, int64_t offset)
|
||||
{
|
||||
Mutex::ScopedLock lock(&m_readersMtx);
|
||||
std::lock_guard<std::mutex> lock(m_readersMtx);
|
||||
map<uint32_t, ReaderData*>::iterator itr = m_readers.find(readerID);
|
||||
if (itr != m_readers.end()) {
|
||||
ReaderData* data = itr->second;
|
||||
@ -87,7 +87,7 @@ uint32_t BufferedReader::createReader(int readBuffOffset)
|
||||
data->m_lastBlock = false;
|
||||
size_t rSize;
|
||||
{
|
||||
Mutex::ScopedLock lock(&m_readersMtx);
|
||||
std::lock_guard<std::mutex> lock(m_readersMtx);
|
||||
newReaderID = createNewReaderID();
|
||||
m_readers.insert(make_pair(newReaderID, data));
|
||||
rSize = m_readers.size();
|
||||
@ -105,7 +105,7 @@ void BufferedReader::deleteReader(uint32_t readerID)
|
||||
{
|
||||
size_t rSize;
|
||||
{
|
||||
Mutex::ScopedLock lock(&m_readersMtx);
|
||||
std::lock_guard<std::mutex> lock(m_readersMtx);
|
||||
std::map<uint32_t, ReaderData*>::iterator iterator = m_readers.find(readerID);
|
||||
if (iterator == m_readers.end())
|
||||
return;
|
||||
@ -125,7 +125,7 @@ uint8_t* BufferedReader::readBlock(uint32_t readerID, uint32_t& readCnt, int& re
|
||||
{
|
||||
ReaderData* data = 0;
|
||||
{
|
||||
Mutex::ScopedLock lock(&m_readersMtx);
|
||||
std::lock_guard<std::mutex> lock(m_readersMtx);
|
||||
map<uint32_t, ReaderData*>::iterator itr = m_readers.find(readerID);
|
||||
if (itr != m_readers.end()) {
|
||||
data = itr->second;
|
||||
@ -144,9 +144,9 @@ uint8_t* BufferedReader::readBlock(uint32_t readerID, uint32_t& readCnt, int& re
|
||||
|
||||
if (!data->m_nextBlockSize)
|
||||
{
|
||||
Mutex::ScopedLock lk(&m_readMtx);
|
||||
std::unique_lock<std::mutex> lk(m_readMtx);
|
||||
while(data->m_nextBlockSize == 0 && !data->m_eof)
|
||||
m_readCond.wait(&lk);
|
||||
m_readCond.wait(lk);
|
||||
}
|
||||
readCnt = data->m_nextBlockSize >= 0 ? data->m_nextBlockSize : 0;
|
||||
rez = data->m_eof ? DATA_EOF : NO_ERROR;
|
||||
@ -171,7 +171,7 @@ void BufferedReader::notify(uint32_t readerID, uint32_t dataReaded)
|
||||
if (data == 0)
|
||||
return;
|
||||
if (dataReaded >= m_prereadThreshold && !data->m_notified) {
|
||||
Mutex::ScopedLock lock(&m_readersMtx);
|
||||
std::lock_guard<std::mutex> lock(m_readersMtx);
|
||||
data->m_notified = true;
|
||||
data->m_atQueue++;
|
||||
m_readQueue.push(readerID);
|
||||
@ -180,7 +180,7 @@ void BufferedReader::notify(uint32_t readerID, uint32_t dataReaded)
|
||||
|
||||
uint32_t BufferedReader::getReaderCount()
|
||||
{
|
||||
Mutex::ScopedLock lock(&m_readersMtx);
|
||||
std::lock_guard<std::mutex> lock(m_readersMtx);
|
||||
return (uint32_t) m_readers.size();
|
||||
}
|
||||
|
||||
@ -250,14 +250,14 @@ void BufferedReader::thread_main()
|
||||
}
|
||||
|
||||
{
|
||||
Mutex::ScopedLock lk(&m_readMtx);
|
||||
std::lock_guard<std::mutex> lk(m_readMtx);
|
||||
data->m_nextBlockSize = bytesReaded;
|
||||
m_readCond.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
Mutex::ScopedLock lock(&m_readersMtx);
|
||||
std::lock_guard<std::mutex> lock(m_readersMtx);
|
||||
data->m_atQueue--;
|
||||
if (data->m_deleted && data->m_atQueue == 0) {
|
||||
delete data;
|
||||
@ -277,7 +277,7 @@ void BufferedReader::thread_main()
|
||||
void BufferedReader::setFileIterator(FileNameIterator* itr, int readerID)
|
||||
{
|
||||
assert(readerID != -1);
|
||||
Mutex::ScopedLock lock(&m_readersMtx);
|
||||
std::lock_guard<std::mutex> lock(m_readersMtx);
|
||||
std::map<uint32_t, ReaderData*>::iterator reader = m_readers.find(readerID);
|
||||
if (reader != m_readers.end())
|
||||
reader->second->itr = itr;
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include "iso_writer.h"
|
||||
#include <assert.h>
|
||||
#include "time/time.h"
|
||||
#include <time.h>
|
||||
#include "vod_common.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -557,7 +555,6 @@ int64_t ISOFile::size() const
|
||||
|
||||
IsoWriter::IsoWriter()
|
||||
{
|
||||
srand(mtime::clockGetTime());
|
||||
m_volumeId = random32();
|
||||
m_appId = std::string("*tsMuxeR ") + std::string(APP_VERSION);
|
||||
m_impId = std::string("*tsMuxeR ") + int32ToHex(random32());
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "metaDemuxer.h"
|
||||
#include "tsMuxer.h"
|
||||
#include "singleFileMuxer.h"
|
||||
#include <time/time.h>
|
||||
#include <fs/directory.h>
|
||||
#include <fs/textfile.h>
|
||||
#include <vector>
|
||||
@ -261,7 +260,8 @@ void muxBlankPL(const string& appDir, BlurayHelper& blurayHelper, const PIDListM
|
||||
pattern = pattern_1280;
|
||||
patternSize = sizeof(pattern_1280);
|
||||
}
|
||||
string tmpFileName = appDir + string("blank_") + int64ToStr(mtime::clockGetTimeEx()) + string(".264");
|
||||
auto fname_time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||
string tmpFileName = appDir + string("blank_") + std::to_string(fname_time) + string(".264");
|
||||
File file;
|
||||
if (!file.open(tmpFileName.c_str(), File::ofWrite))
|
||||
THROW(ERR_COMMON, "can't create file " << tmpFileName);
|
||||
@ -647,7 +647,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
string fileExt = extractFileExt(argv[2]);
|
||||
fileExt = strToUpperCase(fileExt);
|
||||
uint64_t startTime = mtime::clockGetTimeEx();
|
||||
auto startTime = std::chrono::steady_clock::now();
|
||||
|
||||
int autoChapterLen = 0;
|
||||
vector<double> customChapterList;
|
||||
@ -730,19 +730,20 @@ int main(int argc, char** argv)
|
||||
sMuxer.doMux(unquoteStr(argv[2]), 0);
|
||||
LTRACE(LT_INFO, 2, "Demux complete.");
|
||||
}
|
||||
uint64_t endTime = mtime::clockGetTimeEx();
|
||||
int seconds = (double)(endTime - startTime)/1e6 + 0.5;
|
||||
int minutes = seconds/60;
|
||||
auto endTime = std::chrono::steady_clock::now();
|
||||
auto totalTime = endTime - startTime;
|
||||
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(totalTime);
|
||||
auto minutes = std::chrono::duration_cast<std::chrono::minutes>(totalTime);
|
||||
if (muxMode) {
|
||||
LTRACE2(LT_INFO, "Muxing time: ");
|
||||
}
|
||||
else
|
||||
LTRACE2(LT_INFO, "Demuxing time: ");
|
||||
if (minutes > 0) {
|
||||
LTRACE2(LT_INFO, minutes << " min ");
|
||||
seconds -= minutes*60;
|
||||
if (minutes.count() > 0) {
|
||||
LTRACE2(LT_INFO, minutes.count() << " min ");
|
||||
seconds -= minutes;
|
||||
}
|
||||
LTRACE(LT_INFO, 2, seconds << " sec");
|
||||
LTRACE(LT_INFO, 2, seconds.count() << " sec");
|
||||
|
||||
return 0;
|
||||
} catch(runtime_error& e) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <chrono>
|
||||
|
||||
#include <types/types.h>
|
||||
#include <fs/textfile.h>
|
||||
@ -45,7 +46,6 @@ METADemuxer::METADemuxer(const BufferedReaderManager& readManager):
|
||||
{
|
||||
m_flushDataMode = false;
|
||||
m_totalSize = 0;
|
||||
m_lastReportTime = 0;
|
||||
m_lastProgressY = 0;
|
||||
m_lastReadRez = 0;
|
||||
}
|
||||
@ -1143,8 +1143,8 @@ string METADemuxer::findBluRayFile(const string& streamDir, const string& reques
|
||||
|
||||
void METADemuxer::updateReport(bool checkTime)
|
||||
{
|
||||
uint64_t currentTime = mtime::clockGetTimeEx();
|
||||
if (!checkTime || currentTime - m_lastReportTime > 250000ull) {
|
||||
auto currentTime = std::chrono::steady_clock::now();
|
||||
if (!checkTime || currentTime - m_lastReportTime > std::chrono::microseconds(250000)) {
|
||||
uint64_t currentProcessedSize = 0;
|
||||
double progress = 100.0;
|
||||
if (m_totalSize > 0) {
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <chrono>
|
||||
#include <queue>
|
||||
#include "vod_common.h"
|
||||
#include "vodCoreException.h"
|
||||
@ -177,7 +178,7 @@ private:
|
||||
int m_lastReadRez;
|
||||
ContainerToReaderWrapper m_containerReader;
|
||||
int m_lastProgressY;
|
||||
uint64_t m_lastReportTime;
|
||||
std::chrono::steady_clock::time_point m_lastReportTime;
|
||||
uint64_t m_totalSize;
|
||||
bool m_flushDataMode;
|
||||
const BufferedReaderManager& m_readManager;
|
||||
|
@ -67,7 +67,7 @@ private:
|
||||
bool m_asyncMode;
|
||||
//int32_t m_fileBlockSize;
|
||||
std::string m_outFileName;
|
||||
ConditionVariable reinitCond;
|
||||
std::condition_variable reinitCond;
|
||||
METADemuxer m_metaDemuxer;
|
||||
int64_t m_cutStart;
|
||||
int64_t m_cutEnd;
|
||||
|
Loading…
x
Reference in New Issue
Block a user