Move Shared class to a separate file
This commit is contained in:
21
configure.ac
21
configure.ac
@@ -247,27 +247,6 @@ PKG_CHECK_MODULES([libcurl], [libcurl], [
|
||||
AC_MSG_ERROR([libcurl is required!])
|
||||
)
|
||||
|
||||
dnl AC_PATH_PROG(CURL_CONFIG, curl-config)
|
||||
dnl if test "$CURL_CONFIG" != "" ; then
|
||||
dnl CPPFLAGS="$CPPFLAGS `$CURL_CONFIG --cflags`"
|
||||
dnl AC_CHECK_LIB(curl, curl_easy_init, LIBS="$LIBS `$CURL_CONFIG --libs`",
|
||||
dnl if test "$curl" = "yes" ; then
|
||||
dnl AC_MSG_ERROR([curl library is required])
|
||||
dnl fi
|
||||
dnl )
|
||||
dnl AC_CHECK_HEADERS([curl/curl.h], ,
|
||||
dnl if test "$curl" = "yes" ; then
|
||||
dnl AC_MSG_ERROR([missing curl.h header])
|
||||
dnl fi
|
||||
dnl )
|
||||
dnl else
|
||||
dnl AC_CHECK_LIB(curl, curl_easy_init, LIBS="$LIBS -lcurl",
|
||||
dnl if test "$curl" = "yes" ; then
|
||||
dnl AC_MSG_ERROR([curl library is required])
|
||||
dnl fi
|
||||
dnl )
|
||||
dnl fi
|
||||
|
||||
dnl =======================
|
||||
dnl = checking for taglib =
|
||||
dnl =======================
|
||||
|
||||
@@ -64,6 +64,7 @@ noinst_HEADERS = \
|
||||
utility/html.h \
|
||||
utility/option_parser.h \
|
||||
utility/readline.h \
|
||||
utility/shared_resource.h \
|
||||
utility/string.h \
|
||||
utility/type_conversions.h \
|
||||
utility/wide_string.h \
|
||||
|
||||
36
src/lyrics.h
36
src/lyrics.h
@@ -21,6 +21,7 @@
|
||||
#ifndef NCMPCPP_LYRICS_H
|
||||
#define NCMPCPP_LYRICS_H
|
||||
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
@@ -30,40 +31,7 @@
|
||||
#include "lyrics_fetcher.h"
|
||||
#include "screen.h"
|
||||
#include "song.h"
|
||||
|
||||
template <typename ResourceT>
|
||||
struct Shared
|
||||
{
|
||||
struct Resource
|
||||
{
|
||||
Resource(std::mutex &mutex, ResourceT &resource)
|
||||
: m_lock(std::unique_lock<std::mutex>(mutex)), m_resource(resource)
|
||||
{ }
|
||||
|
||||
ResourceT &operator*() { return m_resource; }
|
||||
const ResourceT &operator*() const { return m_resource; }
|
||||
|
||||
ResourceT *operator->() { return &m_resource; }
|
||||
const ResourceT *operator->() const { return &m_resource; }
|
||||
|
||||
private:
|
||||
std::unique_lock<std::mutex> m_lock;
|
||||
ResourceT &m_resource;
|
||||
};
|
||||
|
||||
Shared(){ }
|
||||
|
||||
template <typename ValueT>
|
||||
Shared(ValueT &&value)
|
||||
: m_resource(std::forward<ValueT>(value))
|
||||
{ }
|
||||
|
||||
Resource acquire() { return Resource(m_mutex, m_resource); }
|
||||
|
||||
private:
|
||||
std::mutex m_mutex;
|
||||
ResourceT m_resource;
|
||||
};
|
||||
#include "utility/shared_resource.h"
|
||||
|
||||
struct Lyrics: Screen<NC::Scrollpad>, Tabbable
|
||||
{
|
||||
|
||||
60
src/utility/shared_resource.h
Normal file
60
src/utility/shared_resource.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2008-2016 by Andrzej Rybczak *
|
||||
* electricityispower@gmail.com *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 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 General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef NCMPCPP_UTILITY_SHARED_RESOURCE_H
|
||||
#define NCMPCPP_UTILITY_SHARED_RESOURCE_H
|
||||
|
||||
#include <mutex>
|
||||
|
||||
template <typename ResourceT>
|
||||
struct Shared
|
||||
{
|
||||
struct Resource
|
||||
{
|
||||
Resource(std::mutex &mutex, ResourceT &resource)
|
||||
: m_lock(std::unique_lock<std::mutex>(mutex)), m_resource(resource)
|
||||
{ }
|
||||
|
||||
ResourceT &operator*() { return m_resource; }
|
||||
const ResourceT &operator*() const { return m_resource; }
|
||||
|
||||
ResourceT *operator->() { return &m_resource; }
|
||||
const ResourceT *operator->() const { return &m_resource; }
|
||||
|
||||
private:
|
||||
std::unique_lock<std::mutex> m_lock;
|
||||
ResourceT &m_resource;
|
||||
};
|
||||
|
||||
Shared(){ }
|
||||
|
||||
template <typename ValueT>
|
||||
Shared(ValueT &&value)
|
||||
: m_resource(std::forward<ValueT>(value))
|
||||
{ }
|
||||
|
||||
Resource acquire() { return Resource(m_mutex, m_resource); }
|
||||
|
||||
private:
|
||||
std::mutex m_mutex;
|
||||
ResourceT m_resource;
|
||||
};
|
||||
|
||||
#endif // NCMPCPP_UTILITY_SHARED_RESOURCE_H
|
||||
Reference in New Issue
Block a user