Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
medialibrary
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
56
Issues
56
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
VideoLAN
medialibrary
Commits
8f741e7b
Commit
8f741e7b
authored
Aug 09, 2016
by
Hugo Beauzée-Luyssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a std::condition_variable compatibility layer
parent
82a099af
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
137 additions
and
16 deletions
+137
-16
Makefile.am
Makefile.am
+4
-0
src/compat/ConditionVariable.h
src/compat/ConditionVariable.h
+117
-0
src/database/SqliteConnection.h
src/database/SqliteConnection.h
+1
-1
src/discoverer/DiscovererWorker.h
src/discoverer/DiscovererWorker.h
+2
-2
src/metadata_services/vlc/VLCMetadataService.h
src/metadata_services/vlc/VLCMetadataService.h
+2
-2
src/metadata_services/vlc/VLCThumbnailer.h
src/metadata_services/vlc/VLCThumbnailer.h
+2
-2
src/parser/ParserService.h
src/parser/ParserService.h
+2
-2
src/utils/ModificationsNotifier.h
src/utils/ModificationsNotifier.h
+2
-2
src/utils/SWMRLock.h
src/utils/SWMRLock.h
+2
-2
test/mocks/DiscovererCbMock.h
test/mocks/DiscovererCbMock.h
+1
-1
test/samples/Tester.h
test/samples/Tester.h
+1
-1
test/unittest/RemovalNotifierTests.cpp
test/unittest/RemovalNotifierTests.cpp
+1
-1
No files found.
Makefile.am
View file @
8f741e7b
...
...
@@ -6,6 +6,9 @@ AM_CPPFLAGS = -Wall -Wsign-compare -Wextra -Wstrict-aliasing -Wstrict-overflow \
-pipe
MEDIALIB_CPPFLAGS
=
$(AM_CPPFLAGS)
-I
$(top_srcdir)
/include
-I
$(top_srcdir)
/src
if
HAVE_WIN32
MEDIALIB_CPPFLAGS
+=
-D_WIN32_WINNT
=
0x600
endif
libmedialibrary_ladir
=
$(includedir)
/medialibrary
...
...
@@ -147,6 +150,7 @@ noinst_HEADERS = \
src/VideoTrack.h
\
src/compat/Thread.h
\
src/compat/Mutex.h
\
src/compat/ConditionVariable.h
\
$(NULL)
...
...
src/compat/ConditionVariable.h
0 → 100644
View file @
8f741e7b
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2016 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#pragma once
// Unconditionaly include <mutex> for std::unique_lock
#include <mutex>
#include "compat/Mutex.h"
#if CXX11_THREADS
#include <condition_variable>
namespace
medialibrary
{
namespace
compat
{
using
ConditionVariable
=
std
::
condition_variable
;
}
}
#else
#include <windows.h>
namespace
medialibrary
{
namespace
compat
{
class
ConditionVariable
{
public:
using
native_handle_type
=
PCONDITION_VARIABLE
;
ConditionVariable
()
{
InitializeConditionVariable
(
&
m_cond
);
}
void
notify_one
()
noexcept
{
WakeConditionVariable
(
&
m_cond
);
}
void
notify_all
()
noexcept
{
WakeAllConditionVariable
(
&
m_cond
);
}
void
wait
(
std
::
unique_lock
<
Mutex
>&
lock
)
{
SleepConditionVariableCS
(
&
m_cond
,
lock
.
mutex
()
->
native_handle
(),
INFINITE
);
}
template
<
typename
Pred
>
void
wait
(
std
::
unique_lock
<
Mutex
>&
lock
,
Pred
pred
)
{
while
(
pred
()
==
false
)
SleepConditionVariableCS
(
&
m_cond
,
lock
.
mutex
()
->
native_handle
(),
INFINITE
);
}
template
<
typename
Rep
,
typename
Period
,
typename
Pred
>
bool
wait_for
(
std
::
unique_lock
<
Mutex
>&
lock
,
const
std
::
chrono
::
duration
<
Rep
,
Period
>&
relTime
,
Pred
pred
)
{
auto
timeout
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
relTime
);
while
(
pred
()
==
false
)
{
auto
now
=
std
::
chrono
::
system_clock
::
now
();
if
(
SleepConditionVariableCS
(
&
m_cond
,
lock
.
mutex
()
->
native_handle
(),
timeout
.
count
()
)
!=
0
)
{
auto
res
=
GetLastError
();
if
(
res
==
ERROR_TIMEOUT
)
return
false
;
throw
std
::
system_error
{
std
::
make_error_code
(
std
::
errc
::
resource_unavailable_try_again
)
};
}
timeout
-=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
system_clock
::
now
()
-
now
);
}
return
true
;
}
template
<
typename
Clock
,
typename
Period
,
typename
Pred
>
bool
wait_until
(
std
::
unique_lock
<
Mutex
>&
lock
,
const
std
::
chrono
::
time_point
<
Clock
,
Period
>&
relTime
,
Pred
&&
pred
)
{
auto
timeout
=
relTime
-
std
::
chrono
::
steady_clock
::
now
();
return
wait_for
(
lock
,
timeout
,
std
::
forward
<
Pred
>
(
pred
)
);
}
native_handle_type
native_handle
()
{
return
&
m_cond
;
}
private:
CONDITION_VARIABLE
m_cond
;
};
}
}
#endif
src/database/SqliteConnection.h
View file @
8f741e7b
...
...
@@ -26,7 +26,7 @@
#include <functional>
#include <memory>
#include <sqlite3.h>
#include
<condition_variable>
#include
"compat/ConditionVariable.h"
#include <unordered_map>
#include <string>
...
...
src/discoverer/DiscovererWorker.h
View file @
8f741e7b
...
...
@@ -23,7 +23,7 @@
#pragma once
#include <atomic>
#include
<condition_variable>
#include
"compat/ConditionVariable.h"
#include <memory>
#include <queue>
#include <string>
...
...
@@ -65,7 +65,7 @@ private:
compat
::
Thread
m_thread
;
std
::
queue
<
Task
>
m_tasks
;
compat
::
Mutex
m_mutex
;
std
::
condition_v
ariable
m_cond
;
compat
::
ConditionV
ariable
m_cond
;
std
::
atomic_bool
m_run
;
std
::
vector
<
std
::
unique_ptr
<
IDiscoverer
>>
m_discoverers
;
IMediaLibraryCb
*
m_cb
;
...
...
src/metadata_services/vlc/VLCMetadataService.h
View file @
8f741e7b
...
...
@@ -23,7 +23,7 @@
#ifndef VLCMETADATASERVICE_H
#define VLCMETADATASERVICE_H
#include
<condition_variable>
#include
"compat/ConditionVariable.h"
#include <vlcpp/vlc.hpp>
#include <mutex>
...
...
@@ -48,7 +48,7 @@ private:
private:
VLC
::
Instance
m_instance
;
compat
::
Mutex
m_mutex
;
std
::
condition_v
ariable
m_cond
;
compat
::
ConditionV
ariable
m_cond
;
};
}
...
...
src/metadata_services/vlc/VLCThumbnailer.h
View file @
8f741e7b
...
...
@@ -22,7 +22,7 @@
#pragma once
#include
<condition_variable>
#include
"compat/ConditionVariable.h"
#include <vlcpp/vlc.hpp>
...
...
@@ -58,7 +58,7 @@ private:
private:
VLC
::
Instance
m_instance
;
compat
::
Mutex
m_mutex
;
std
::
condition_v
ariable
m_cond
;
compat
::
ConditionV
ariable
m_cond
;
std
::
unique_ptr
<
IImageCompressor
>
m_compressor
;
// Per thumbnail variables
std
::
unique_ptr
<
uint8_t
[]
>
m_buff
;
...
...
src/parser/ParserService.h
View file @
8f741e7b
...
...
@@ -23,7 +23,7 @@
#pragma once
#include <atomic>
#include
<condition_variable>
#include
"compat/ConditionVariable.h"
#include <queue>
#include "Task.h"
...
...
@@ -83,7 +83,7 @@ private:
IParserCb
*
m_parserCb
;
bool
m_stopParser
;
bool
m_paused
;
std
::
condition_v
ariable
m_cond
;
compat
::
ConditionV
ariable
m_cond
;
std
::
queue
<
std
::
unique_ptr
<
parser
::
Task
>>
m_tasks
;
std
::
vector
<
compat
::
Thread
>
m_threads
;
compat
::
Mutex
m_lock
;
...
...
src/utils/ModificationsNotifier.h
View file @
8f741e7b
...
...
@@ -23,7 +23,7 @@
#pragma once
#include <atomic>
#include
<condition_variable>
#include
"compat/ConditionVariable.h"
#include <functional>
#include <vector>
#include <chrono>
...
...
@@ -154,7 +154,7 @@ private:
// Notifier thread
compat
::
Mutex
m_lock
;
std
::
condition_v
ariable
m_cond
;
compat
::
ConditionV
ariable
m_cond
;
compat
::
Thread
m_notifierThread
;
std
::
atomic_bool
m_stop
;
std
::
chrono
::
time_point
<
std
::
chrono
::
steady_clock
>
m_timeout
;
...
...
src/utils/SWMRLock.h
View file @
8f741e7b
...
...
@@ -22,7 +22,7 @@
#pragma once
#include
<condition_variable>
#include
"compat/ConditionVariable.h"
#include "compat/Mutex.h"
#include <atomic>
...
...
@@ -85,7 +85,7 @@ public:
}
private:
std
::
condition_v
ariable
m_writeDoneCond
;
compat
::
ConditionV
ariable
m_writeDoneCond
;
compat
::
Mutex
m_lock
;
unsigned
int
m_nbReader
;
unsigned
int
m_nbReaderWaiting
;
...
...
test/mocks/DiscovererCbMock.h
View file @
8f741e7b
...
...
@@ -75,7 +75,7 @@ public:
private:
std
::
atomic_bool
m_done
;
std
::
atomic_bool
m_waitingReload
;
std
::
condition_v
ariable
m_cond
;
compat
::
ConditionV
ariable
m_cond
;
compat
::
Mutex
m_mutex
;
};
...
...
test/samples/Tester.h
View file @
8f741e7b
...
...
@@ -48,7 +48,7 @@ private:
virtual
void
onDiscoveryCompleted
(
const
std
::
string
&
)
override
;
virtual
void
onParsingStatsUpdated
(
uint32_t
percent
)
override
;
std
::
condition_v
ariable
m_parsingCompleteVar
;
compat
::
ConditionV
ariable
m_parsingCompleteVar
;
compat
::
Mutex
m_parsingMutex
;
bool
m_done
;
bool
m_discoveryCompleted
;
...
...
test/unittest/RemovalNotifierTests.cpp
View file @
8f741e7b
...
...
@@ -55,7 +55,7 @@ public:
private:
std
::
mutex
m_lock
;
std
::
condition_v
ariable
m_cond
;
compat
::
ConditionV
ariable
m_cond
;
uint32_t
m_nbMedia
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment