mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-28 01:21:31 +01:00
Fixes from develop experimental (on top of 1.11.2) (#3017)
* MongoDB::PooledConnection: Prevent unwanted release by disabling copy semantics. Enabled move semantics for C++11. * Construct MongoDB::Cursor from aggragation cursor. * Added function to get OS-specific numerical thread ID and %J pattern to use numerical OS thread id in pattern formatter. Co-authored-by: Tomaz Beltram <tomaz.beltram@topit.si>
This commit is contained in:
parent
5bac3e303f
commit
8a8c23c352
@ -132,6 +132,9 @@ public:
|
||||
long getTid() const;
|
||||
/// Returns the numeric thread identifier for the message.
|
||||
|
||||
long getOsTid() const;
|
||||
/// Returns the numeric thread identifier for the message.
|
||||
|
||||
void setPid(long pid);
|
||||
/// Sets the process identifier for the message.
|
||||
|
||||
@ -200,6 +203,7 @@ private:
|
||||
Priority _prio;
|
||||
Timestamp _time;
|
||||
long _tid;
|
||||
long _ostid;
|
||||
std::string _thread;
|
||||
long _pid;
|
||||
const char* _file;
|
||||
@ -246,6 +250,10 @@ inline long Message::getTid() const
|
||||
return _tid;
|
||||
}
|
||||
|
||||
inline long Message::getOsTid() const
|
||||
{
|
||||
return _ostid;
|
||||
}
|
||||
|
||||
inline long Message::getPid() const
|
||||
{
|
||||
|
@ -43,6 +43,7 @@ class Foundation_API PatternFormatter: public Formatter
|
||||
/// * %P - message process identifier
|
||||
/// * %T - message thread name
|
||||
/// * %I - message thread identifier (numeric)
|
||||
/// * %J - message thread OS identifier (numeric)
|
||||
/// * %N - node or host name
|
||||
/// * %U - message source file path (empty string if not set)
|
||||
/// * %O - message source file filename (empty string if not set)
|
||||
|
@ -224,8 +224,11 @@ public:
|
||||
/// Returns the Thread object for the currently active thread.
|
||||
/// If the current thread is the main thread, 0 is returned.
|
||||
|
||||
static TID currentTid();
|
||||
/// Returns the native thread ID for the current thread.
|
||||
static TID currentTid();
|
||||
/// Returns the native thread ID for the current thread.
|
||||
|
||||
static long currentOsTid();
|
||||
/// Returns the operating system specific thread ID for the current thread.
|
||||
|
||||
protected:
|
||||
ThreadLocalStorage& tls();
|
||||
@ -378,6 +381,10 @@ inline Thread::TID Thread::currentTid()
|
||||
return currentTidImpl();
|
||||
}
|
||||
|
||||
inline long Thread::currentOsTid()
|
||||
{
|
||||
return currentOsTidImpl();
|
||||
}
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
@ -80,6 +80,7 @@ public:
|
||||
static void yieldImpl();
|
||||
static ThreadImpl* currentImpl();
|
||||
static TIDImpl currentTidImpl();
|
||||
static long currentOsTidImpl();
|
||||
|
||||
protected:
|
||||
static void* runnableEntry(void* pThread);
|
||||
|
@ -88,6 +88,7 @@ public:
|
||||
static void yieldImpl();
|
||||
static ThreadImpl* currentImpl();
|
||||
static TIDImpl currentTidImpl();
|
||||
static long currentOsTidImpl();
|
||||
|
||||
protected:
|
||||
static void runnableEntry(void* pThread, int, int, int, int, int, int, int, int, int);
|
||||
|
@ -73,7 +73,8 @@ public:
|
||||
static void yieldImpl();
|
||||
static ThreadImpl* currentImpl();
|
||||
static TIDImpl currentTidImpl();
|
||||
|
||||
static long currentOsTidImpl();
|
||||
|
||||
protected:
|
||||
#if defined(_DLL)
|
||||
static DWORD WINAPI runnableEntry(LPVOID pThread);
|
||||
|
@ -73,6 +73,7 @@ public:
|
||||
static void yieldImpl();
|
||||
static ThreadImpl* currentImpl();
|
||||
static TIDImpl currentTidImpl();
|
||||
static long currentOsTidImpl();
|
||||
|
||||
protected:
|
||||
static DWORD WINAPI runnableEntry(LPVOID pThread);
|
||||
|
@ -31,7 +31,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
// set up two channel chains - one to the
|
||||
// console and the other one to a log file.
|
||||
FormattingChannel* pFCConsole = new FormattingChannel(new PatternFormatter("%s: %p: %t"));
|
||||
FormattingChannel* pFCConsole = new FormattingChannel(new PatternFormatter("[%O] %s: %p: %t"));
|
||||
pFCConsole->setChannel(new ConsoleChannel);
|
||||
pFCConsole->open();
|
||||
|
||||
|
@ -27,6 +27,7 @@ namespace Poco {
|
||||
Message::Message():
|
||||
_prio(PRIO_FATAL),
|
||||
_tid(0),
|
||||
_ostid(0),
|
||||
_pid(0),
|
||||
_file(0),
|
||||
_line(0),
|
||||
@ -41,6 +42,7 @@ Message::Message(const std::string& source, const std::string& text, Priority pr
|
||||
_text(text),
|
||||
_prio(prio),
|
||||
_tid(0),
|
||||
_ostid(0),
|
||||
_pid(0),
|
||||
_file(0),
|
||||
_line(0),
|
||||
@ -55,6 +57,7 @@ Message::Message(const std::string& source, const std::string& text, Priority pr
|
||||
_text(text),
|
||||
_prio(prio),
|
||||
_tid(0),
|
||||
_ostid(0),
|
||||
_pid(0),
|
||||
_file(file),
|
||||
_line(line),
|
||||
@ -70,6 +73,7 @@ Message::Message(const Message& msg):
|
||||
_prio(msg._prio),
|
||||
_time(msg._time),
|
||||
_tid(msg._tid),
|
||||
_ostid(msg._ostid),
|
||||
_thread(msg._thread),
|
||||
_pid(msg._pid),
|
||||
_file(msg._file),
|
||||
@ -88,6 +92,7 @@ Message::Message(Message&& msg) noexcept:
|
||||
_prio(std::move(msg._prio)),
|
||||
_time(std::move(msg._time)),
|
||||
_tid(std::move(msg._tid)),
|
||||
_ostid(std::move(msg._ostid)),
|
||||
_thread(std::move(msg._thread)),
|
||||
_pid(std::move(msg._pid)),
|
||||
_file(std::move(msg._file)),
|
||||
@ -104,6 +109,7 @@ Message::Message(const Message& msg, const std::string& text):
|
||||
_prio(msg._prio),
|
||||
_time(msg._time),
|
||||
_tid(msg._tid),
|
||||
_ostid(msg._ostid),
|
||||
_thread(msg._thread),
|
||||
_pid(msg._pid),
|
||||
_file(msg._file),
|
||||
@ -127,6 +133,7 @@ void Message::init()
|
||||
#if !defined(POCO_VXWORKS)
|
||||
_pid = Process::id();
|
||||
#endif
|
||||
_ostid = (IntPtr)Thread::currentOsTid();
|
||||
Thread* pThread = Thread::current();
|
||||
if (pThread)
|
||||
{
|
||||
@ -154,6 +161,7 @@ Message& Message::operator = (Message&& msg) noexcept
|
||||
_prio = std::move(msg._prio);
|
||||
_time = std::move(msg._time);
|
||||
_tid = std::move(msg._tid);
|
||||
_ostid = std::move(msg._ostid);
|
||||
_thread = std::move(msg._thread);
|
||||
_pid = std::move(msg._pid);
|
||||
_file = std::move(msg._file);
|
||||
@ -173,6 +181,7 @@ void Message::swap(Message& msg)
|
||||
swap(_prio, msg._prio);
|
||||
swap(_time, msg._time);
|
||||
swap(_tid, msg._tid);
|
||||
swap(_ostid, msg._ostid);
|
||||
swap(_thread, msg._thread);
|
||||
swap(_pid, msg._pid);
|
||||
swap(_file, msg._file);
|
||||
|
@ -80,6 +80,7 @@ void PatternFormatter::format(const Message& msg, std::string& text)
|
||||
case 'P': NumberFormatter::append(text, msg.getPid()); break;
|
||||
case 'T': text.append(msg.getThread()); break;
|
||||
case 'I': NumberFormatter::append(text, msg.getTid()); break;
|
||||
case 'J': NumberFormatter::append(text, msg.getOsTid()); break;
|
||||
case 'N': text.append(Environment::nodeName()); break;
|
||||
case 'U': text.append(msg.getSourceFile() ? msg.getSourceFile() : ""); break;
|
||||
case 'O': text.append(msg.getSourceFile() ? Path(msg.getSourceFile()).getFileName() : ""); break;
|
||||
|
@ -28,6 +28,12 @@
|
||||
# include <time.h>
|
||||
#endif
|
||||
|
||||
#if POCO_OS == POCO_OS_LINUX
|
||||
#define _GNU_SOURCE /* See feature_test_macros(7) */
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h> /* For SYS_xxx definitions */
|
||||
#endif
|
||||
|
||||
//
|
||||
// Block SIGPIPE in main thread.
|
||||
//
|
||||
@ -262,6 +268,16 @@ ThreadImpl::TIDImpl ThreadImpl::currentTidImpl()
|
||||
return pthread_self();
|
||||
}
|
||||
|
||||
long ThreadImpl::currentOsTidImpl()
|
||||
{
|
||||
#if POCO_OS == POCO_OS_LINUX
|
||||
return ::syscall(SYS_gettid);
|
||||
#elif POCO_OS == POCO_OS_MAC_OS_X
|
||||
return ::pthread_mach_thread_np(::pthread_self());
|
||||
#else
|
||||
return ::pthread_self();
|
||||
#endif
|
||||
}
|
||||
|
||||
void ThreadImpl::sleepImpl(long milliseconds)
|
||||
{
|
||||
|
@ -144,6 +144,10 @@ ThreadImpl::TIDImpl ThreadImpl::currentTidImpl()
|
||||
return taskIdSelf();
|
||||
}
|
||||
|
||||
long ThreadImpl::currentOsTidImpl()
|
||||
{
|
||||
return taskIdSelf();
|
||||
}
|
||||
|
||||
void ThreadImpl::sleepImpl(long milliseconds)
|
||||
{
|
||||
|
@ -189,6 +189,10 @@ ThreadImpl::TIDImpl ThreadImpl::currentTidImpl()
|
||||
return GetCurrentThreadId();
|
||||
}
|
||||
|
||||
long ThreadImpl::currentOsTidImpl()
|
||||
{
|
||||
return GetCurrentThreadId();
|
||||
}
|
||||
|
||||
#if defined(_DLL)
|
||||
DWORD WINAPI ThreadImpl::runnableEntry(LPVOID pThread)
|
||||
|
@ -139,9 +139,13 @@ ThreadImpl* ThreadImpl::currentImpl()
|
||||
|
||||
ThreadImpl::TIDImpl ThreadImpl::currentTidImpl()
|
||||
{
|
||||
return GetCurrentThreadId();
|
||||
return GetCurrentThreadId();
|
||||
}
|
||||
|
||||
long ThreadImpl::currentOsTidImpl()
|
||||
{
|
||||
return GetCurrentThreadId();
|
||||
}
|
||||
|
||||
DWORD WINAPI ThreadImpl::runnableEntry(LPVOID pThread)
|
||||
{
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "Poco/MongoDB/QueryRequest.h"
|
||||
#include "Poco/MongoDB/ResponseMessage.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace MongoDB {
|
||||
|
||||
@ -38,6 +37,9 @@ public:
|
||||
Cursor(const std::string& fullCollectionName, QueryRequest::Flags flags = QueryRequest::QUERY_DEFAULT);
|
||||
/// Creates a Cursor for the given database and collection ("database.collection"), using the specified flags.
|
||||
|
||||
Cursor(const Document& aggregationResponse);
|
||||
/// Creates a Cursor for the given agregation query response.
|
||||
|
||||
virtual ~Cursor();
|
||||
/// Destroys the Cursor.
|
||||
|
||||
|
@ -116,7 +116,24 @@ public:
|
||||
return _connection;
|
||||
}
|
||||
|
||||
#if defined(POCO_ENABLE_CPP11)
|
||||
// Disable copy to prevent unwanted release of resources: C++11 way
|
||||
PooledConnection(const PooledConnection&) = delete;
|
||||
PooledConnection& operator=(const PooledConnection&) = delete;
|
||||
|
||||
// Enable move semantics
|
||||
PooledConnection(PooledConnection&& other) = default;
|
||||
PooledConnection& operator=(PooledConnection&&) = default;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
#if ! defined(POCO_ENABLE_CPP11)
|
||||
// Disable copy to prevent unwanted release of resources: pre C++11 way
|
||||
PooledConnection(const PooledConnection&);
|
||||
PooledConnection& operator=(const PooledConnection&);
|
||||
#endif
|
||||
|
||||
Poco::ObjectPool<Connection, Connection::Ptr>& _pool;
|
||||
Connection::Ptr _connection;
|
||||
};
|
||||
|
@ -36,6 +36,9 @@ public:
|
||||
ResponseMessage();
|
||||
/// Creates an empty ResponseMessage.
|
||||
|
||||
ResponseMessage(const Int64& cursorID);
|
||||
/// Creates an ResponseMessage for existing cursor ID.
|
||||
|
||||
virtual ~ResponseMessage();
|
||||
/// Destroys the ResponseMessage.
|
||||
|
||||
|
@ -33,6 +33,12 @@ Cursor::Cursor(const std::string& fullCollectionName, QueryRequest::Flags flags)
|
||||
}
|
||||
|
||||
|
||||
Cursor::Cursor(const Document& aggregationResponse) :
|
||||
_query(aggregationResponse.get<Poco::MongoDB::Document::Ptr>("cursor")->get<std::string>("ns")),
|
||||
_response(aggregationResponse.get<Poco::MongoDB::Document::Ptr>("cursor")->get<Int64>("id"))
|
||||
{
|
||||
}
|
||||
|
||||
Cursor::~Cursor()
|
||||
{
|
||||
try
|
||||
|
@ -30,6 +30,16 @@ ResponseMessage::ResponseMessage():
|
||||
}
|
||||
|
||||
|
||||
ResponseMessage::ResponseMessage(const Int64& cursorID):
|
||||
Message(MessageHeader::OP_REPLY),
|
||||
_responseFlags(0),
|
||||
_cursorID(cursorID),
|
||||
_startingFrom(0),
|
||||
_numberReturned(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ResponseMessage::~ResponseMessage()
|
||||
{
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user