File px_worker_manager.hpp¶
File List > cubrid > src > query > parallel > px_worker_manager.hpp
Go to the documentation of this file
/*
*
* Copyright 2016 CUBRID Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* px_worker_manager.hpp - module that manages parallel worker threads.
*/
#ifndef _PX_WORKER_MANAGER_HPP_
#define _PX_WORKER_MANAGER_HPP_
#if !defined (SERVER_MODE) && !defined (SA_MODE)
#error Belongs to server module
#endif /* !defined (SERVER_MODE) && !defined (SA_MODE) */
#include <atomic>
#include "thread_entry_task.hpp" /* cubthread::entry_task */
namespace parallel_query
{
class worker_manager
{
public:
static worker_manager *try_reserve_workers (int num_workers);
worker_manager();
~worker_manager();
void release_workers ();
void wait_workers ();
void push_task (cubthread::entry_task *task);
void pop_task ()
{
m_active_tasks.fetch_sub (1, std::memory_order_release);
}
int get_reserved_workers () const
{
return m_reserved_workers;
}
private:
std::atomic<int> m_active_tasks;
int m_reserved_workers;
worker_manager (const worker_manager &) = delete;
worker_manager &operator= (const worker_manager &) = delete;
};
}
#endif /*_PX_WORKER_MANAGER_HPP_ */