提交 0c41b876 编写于 作者: A Alexey Milovidov

Fixed insignificant error in Poco, shown by TSan [#CLICKHOUSE-2].

上级 2e741230
......@@ -45,6 +45,7 @@
#endif
#include <algorithm>
#include <map>
#include <atomic>
namespace Poco {
......@@ -66,7 +67,7 @@ public:
{
return _owner;
}
virtual void run() = 0;
virtual void stop() = 0;
virtual bool supportsMoveEvents() const = 0;
......@@ -78,21 +79,21 @@ protected:
size(0)
{
}
ItemInfo(const ItemInfo& other):
path(other.path),
size(other.size),
lastModified(other.lastModified)
{
}
explicit ItemInfo(const File& f):
path(f.path()),
size(f.isFile() ? f.getSize() : 0),
lastModified(f.getLastModified())
{
}
std::string path;
File::FileSize size;
Timestamp lastModified;
......@@ -109,7 +110,7 @@ protected:
++it;
}
}
void compare(ItemInfoMap& oldEntries, ItemInfoMap& newEntries)
{
for (ItemInfoMap::iterator itn = newEntries.begin(); itn != newEntries.end(); ++itn)
......@@ -150,7 +151,7 @@ private:
DirectoryWatcherStrategy();
DirectoryWatcherStrategy(const DirectoryWatcherStrategy&);
DirectoryWatcherStrategy& operator = (const DirectoryWatcherStrategy&);
DirectoryWatcher& _owner;
};
......@@ -168,21 +169,21 @@ public:
if (!_hStopped)
throw SystemException("cannot create event");
}
~WindowsDirectoryWatcherStrategy()
{
CloseHandle(_hStopped);
}
void run()
{
ItemInfoMap entries;
scan(entries);
DWORD filter = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME;
if (owner().eventMask() & DirectoryWatcher::DW_ITEM_MODIFIED)
filter |= FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE;
std::string path(owner().directory().path());
#if defined(POCO_WIN32_UTF8)
std::wstring upath;
......@@ -204,7 +205,7 @@ public:
}
return;
}
bool stopped = false;
while (!stopped)
{
......@@ -237,21 +238,21 @@ public:
catch (Poco::Exception& exc)
{
owner().scanError(&owner(), exc);
}
}
}
FindCloseChangeNotification(hChange);
}
void stop()
{
SetEvent(_hStopped);
}
bool supportsMoveEvents() const
{
return false;
}
private:
HANDLE _hStopped;
};
......@@ -271,12 +272,12 @@ public:
_fd = inotify_init();
if (_fd == -1) throw Poco::IOException("cannot initialize inotify", errno);
}
~LinuxDirectoryWatcherStrategy()
{
close(_fd);
}
void run()
{
int mask = 0;
......@@ -302,7 +303,7 @@ public:
owner().scanError(&owner(), exc);
}
}
Poco::Buffer<char> buffer(4096);
while (!_stopped)
{
......@@ -323,16 +324,16 @@ public:
while (n > 0)
{
struct inotify_event* pEvent = reinterpret_cast<struct inotify_event*>(buffer.begin() + i);
if (pEvent->len > 0)
{
{
if (!owner().eventsSuspended())
{
Poco::Path p(owner().directory().path());
p.makeDirectory();
p.setFileName(pEvent->name);
Poco::File f(p.toString());
if ((pEvent->mask & IN_CREATE) && (owner().eventMask() & DirectoryWatcher::DW_ITEM_ADDED))
{
DirectoryWatcher::DirectoryEvent ev(f, DirectoryWatcher::DW_ITEM_ADDED);
......@@ -360,7 +361,7 @@ public:
}
}
}
i += sizeof(inotify_event) + pEvent->len;
n -= sizeof(inotify_event) + pEvent->len;
}
......@@ -368,12 +369,12 @@ public:
}
}
}
void stop()
{
_stopped = true;
}
bool supportsMoveEvents() const
{
return true;
......@@ -381,7 +382,7 @@ public:
private:
int _fd;
bool _stopped;
std::atomic<bool> _stopped;
};
......@@ -464,7 +465,7 @@ public:
private:
int _queueFD;
int _dirFD;
bool _stopped;
std::atomic<bool> _stopped;
};
......@@ -478,11 +479,11 @@ public:
DirectoryWatcherStrategy(owner)
{
}
~PollingDirectoryWatcherStrategy()
{
}
void run()
{
ItemInfoMap entries;
......@@ -502,7 +503,7 @@ public:
}
}
}
void stop()
{
_stopped.set();
......@@ -529,7 +530,7 @@ DirectoryWatcher::DirectoryWatcher(const std::string& path, int eventMask, int s
init();
}
DirectoryWatcher::DirectoryWatcher(const Poco::File& directory, int eventMask, int scanInterval):
_directory(directory),
_eventMask(eventMask),
......@@ -552,11 +553,11 @@ DirectoryWatcher::~DirectoryWatcher()
}
}
void DirectoryWatcher::suspendEvents()
{
poco_assert (_eventsSuspended > 0);
_eventsSuspended--;
}
......@@ -571,7 +572,7 @@ void DirectoryWatcher::init()
{
if (!_directory.exists())
throw Poco::FileNotFoundException(_directory.path());
if (!_directory.isDirectory())
throw Poco::InvalidArgumentException("not a directory", _directory.path());
......@@ -587,7 +588,7 @@ void DirectoryWatcher::init()
_thread.start(*this);
}
void DirectoryWatcher::run()
{
_pStrategy->run();
......
......@@ -27,6 +27,8 @@
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Mutex.h"
#include <atomic>
namespace Poco {
namespace Net {
......@@ -45,7 +47,7 @@ public:
virtual ~HTTPServerConnection();
/// Destroys the HTTPServerConnection.
void run();
/// Handles all HTTP requests coming in.
......@@ -56,7 +58,7 @@ protected:
private:
HTTPServerParams::Ptr _pParams;
HTTPRequestHandlerFactory::Ptr _pFactory;
bool _stopped;
std::atomic<bool> _stopped;
Poco::FastMutex _mutex;
};
......
......@@ -29,6 +29,8 @@
#include "Poco/ThreadPool.h"
#include "Poco/Mutex.h"
#include <atomic>
namespace Poco {
namespace Net {
......@@ -52,35 +54,35 @@ public:
void release();
/// Decrements the object's reference count
/// and deletes the object if the count
/// reaches zero.
/// reaches zero.
void run();
/// Runs the dispatcher.
void enqueue(const StreamSocket& socket);
/// Queues the given socket connection.
void stop();
/// Stops the dispatcher.
int currentThreads() const;
/// Returns the number of currently used threads.
int maxThreads() const;
/// Returns the maximum number of threads available.
int totalConnections() const;
/// Returns the total number of handled connections.
int currentConnections() const;
/// Returns the number of currently handled connections.
/// Returns the number of currently handled connections.
int maxConcurrentConnections() const;
/// Returns the maximum number of concurrently handled connections.
/// Returns the maximum number of concurrently handled connections.
int queuedConnections() const;
/// Returns the number of queued connections.
/// Returns the number of queued connections.
int refusedConnections() const;
/// Returns the number of refused connections.
......@@ -93,7 +95,7 @@ protected:
void beginConnection();
/// Updates the performance counters.
void endConnection();
/// Updates the performance counters.
......@@ -109,7 +111,7 @@ private:
int _currentConnections;
int _maxConcurrentConnections;
int _refusedConnections;
bool _stopped;
std::atomic<bool> _stopped;
Poco::NotificationQueue _queue;
TCPServerConnectionFactory::Ptr _pConnectionFactory;
Poco::ThreadPool& _threadPool;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册