MXS-2002 Replace auto_ptr with unique_ptr
Given 'Derived : public Base', a unique_ptr<Derived> converts implictly to a unique_ptr<Base>.
This commit is contained in:
@ -747,13 +747,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @attention Once the task has been executed, it will be deleted.
|
* @attention Once the task has been executed, it will be deleted.
|
||||||
*/
|
*/
|
||||||
bool post(std::auto_ptr<DisposableTask> sTask, enum execute_mode_t mode);
|
bool post(std::unique_ptr<DisposableTask> sTask, enum execute_mode_t mode);
|
||||||
|
|
||||||
template<class T>
|
|
||||||
bool post(std::auto_ptr<T> sTask, enum execute_mode_t mode)
|
|
||||||
{
|
|
||||||
return post(std::auto_ptr<DisposableTask>(sTask.release()), mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a funcion in a worker
|
* Execute a funcion in a worker
|
||||||
|
@ -3309,7 +3309,7 @@ static void poll_add_event_to_dcb(DCB* dcb, GWBUF* buf, uint32_t ev)
|
|||||||
if (task)
|
if (task)
|
||||||
{
|
{
|
||||||
RoutingWorker* worker = static_cast<RoutingWorker*>(dcb->poll.owner);
|
RoutingWorker* worker = static_cast<RoutingWorker*>(dcb->poll.owner);
|
||||||
worker->post(std::auto_ptr<FakeEventTask>(task), mxs::Worker::EXECUTE_QUEUED);
|
worker->post(std::unique_ptr<FakeEventTask>(task), mxs::Worker::EXECUTE_QUEUED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3523,7 +3523,7 @@ static bool dcb_add_to_worker(Worker* worker, DCB* dcb, uint32_t events)
|
|||||||
Worker* worker = static_cast<RoutingWorker*>(dcb->poll.owner);
|
Worker* worker = static_cast<RoutingWorker*>(dcb->poll.owner);
|
||||||
ss_dassert(worker);
|
ss_dassert(worker);
|
||||||
|
|
||||||
if (worker->post(std::auto_ptr<AddDcbToWorker>(task), mxs::Worker::EXECUTE_QUEUED))
|
if (worker->post(std::unique_ptr<AddDcbToWorker>(task), mxs::Worker::EXECUTE_QUEUED))
|
||||||
{
|
{
|
||||||
rv = true;
|
rv = true;
|
||||||
}
|
}
|
||||||
|
@ -207,13 +207,7 @@ public:
|
|||||||
* directly without going through the message loop of the worker,
|
* directly without going through the message loop of the worker,
|
||||||
* otherwise the task is delivered via the message loop.
|
* otherwise the task is delivered via the message loop.
|
||||||
*/
|
*/
|
||||||
static size_t broadcast(std::auto_ptr<DisposableTask> sTask);
|
static size_t broadcast(std::unique_ptr<DisposableTask> sTask);
|
||||||
|
|
||||||
template<class T>
|
|
||||||
static size_t broadcast(std::auto_ptr<T> sTask)
|
|
||||||
{
|
|
||||||
return broadcast(std::auto_ptr<DisposableTask>(sTask.release()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a task on all workers in serial mode (the task is executed
|
* Executes a task on all workers in serial mode (the task is executed
|
||||||
|
@ -614,7 +614,7 @@ size_t RoutingWorker::broadcast(Task* pTask, Semaphore* pSem)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//static
|
//static
|
||||||
size_t RoutingWorker::broadcast(std::auto_ptr<DisposableTask> sTask)
|
size_t RoutingWorker::broadcast(std::unique_ptr<DisposableTask> sTask)
|
||||||
{
|
{
|
||||||
DisposableTask* pTask = sTask.release();
|
DisposableTask* pTask = sTask.release();
|
||||||
Worker::inc_ref(pTask);
|
Worker::inc_ref(pTask);
|
||||||
@ -1165,12 +1165,12 @@ protected:
|
|||||||
|
|
||||||
size_t mxs_rworker_broadcast(void (*cb)(void* data), void* data)
|
size_t mxs_rworker_broadcast(void (*cb)(void* data), void* data)
|
||||||
{
|
{
|
||||||
std::auto_ptr<FunctionTask> task(new FunctionTask([cb, data]()
|
std::unique_ptr<FunctionTask> task(new FunctionTask([cb, data]()
|
||||||
{
|
{
|
||||||
cb(data);
|
cb(data);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return RoutingWorker::broadcast(task);
|
return RoutingWorker::broadcast(std::move(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t mxs_rworker_create_key()
|
uint64_t mxs_rworker_create_key()
|
||||||
@ -1195,8 +1195,8 @@ void mxs_rworker_delete_data(uint64_t key)
|
|||||||
RoutingWorker::get_current()->delete_data(key);
|
RoutingWorker::get_current()->delete_data(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::auto_ptr<FunctionTask> task(new FunctionTask(func));
|
std::unique_ptr<FunctionTask> task(new FunctionTask(func));
|
||||||
RoutingWorker::broadcast(task);
|
RoutingWorker::broadcast(std::move(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
json_t* mxs_rworker_to_json(const char* zHost, int id)
|
json_t* mxs_rworker_to_json(const char* zHost, int id)
|
||||||
|
@ -359,7 +359,7 @@ static void session_free(MXS_SESSION *session)
|
|||||||
{
|
{
|
||||||
// Destroy the service in the main routing worker thread
|
// Destroy the service in the main routing worker thread
|
||||||
mxs::RoutingWorker* main_worker = mxs::RoutingWorker::get(mxs::RoutingWorker::MAIN);
|
mxs::RoutingWorker* main_worker = mxs::RoutingWorker::get(mxs::RoutingWorker::MAIN);
|
||||||
main_worker->post(std::auto_ptr<ServiceDestroyTask>(new ServiceDestroyTask(service)),
|
main_worker->post(std::unique_ptr<ServiceDestroyTask>(new ServiceDestroyTask(service)),
|
||||||
mxs::Worker::EXECUTE_AUTO);
|
mxs::Worker::EXECUTE_AUTO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1112,7 +1112,7 @@ bool session_delay_routing(MXS_SESSION* session, MXS_DOWNSTREAM down, GWBUF* buf
|
|||||||
{
|
{
|
||||||
Worker* worker = Worker::get_current();
|
Worker* worker = Worker::get_current();
|
||||||
ss_dassert(worker == session->client_dcb->poll.owner);
|
ss_dassert(worker == session->client_dcb->poll.owner);
|
||||||
std::auto_ptr<DelayedRoutingTask> task(new DelayedRoutingTask(session, down, buffer));
|
std::unique_ptr<DelayedRoutingTask> task(new DelayedRoutingTask(session, down, buffer));
|
||||||
|
|
||||||
// Delay the routing for at least a millisecond
|
// Delay the routing for at least a millisecond
|
||||||
int32_t delay = 1 + seconds * 1000;
|
int32_t delay = 1 + seconds * 1000;
|
||||||
|
@ -444,7 +444,7 @@ bool Worker::post(Task* pTask, Semaphore* pSem, enum execute_mode_t mode)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Worker::post(std::auto_ptr<DisposableTask> sTask, enum execute_mode_t mode)
|
bool Worker::post(std::unique_ptr<DisposableTask> sTask, enum execute_mode_t mode)
|
||||||
{
|
{
|
||||||
// No logging here, function must be signal safe.
|
// No logging here, function must be signal safe.
|
||||||
return post_disposable(sTask.release(), mode);
|
return post_disposable(sTask.release(), mode);
|
||||||
|
@ -331,11 +331,11 @@ static bool conversion_task_ctl(Avro *inst, bool start)
|
|||||||
if (!service_should_stop)
|
if (!service_should_stop)
|
||||||
{
|
{
|
||||||
Worker* worker = static_cast<Worker*>(mxs_rworker_get(MXS_RWORKER_MAIN));
|
Worker* worker = static_cast<Worker*>(mxs_rworker_get(MXS_RWORKER_MAIN));
|
||||||
std::auto_ptr<ConversionCtlTask> task(new (std::nothrow) ConversionCtlTask(inst, start));
|
std::unique_ptr<ConversionCtlTask> task(new (std::nothrow) ConversionCtlTask(inst, start));
|
||||||
|
|
||||||
if (task.get())
|
if (task.get())
|
||||||
{
|
{
|
||||||
worker->post(task, Worker::EXECUTE_AUTO);
|
worker->post(std::move(task), Worker::EXECUTE_AUTO);
|
||||||
rval = true;
|
rval = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user