Replace boost thread with std thread for queue; refine cmake files.
This commit is contained in:
+79
-75
@@ -6,94 +6,98 @@ if(MSVC)
|
||||
endif()
|
||||
|
||||
set(HEADERS
|
||||
globals.h
|
||||
http_async_client.h
|
||||
http_client.h
|
||||
http_connection.h
|
||||
http_message.h
|
||||
http_parser.h
|
||||
http_request.h
|
||||
http_request_handler.h
|
||||
http_request_parser.h
|
||||
http_response.h
|
||||
http_response_parser.h
|
||||
http_server.h
|
||||
logger.h
|
||||
queue.h
|
||||
rest_async_client.h
|
||||
rest_client.h
|
||||
rest_request_handler.h
|
||||
rest_server.h
|
||||
rest_service.h
|
||||
rest_service_manager.h
|
||||
url.h
|
||||
utility.h
|
||||
)
|
||||
globals.h
|
||||
http_async_client.h
|
||||
http_client.h
|
||||
http_connection.h
|
||||
http_message.h
|
||||
http_parser.h
|
||||
http_request.h
|
||||
http_request_handler.h
|
||||
http_request_parser.h
|
||||
http_response.h
|
||||
http_response_parser.h
|
||||
http_server.h
|
||||
logger.h
|
||||
queue.h
|
||||
rest_async_client.h
|
||||
rest_client.h
|
||||
rest_request_handler.h
|
||||
rest_server.h
|
||||
rest_service.h
|
||||
rest_service_manager.h
|
||||
url.h
|
||||
utility.h
|
||||
)
|
||||
|
||||
set(SOURCES
|
||||
globals.cc
|
||||
http_async_client.cc
|
||||
http_client.cc
|
||||
http_connection.cc
|
||||
http_message.cc
|
||||
http_parser.cc
|
||||
http_request.cc
|
||||
http_request_handler.cc
|
||||
http_request_parser.cc
|
||||
http_response.cc
|
||||
http_response_parser.cc
|
||||
http_server.cc
|
||||
logger.cc
|
||||
rest_async_client.cc
|
||||
rest_client.cc
|
||||
rest_request_handler.cc
|
||||
rest_service_manager.cc
|
||||
rest_service.cc
|
||||
url.cc
|
||||
utility.cc
|
||||
)
|
||||
globals.cc
|
||||
http_async_client.cc
|
||||
http_client.cc
|
||||
http_connection.cc
|
||||
http_message.cc
|
||||
http_parser.cc
|
||||
http_request.cc
|
||||
http_request_handler.cc
|
||||
http_request_parser.cc
|
||||
http_response.cc
|
||||
http_response_parser.cc
|
||||
http_server.cc
|
||||
logger.cc
|
||||
rest_async_client.cc
|
||||
rest_client.cc
|
||||
rest_request_handler.cc
|
||||
rest_service_manager.cc
|
||||
rest_service.cc
|
||||
url.cc
|
||||
utility.cc
|
||||
)
|
||||
|
||||
if(WEBCC_ENABLE_SSL)
|
||||
set(HEADERS ${HEADERS}
|
||||
http_ssl_client.h
|
||||
)
|
||||
set(HEADERS ${HEADERS}
|
||||
http_ssl_client.h
|
||||
)
|
||||
|
||||
set(SOURCES ${SOURCES}
|
||||
http_ssl_client.cc
|
||||
)
|
||||
set(SOURCES ${SOURCES}
|
||||
http_ssl_client.cc
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WEBCC_ENABLE_SOAP)
|
||||
set(SOAP_HEADERS
|
||||
soap_async_client.h
|
||||
soap_client.h
|
||||
soap_message.h
|
||||
soap_parameter.h
|
||||
soap_response.h
|
||||
soap_request.h
|
||||
soap_request_handler.h
|
||||
soap_server.h
|
||||
soap_service.h
|
||||
soap_xml.h
|
||||
)
|
||||
set(SOAP_HEADERS
|
||||
soap_async_client.h
|
||||
soap_client.h
|
||||
soap_message.h
|
||||
soap_parameter.h
|
||||
soap_response.h
|
||||
soap_request.h
|
||||
soap_request_handler.h
|
||||
soap_server.h
|
||||
soap_service.h
|
||||
soap_xml.h
|
||||
)
|
||||
|
||||
set(SOAP_SOURCES
|
||||
soap_async_client.cc
|
||||
soap_client.cc
|
||||
soap_message.cc
|
||||
soap_response.cc
|
||||
soap_request.cc
|
||||
soap_request_handler.cc
|
||||
soap_xml.cc
|
||||
)
|
||||
set(SOAP_SOURCES
|
||||
soap_async_client.cc
|
||||
soap_client.cc
|
||||
soap_message.cc
|
||||
soap_response.cc
|
||||
soap_request.cc
|
||||
soap_request_handler.cc
|
||||
soap_xml.cc
|
||||
)
|
||||
|
||||
set(HEADERS ${HEADERS} ${SOAP_HEADERS})
|
||||
set(SOURCES ${SOURCES} ${SOAP_SOURCES})
|
||||
set(HEADERS ${HEADERS} ${SOAP_HEADERS})
|
||||
set(SOURCES ${SOURCES} ${SOAP_SOURCES})
|
||||
endif()
|
||||
|
||||
set(TARGET webcc)
|
||||
|
||||
add_library(${TARGET} ${HEADERS} ${SOURCES})
|
||||
add_library(${TARGET} STATIC ${HEADERS} ${SOURCES})
|
||||
|
||||
install(TARGETS ${TARGET} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/lib)
|
||||
# Install lib and header files.
|
||||
# On Linux, if CMAKE_INSTALL_PREFIX is ~, the lib (libwebcc.a) will be installed
|
||||
# to ~/lib and header files will be installed to ~/include.
|
||||
|
||||
install(TARGETS ${TARGET} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/webcc)
|
||||
|
||||
+8
-10
@@ -3,12 +3,10 @@
|
||||
|
||||
// A general message queue.
|
||||
|
||||
#include <condition_variable>
|
||||
#include <list>
|
||||
#include <queue>
|
||||
|
||||
#include "boost/thread/condition_variable.hpp"
|
||||
#include "boost/thread/locks.hpp"
|
||||
#include "boost/thread/mutex.hpp"
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
namespace webcc {
|
||||
|
||||
@@ -21,7 +19,7 @@ class Queue {
|
||||
Queue& operator=(const Queue&) = delete;
|
||||
|
||||
T PopOrWait() {
|
||||
boost::unique_lock<boost::mutex> lock(mutex_);
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
|
||||
// Wait for a message.
|
||||
not_empty_cv_.wait(lock, [this] { return !message_list_.empty(); });
|
||||
@@ -32,7 +30,7 @@ class Queue {
|
||||
}
|
||||
|
||||
T Pop() {
|
||||
boost::lock_guard<boost::mutex> lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
if (message_list_.empty()) {
|
||||
return T();
|
||||
@@ -45,7 +43,7 @@ class Queue {
|
||||
|
||||
void Push(const T& message) {
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
message_list_.push_back(message);
|
||||
}
|
||||
not_empty_cv_.notify_one();
|
||||
@@ -53,8 +51,8 @@ class Queue {
|
||||
|
||||
private:
|
||||
std::list<T> message_list_;
|
||||
boost::mutex mutex_;
|
||||
boost::condition_variable not_empty_cv_;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable not_empty_cv_;
|
||||
};
|
||||
|
||||
} // namespace webcc
|
||||
|
||||
Reference in New Issue
Block a user