Commit d965d13e authored by andersca@apple.com's avatar andersca@apple.com

Clean up MessageQueue.h

https://bugs.webkit.org/show_bug.cgi?id=122392

Reviewed by Andreas Kling.

Source/WebCore:

Update for changes to MessageQueue, mostly changing create functions to return std::unique_ptr.
I intentionally avoided using std::make_unique in a couple of places because I didn't want to make nested classes
public, and I believe that we can change some of this code to use std::function.

* Modules/webaudio/AsyncAudioDecoder.cpp:
(WebCore::AsyncAudioDecoder::decodeAsync):
(WebCore::AsyncAudioDecoder::runLoop):
(WebCore::AsyncAudioDecoder::DecodingTask::create):
* Modules/webaudio/AsyncAudioDecoder.h:
* Modules/webdatabase/Database.cpp:
(WebCore::Database::markAsDeletedAndClose):
(WebCore::Database::tableNames):
* Modules/webdatabase/DatabaseBackend.cpp:
(WebCore::DatabaseBackend::openAndVerifyVersion):
(WebCore::DatabaseBackend::scheduleTransaction):
(WebCore::DatabaseBackend::scheduleTransactionStep):
* Modules/webdatabase/DatabaseTask.h:
(WebCore::DatabaseBackend::DatabaseOpenTask::create):
(WebCore::DatabaseBackend::DatabaseCloseTask::create):
(WebCore::DatabaseBackend::DatabaseTransactionTask::create):
(WebCore::DatabaseBackend::DatabaseTableNamesTask::create):
* Modules/webdatabase/DatabaseThread.cpp:
(WebCore::DatabaseThread::databaseThread):
(WebCore::DatabaseThread::scheduleTask):
(WebCore::DatabaseThread::scheduleImmediateTask):
(WebCore::SameDatabasePredicate::operator()):
* Modules/webdatabase/DatabaseThread.h:
* dom/default/PlatformMessagePortChannel.cpp:
(WebCore::PlatformMessagePortChannel::EventData::create):
(WebCore::MessagePortChannel::tryGetMessageFromRemote):
* dom/default/PlatformMessagePortChannel.h:
(WebCore::PlatformMessagePortChannel::MessagePortQueue::tryGetMessage):
(WebCore::PlatformMessagePortChannel::MessagePortQueue::appendAndCheckEmpty):
* fileapi/FileThread.cpp:
(WebCore::FileThread::postTask):
(WebCore::SameInstancePredicate::operator()):
(WebCore::FileThread::runLoop):
* fileapi/FileThread.h:
* fileapi/FileThreadTask.h:
(WebCore::createFileThreadTask):
* storage/StorageThread.cpp:
(WebCore::StorageThread::threadEntryPoint):
(WebCore::StorageThread::dispatch):
(WebCore::StorageThread::terminate):
* workers/WorkerRunLoop.cpp:
(WebCore::ModePredicate::operator()):
(WebCore::WorkerRunLoop::runInMode):
(WebCore::WorkerRunLoop::runCleanupTasks):
(WebCore::WorkerRunLoop::Task::create):
* workers/WorkerRunLoop.h:

Source/WTF:

Make MessageQueue use std::unique_ptr and change findIf and removeIf to take const references.

* wtf/Deque.h:
Change findIf to take an rvalue reference.

* wtf/MessageQueue.h:
(WTF::::append):
(WTF::::appendAndKill):
(WTF::::appendAndCheckEmpty):
(WTF::::prepend):
(WTF::::removeIf):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156972 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a353cb26
2013-10-05 Anders Carlsson <andersca@apple.com>
Clean up MessageQueue.h
https://bugs.webkit.org/show_bug.cgi?id=122392
Reviewed by Andreas Kling.
Make MessageQueue use std::unique_ptr and change findIf and removeIf to take const references.
* wtf/Deque.h:
Change findIf to take an rvalue reference.
* wtf/MessageQueue.h:
(WTF::::append):
(WTF::::appendAndKill):
(WTF::::appendAndCheckEmpty):
(WTF::::prepend):
(WTF::::removeIf):
2013-10-05 Anders Carlsson <andersca@apple.com>
Try to #define final to sealed when building with MSVC
......
......@@ -88,7 +88,7 @@ namespace WTF {
void clear();
template<typename Predicate>
iterator findIf(Predicate&);
iterator findIf(Predicate&&);
private:
friend class DequeIteratorBase<T, inlineCapacity>;
......@@ -353,7 +353,7 @@ namespace WTF {
template<typename T, size_t inlineCapacity>
template<typename Predicate>
inline auto Deque<T, inlineCapacity>::findIf(Predicate& predicate) -> iterator
inline auto Deque<T, inlineCapacity>::findIf(Predicate&& predicate) -> iterator
{
iterator end_iterator = end();
for (iterator it = begin(); it != end_iterator; ++it) {
......
......@@ -46,7 +46,7 @@ namespace WTF {
// The queue takes ownership of messages and transfer it to the new owner
// when messages are fetched from the queue.
// Essentially, MessageQueue acts as a queue of OwnPtr<DataType>.
// Essentially, MessageQueue acts as a queue of std::unique_ptr<DataType>.
template<typename DataType>
class MessageQueue {
WTF_MAKE_NONCOPYABLE(MessageQueue);
......@@ -54,19 +54,19 @@ namespace WTF {
MessageQueue() : m_killed(false) { }
~MessageQueue();
void append(OwnPtr<DataType>);
void appendAndKill(OwnPtr<DataType>);
bool appendAndCheckEmpty(OwnPtr<DataType>);
void prepend(OwnPtr<DataType>);
void append(std::unique_ptr<DataType>);
void appendAndKill(std::unique_ptr<DataType>);
bool appendAndCheckEmpty(std::unique_ptr<DataType>);
void prepend(std::unique_ptr<DataType>);
OwnPtr<DataType> waitForMessage();
OwnPtr<DataType> tryGetMessage();
OwnPtr<DataType> tryGetMessageIgnoringKilled();
std::unique_ptr<DataType> waitForMessage();
std::unique_ptr<DataType> tryGetMessage();
std::unique_ptr<DataType> tryGetMessageIgnoringKilled();
template<typename Predicate>
OwnPtr<DataType> waitForMessageFilteredWithTimeout(MessageQueueWaitResult&, Predicate&, double absoluteTime);
std::unique_ptr<DataType> waitForMessageFilteredWithTimeout(MessageQueueWaitResult&, Predicate&&, double absoluteTime);
template<typename Predicate>
void removeIf(Predicate&);
void removeIf(Predicate&&);
void kill();
bool killed() const;
......@@ -77,11 +77,9 @@ namespace WTF {
static double infiniteTime() { return std::numeric_limits<double>::max(); }
private:
static bool alwaysTruePredicate(const OwnPtr<DataType>&) { return true; }
mutable Mutex m_mutex;
ThreadCondition m_condition;
Deque<OwnPtr<DataType>> m_queue;
Deque<std::unique_ptr<DataType>> m_queue;
bool m_killed;
};
......@@ -91,7 +89,7 @@ namespace WTF {
}
template<typename DataType>
inline void MessageQueue<DataType>::append(OwnPtr<DataType> message)
inline void MessageQueue<DataType>::append(std::unique_ptr<DataType> message)
{
MutexLocker lock(m_mutex);
m_queue.append(std::move(message));
......@@ -99,7 +97,7 @@ namespace WTF {
}
template<typename DataType>
inline void MessageQueue<DataType>::appendAndKill(OwnPtr<DataType> message)
inline void MessageQueue<DataType>::appendAndKill(std::unique_ptr<DataType> message)
{
MutexLocker lock(m_mutex);
m_queue.append(std::move(message));
......@@ -109,7 +107,7 @@ namespace WTF {
// Returns true if the queue was empty before the item was added.
template<typename DataType>
inline bool MessageQueue<DataType>::appendAndCheckEmpty(OwnPtr<DataType> message)
inline bool MessageQueue<DataType>::appendAndCheckEmpty(std::unique_ptr<DataType> message)
{
MutexLocker lock(m_mutex);
bool wasEmpty = m_queue.isEmpty();
......@@ -119,7 +117,7 @@ namespace WTF {
}
template<typename DataType>
inline void MessageQueue<DataType>::prepend(OwnPtr<DataType> message)
inline void MessageQueue<DataType>::prepend(std::unique_ptr<DataType> message)
{
MutexLocker lock(m_mutex);
m_queue.prepend(std::move(message));
......@@ -127,24 +125,32 @@ namespace WTF {
}
template<typename DataType>
inline auto MessageQueue<DataType>::waitForMessage() -> OwnPtr<DataType>
inline auto MessageQueue<DataType>::waitForMessage() -> std::unique_ptr<DataType>
{
MessageQueueWaitResult exitReason;
OwnPtr<DataType> result = waitForMessageFilteredWithTimeout(exitReason, MessageQueue<DataType>::alwaysTruePredicate, infiniteTime());
std::unique_ptr<DataType> result = waitForMessageFilteredWithTimeout(exitReason, [](const DataType&) { return true; }, infiniteTime());
ASSERT(exitReason == MessageQueueTerminated || exitReason == MessageQueueMessageReceived);
return result;
}
template<typename DataType>
template<typename Predicate>
inline auto MessageQueue<DataType>::waitForMessageFilteredWithTimeout(MessageQueueWaitResult& result, Predicate& predicate, double absoluteTime) -> OwnPtr<DataType>
inline auto MessageQueue<DataType>::waitForMessageFilteredWithTimeout(MessageQueueWaitResult& result, Predicate&& predicate, double absoluteTime) -> std::unique_ptr<DataType>
{
MutexLocker lock(m_mutex);
bool timedOut = false;
auto found = m_queue.end();
while (!m_killed && !timedOut && (found = m_queue.findIf(predicate)) == m_queue.end())
while (!m_killed && !timedOut) {
found = m_queue.findIf([&predicate](const std::unique_ptr<DataType>& ptr) -> bool {
ASSERT(ptr);
return predicate(*ptr);
});
if (found != m_queue.end())
break;
timedOut = !m_condition.timedWait(m_mutex, absoluteTime);
}
ASSERT(!timedOut || absoluteTime != infiniteTime());
......@@ -159,14 +165,14 @@ namespace WTF {
}
ASSERT(found != m_queue.end());
OwnPtr<DataType> message = std::move(*found);
std::unique_ptr<DataType> message = std::move(*found);
m_queue.remove(found);
result = MessageQueueMessageReceived;
return message;
}
template<typename DataType>
inline auto MessageQueue<DataType>::tryGetMessage() -> OwnPtr<DataType>
inline auto MessageQueue<DataType>::tryGetMessage() -> std::unique_ptr<DataType>
{
MutexLocker lock(m_mutex);
if (m_killed)
......@@ -178,7 +184,7 @@ namespace WTF {
}
template<typename DataType>
inline auto MessageQueue<DataType>::tryGetMessageIgnoringKilled() -> OwnPtr<DataType>
inline auto MessageQueue<DataType>::tryGetMessageIgnoringKilled() -> std::unique_ptr<DataType>
{
MutexLocker lock(m_mutex);
if (m_queue.isEmpty())
......@@ -189,14 +195,18 @@ namespace WTF {
template<typename DataType>
template<typename Predicate>
inline void MessageQueue<DataType>::removeIf(Predicate& predicate)
inline void MessageQueue<DataType>::removeIf(Predicate&& predicate)
{
MutexLocker lock(m_mutex);
auto found = m_queue.end();
// FIXME: I think the predicate here should really take a const DataType&
// instead of a const OwnPtr<DataType>&.
while ((found = m_queue.findIf(predicate)) != m_queue.end()) {
OwnPtr<DataType> message = std::move(*found);
while (true) {
auto found = m_queue.findIf([&predicate](const std::unique_ptr<DataType>& ptr) -> bool {
ASSERT(ptr);
return predicate(*ptr);
});
if (found == m_queue.end())
break;
m_queue.remove(found);
}
}
......
2013-10-05 Anders Carlsson <andersca@apple.com>
Clean up MessageQueue.h
https://bugs.webkit.org/show_bug.cgi?id=122392
Reviewed by Andreas Kling.
Update for changes to MessageQueue, mostly changing create functions to return std::unique_ptr.
I intentionally avoided using std::make_unique in a couple of places because I didn't want to make nested classes
public, and I believe that we can change some of this code to use std::function.
* Modules/webaudio/AsyncAudioDecoder.cpp:
(WebCore::AsyncAudioDecoder::decodeAsync):
(WebCore::AsyncAudioDecoder::runLoop):
(WebCore::AsyncAudioDecoder::DecodingTask::create):
* Modules/webaudio/AsyncAudioDecoder.h:
* Modules/webdatabase/Database.cpp:
(WebCore::Database::markAsDeletedAndClose):
(WebCore::Database::tableNames):
* Modules/webdatabase/DatabaseBackend.cpp:
(WebCore::DatabaseBackend::openAndVerifyVersion):
(WebCore::DatabaseBackend::scheduleTransaction):
(WebCore::DatabaseBackend::scheduleTransactionStep):
* Modules/webdatabase/DatabaseTask.h:
(WebCore::DatabaseBackend::DatabaseOpenTask::create):
(WebCore::DatabaseBackend::DatabaseCloseTask::create):
(WebCore::DatabaseBackend::DatabaseTransactionTask::create):
(WebCore::DatabaseBackend::DatabaseTableNamesTask::create):
* Modules/webdatabase/DatabaseThread.cpp:
(WebCore::DatabaseThread::databaseThread):
(WebCore::DatabaseThread::scheduleTask):
(WebCore::DatabaseThread::scheduleImmediateTask):
(WebCore::SameDatabasePredicate::operator()):
* Modules/webdatabase/DatabaseThread.h:
* dom/default/PlatformMessagePortChannel.cpp:
(WebCore::PlatformMessagePortChannel::EventData::create):
(WebCore::MessagePortChannel::tryGetMessageFromRemote):
* dom/default/PlatformMessagePortChannel.h:
(WebCore::PlatformMessagePortChannel::MessagePortQueue::tryGetMessage):
(WebCore::PlatformMessagePortChannel::MessagePortQueue::appendAndCheckEmpty):
* fileapi/FileThread.cpp:
(WebCore::FileThread::postTask):
(WebCore::SameInstancePredicate::operator()):
(WebCore::FileThread::runLoop):
* fileapi/FileThread.h:
* fileapi/FileThreadTask.h:
(WebCore::createFileThreadTask):
* storage/StorageThread.cpp:
(WebCore::StorageThread::threadEntryPoint):
(WebCore::StorageThread::dispatch):
(WebCore::StorageThread::terminate):
* workers/WorkerRunLoop.cpp:
(WebCore::ModePredicate::operator()):
(WebCore::WorkerRunLoop::runInMode):
(WebCore::WorkerRunLoop::runCleanupTasks):
(WebCore::WorkerRunLoop::Task::create):
* workers/WorkerRunLoop.h:
2013-10-04 Dean Jackson <dino@apple.com>
[WebGL] program should not be able to link if a bad shader is attached
......@@ -60,8 +60,8 @@ void AsyncAudioDecoder::decodeAsync(ArrayBuffer* audioData, float sampleRate, Pa
if (!audioData)
return;
OwnPtr<DecodingTask> decodingTask = DecodingTask::create(audioData, sampleRate, successCallback, errorCallback);
m_queue.append(decodingTask.release()); // note that ownership of the task is effectively taken by the queue.
auto decodingTask = DecodingTask::create(audioData, sampleRate, successCallback, errorCallback);
m_queue.append(std::move(decodingTask)); // note that ownership of the task is effectively taken by the queue.
}
// Asynchronously decode in this thread.
......@@ -82,16 +82,16 @@ void AsyncAudioDecoder::runLoop()
}
// Keep running decoding tasks until we're killed.
while (OwnPtr<DecodingTask> decodingTask = m_queue.waitForMessage()) {
while (auto decodingTask = m_queue.waitForMessage()) {
// Let the task take care of its own ownership.
// See DecodingTask::notifyComplete() for cleanup.
decodingTask.leakPtr()->decode();
decodingTask.release()->decode();
}
}
PassOwnPtr<AsyncAudioDecoder::DecodingTask> AsyncAudioDecoder::DecodingTask::create(ArrayBuffer* audioData, float sampleRate, PassRefPtr<AudioBufferCallback> successCallback, PassRefPtr<AudioBufferCallback> errorCallback)
std::unique_ptr<AsyncAudioDecoder::DecodingTask> AsyncAudioDecoder::DecodingTask::create(ArrayBuffer* audioData, float sampleRate, PassRefPtr<AudioBufferCallback> successCallback, PassRefPtr<AudioBufferCallback> errorCallback)
{
return adoptPtr(new DecodingTask(audioData, sampleRate, successCallback, errorCallback));
return std::unique_ptr<DecodingTask>(new DecodingTask(audioData, sampleRate, successCallback, errorCallback));
}
AsyncAudioDecoder::DecodingTask::DecodingTask(ArrayBuffer* audioData, float sampleRate, PassRefPtr<AudioBufferCallback> successCallback, PassRefPtr<AudioBufferCallback> errorCallback)
......
......@@ -57,7 +57,7 @@ private:
class DecodingTask {
WTF_MAKE_NONCOPYABLE(DecodingTask);
public:
static PassOwnPtr<DecodingTask> create(JSC::ArrayBuffer* audioData, float sampleRate, PassRefPtr<AudioBufferCallback> successCallback, PassRefPtr<AudioBufferCallback> errorCallback);
static std::unique_ptr<DecodingTask> create(JSC::ArrayBuffer* audioData, float sampleRate, PassRefPtr<AudioBufferCallback> successCallback, PassRefPtr<AudioBufferCallback> errorCallback);
void decode();
......
......@@ -151,8 +151,8 @@ void Database::markAsDeletedAndClose()
return;
}
OwnPtr<DatabaseCloseTask> task = DatabaseCloseTask::create(this, &synchronizer);
databaseContext()->databaseThread()->scheduleImmediateTask(task.release());
auto task = DatabaseCloseTask::create(this, &synchronizer);
databaseContext()->databaseThread()->scheduleImmediateTask(std::move(task));
synchronizer.waitForTaskCompletion();
}
......@@ -267,8 +267,8 @@ Vector<String> Database::tableNames()
if (!databaseContext()->databaseThread() || databaseContext()->databaseThread()->terminationRequested(&synchronizer))
return result;
OwnPtr<DatabaseTableNamesTask> task = DatabaseTableNamesTask::create(this, &synchronizer, result);
databaseContext()->databaseThread()->scheduleImmediateTask(task.release());
auto task = DatabaseTableNamesTask::create(this, &synchronizer, result);
databaseContext()->databaseThread()->scheduleImmediateTask(std::move(task));
synchronizer.waitForTaskCompletion();
return result;
......
......@@ -56,8 +56,8 @@ bool DatabaseBackend::openAndVerifyVersion(bool setVersionInNewDatabase, Databas
return false;
bool success = false;
OwnPtr<DatabaseOpenTask> task = DatabaseOpenTask::create(this, setVersionInNewDatabase, &synchronizer, error, errorMessage, success);
databaseContext()->databaseThread()->scheduleImmediateTask(task.release());
auto task = DatabaseOpenTask::create(this, setVersionInNewDatabase, &synchronizer, error, errorMessage, success);
databaseContext()->databaseThread()->scheduleImmediateTask(std::move(task));
synchronizer.waitForTaskCompletion();
return success;
......@@ -144,10 +144,10 @@ void DatabaseBackend::scheduleTransaction()
transaction = m_transactionQueue.takeFirst();
if (transaction && databaseContext()->databaseThread()) {
OwnPtr<DatabaseTransactionTask> task = DatabaseTransactionTask::create(transaction);
auto task = DatabaseTransactionTask::create(transaction);
LOG(StorageAPI, "Scheduling DatabaseTransactionTask %p for transaction %p\n", task.get(), task->transaction());
m_transactionInProgress = true;
databaseContext()->databaseThread()->scheduleTask(task.release());
databaseContext()->databaseThread()->scheduleTask(std::move(task));
} else
m_transactionInProgress = false;
}
......@@ -157,9 +157,9 @@ void DatabaseBackend::scheduleTransactionStep(SQLTransactionBackend* transaction
if (!databaseContext()->databaseThread())
return;
OwnPtr<DatabaseTransactionTask> task = DatabaseTransactionTask::create(transaction);
auto task = DatabaseTransactionTask::create(transaction);
LOG(StorageAPI, "Scheduling DatabaseTransactionTask %p for the transaction step\n", task.get());
databaseContext()->databaseThread()->scheduleTask(task.release());
databaseContext()->databaseThread()->scheduleTask(std::move(task));
}
SQLTransactionClient* DatabaseBackend::transactionClient() const
......
......@@ -100,9 +100,9 @@ private:
class DatabaseBackend::DatabaseOpenTask : public DatabaseTask {
public:
static PassOwnPtr<DatabaseOpenTask> create(DatabaseBackend* db, bool setVersionInNewDatabase, DatabaseTaskSynchronizer* synchronizer, DatabaseError& error, String& errorMessage, bool& success)
static std::unique_ptr<DatabaseOpenTask> create(DatabaseBackend* db, bool setVersionInNewDatabase, DatabaseTaskSynchronizer* synchronizer, DatabaseError& error, String& errorMessage, bool& success)
{
return adoptPtr(new DatabaseOpenTask(db, setVersionInNewDatabase, synchronizer, error, errorMessage, success));
return std::unique_ptr<DatabaseOpenTask>(new DatabaseOpenTask(db, setVersionInNewDatabase, synchronizer, error, errorMessage, success));
}
private:
......@@ -121,9 +121,9 @@ private:
class DatabaseBackend::DatabaseCloseTask : public DatabaseTask {
public:
static PassOwnPtr<DatabaseCloseTask> create(DatabaseBackend* db, DatabaseTaskSynchronizer* synchronizer)
static std::unique_ptr<DatabaseCloseTask> create(DatabaseBackend* db, DatabaseTaskSynchronizer* synchronizer)
{
return adoptPtr(new DatabaseCloseTask(db, synchronizer));
return std::unique_ptr<DatabaseCloseTask>(new DatabaseCloseTask(db, synchronizer));
}
private:
......@@ -140,9 +140,9 @@ public:
virtual ~DatabaseTransactionTask();
// Transaction task is never synchronous, so no 'synchronizer' parameter.
static PassOwnPtr<DatabaseTransactionTask> create(PassRefPtr<SQLTransactionBackend> transaction)
static std::unique_ptr<DatabaseTransactionTask> create(PassRefPtr<SQLTransactionBackend> transaction)
{
return adoptPtr(new DatabaseTransactionTask(transaction));
return std::unique_ptr<DatabaseTransactionTask>(new DatabaseTransactionTask(transaction));
}
SQLTransactionBackend* transaction() const { return m_transaction.get(); }
......@@ -161,9 +161,9 @@ private:
class DatabaseBackend::DatabaseTableNamesTask : public DatabaseTask {
public:
static PassOwnPtr<DatabaseTableNamesTask> create(DatabaseBackend* db, DatabaseTaskSynchronizer* synchronizer, Vector<String>& names)
static std::unique_ptr<DatabaseTableNamesTask> create(DatabaseBackend* db, DatabaseTaskSynchronizer* synchronizer, Vector<String>& names)
{
return adoptPtr(new DatabaseTableNamesTask(db, synchronizer, names));
return std::unique_ptr<DatabaseTableNamesTask>(new DatabaseTableNamesTask(db, synchronizer, names));
}
private:
......
......@@ -106,7 +106,7 @@ void DatabaseThread::databaseThread()
LOG(StorageAPI, "Started DatabaseThread %p", this);
}
while (OwnPtr<DatabaseTask> task = m_queue.waitForMessage()) {
while (auto task = m_queue.waitForMessage()) {
AutodrainedPool pool;
task->performTask();
......@@ -156,22 +156,22 @@ void DatabaseThread::recordDatabaseClosed(DatabaseBackend* database)
m_openDatabaseSet.remove(database);
}
void DatabaseThread::scheduleTask(PassOwnPtr<DatabaseTask> task)
void DatabaseThread::scheduleTask(std::unique_ptr<DatabaseTask> task)
{
ASSERT(!task->hasSynchronizer() || task->hasCheckedForTermination());
m_queue.append(task);
m_queue.append(std::move(task));
}
void DatabaseThread::scheduleImmediateTask(PassOwnPtr<DatabaseTask> task)
void DatabaseThread::scheduleImmediateTask(std::unique_ptr<DatabaseTask> task)
{
ASSERT(!task->hasSynchronizer() || task->hasCheckedForTermination());
m_queue.prepend(task);
m_queue.prepend(std::move(task));
}
class SameDatabasePredicate {
public:
SameDatabasePredicate(const DatabaseBackend* database) : m_database(database) { }
bool operator()(const OwnPtr<DatabaseTask>& task) const { return task->database() == m_database; }
bool operator()(const DatabaseTask& task) const { return task.database() == m_database; }
private:
const DatabaseBackend* m_database;
};
......
......@@ -58,8 +58,8 @@ public:
void requestTermination(DatabaseTaskSynchronizer* cleanupSync);
bool terminationRequested(DatabaseTaskSynchronizer* taskSynchronizer = 0) const;
void scheduleTask(PassOwnPtr<DatabaseTask>);
void scheduleImmediateTask(PassOwnPtr<DatabaseTask>); // This just adds the task to the front of the queue - the caller needs to be extremely careful not to create deadlocks when waiting for completion.
void scheduleTask(std::unique_ptr<DatabaseTask>);
void scheduleImmediateTask(std::unique_ptr<DatabaseTask>); // This just adds the task to the front of the queue - the caller needs to be extremely careful not to create deadlocks when waiting for completion.
void unscheduleDatabaseTasks(DatabaseBackend*);
void recordDatabaseOpen(DatabaseBackend*);
......
......@@ -37,9 +37,9 @@
namespace WebCore {
PassOwnPtr<PlatformMessagePortChannel::EventData> PlatformMessagePortChannel::EventData::create(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray> channels)
std::unique_ptr<PlatformMessagePortChannel::EventData> PlatformMessagePortChannel::EventData::create(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray> channels)
{
return adoptPtr(new EventData(message, channels));
return std::unique_ptr<EventData>(new EventData(message, channels));
}
PlatformMessagePortChannel::EventData::EventData(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray> channels)
......@@ -104,7 +104,7 @@ void MessagePortChannel::postMessageToRemote(PassRefPtr<SerializedScriptValue> m
bool MessagePortChannel::tryGetMessageFromRemote(RefPtr<SerializedScriptValue>& message, OwnPtr<MessagePortChannelArray>& channels)
{
MutexLocker lock(m_channel->m_mutex);
OwnPtr<PlatformMessagePortChannel::EventData> result = m_channel->m_incomingQueue->tryGetMessage();
auto result = m_channel->m_incomingQueue->tryGetMessage();
if (!result)
return false;
......
......@@ -49,7 +49,7 @@ namespace WebCore {
class EventData {
WTF_MAKE_NONCOPYABLE(EventData); WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<EventData> create(PassRefPtr<SerializedScriptValue>, PassOwnPtr<MessagePortChannelArray>);
static std::unique_ptr<EventData> create(PassRefPtr<SerializedScriptValue>, PassOwnPtr<MessagePortChannelArray>);
PassRefPtr<SerializedScriptValue> message() { return m_message; }
PassOwnPtr<MessagePortChannelArray> channels() { return m_channels.release(); }
......@@ -65,14 +65,14 @@ namespace WebCore {
public:
static PassRefPtr<MessagePortQueue> create() { return adoptRef(new MessagePortQueue()); }
OwnPtr<PlatformMessagePortChannel::EventData> tryGetMessage()
std::unique_ptr<PlatformMessagePortChannel::EventData> tryGetMessage()
{
return m_queue.tryGetMessage();
}
bool appendAndCheckEmpty(PassOwnPtr<PlatformMessagePortChannel::EventData> message)
bool appendAndCheckEmpty(std::unique_ptr<PlatformMessagePortChannel::EventData> message)
{
return m_queue.appendAndCheckEmpty(message);
return m_queue.appendAndCheckEmpty(std::move(message));
}
bool isEmpty()
......
......@@ -64,15 +64,15 @@ void FileThread::stop()
m_queue.kill();
}
void FileThread::postTask(PassOwnPtr<Task> task)
void FileThread::postTask(std::unique_ptr<Task> task)
{
m_queue.append(task);
m_queue.append(std::move(task));
}
class SameInstancePredicate {
public:
SameInstancePredicate(const void* instance) : m_instance(instance) { }
bool operator()(const OwnPtr<FileThread::Task>& task) const { return task->instance() == m_instance; }
bool operator()(FileThread::Task& task) const { return task.instance() == m_instance; }
private:
const void* m_instance;
};
......@@ -98,7 +98,7 @@ void FileThread::runLoop()
LOG(FileAPI, "Started FileThread %p", this);
}
while (OwnPtr<Task> task = m_queue.waitForMessage()) {
while (auto task = m_queue.waitForMessage()) {
AutodrainedPool pool;
task->performTask();
......
......@@ -65,7 +65,7 @@ public:
void* m_instance;
};
void postTask(PassOwnPtr<Task> task);
void postTask(std::unique_ptr<Task>);
void unscheduleTasks(const void* instance);
......
......@@ -45,18 +45,13 @@ public:
typedef void (T::*Method)();
typedef FileThreadTask0<T> FileThreadTaskImpl;
static PassOwnPtr<FileThreadTaskImpl> create(T* instance, Method method)
{
return adoptPtr(new FileThreadTaskImpl(instance, method));
}
private:
FileThreadTask0(T* instance, Method method)
: FileThread::Task(instance)
, m_method(method)
{
}
private:
virtual void performTask()
{
(*static_cast<T*>(instance()).*m_method)();
......@@ -73,12 +68,6 @@ public:
typedef FileThreadTask1<T, P1, MP1> FileThreadTaskImpl;
typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
static PassOwnPtr<FileThreadTaskImpl> create(T* instance, Method method, Param1 parameter1)
{
return adoptPtr(new FileThreadTaskImpl(instance, method, parameter1));
}
private:
FileThreadTask1(T* instance, Method method, Param1 parameter1)
: FileThread::Task(instance)
, m_method(method)
......@@ -86,6 +75,7 @@ private:
{
}
private:
virtual void performTask()
{
(*static_cast<T*>(instance()).*m_method)(m_parameter1);
......@@ -104,12 +94,6 @@ public:
typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
typedef typename CrossThreadTaskTraits<P2>::ParamType Param2;
static PassOwnPtr<FileThreadTaskImpl> create(T* instance, Method method, Param1 parameter1, Param2 parameter2)
{
return adoptPtr(new FileThreadTaskImpl(instance, method, parameter1, parameter2));
}
private:
FileThreadTask2(T* instance, Method method, Param1 parameter1, Param2 parameter2)
: FileThread::Task(instance)