diff --git a/configure.ac b/configure.ac index 798e260d..5beea972 100644 --- a/configure.ac +++ b/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 ======================= diff --git a/src/Makefile.am b/src/Makefile.am index 89eebfd2..46a3fbe1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/lyrics.h b/src/lyrics.h index 450a9166..32739c32 100644 --- a/src/lyrics.h +++ b/src/lyrics.h @@ -21,6 +21,7 @@ #ifndef NCMPCPP_LYRICS_H #define NCMPCPP_LYRICS_H + #include #include #include @@ -30,40 +31,7 @@ #include "lyrics_fetcher.h" #include "screen.h" #include "song.h" - -template -struct Shared -{ - struct Resource - { - Resource(std::mutex &mutex, ResourceT &resource) - : m_lock(std::unique_lock(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 m_lock; - ResourceT &m_resource; - }; - - Shared(){ } - - template - Shared(ValueT &&value) - : m_resource(std::forward(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, Tabbable { diff --git a/src/utility/shared_resource.h b/src/utility/shared_resource.h new file mode 100644 index 00000000..99150b64 --- /dev/null +++ b/src/utility/shared_resource.h @@ -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 + +template +struct Shared +{ + struct Resource + { + Resource(std::mutex &mutex, ResourceT &resource) + : m_lock(std::unique_lock(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 m_lock; + ResourceT &m_resource; + }; + + Shared(){ } + + template + Shared(ValueT &&value) + : m_resource(std::forward(value)) + { } + + Resource acquire() { return Resource(m_mutex, m_resource); } + +private: + std::mutex m_mutex; + ResourceT m_resource; +}; + +#endif // NCMPCPP_UTILITY_SHARED_RESOURCE_H