osrm-backend/include/extractor/scripting_environment.hpp

55 lines
1.2 KiB
C++
Raw Normal View History

#ifndef SCRIPTING_ENVIRONMENT_HPP
#define SCRIPTING_ENVIRONMENT_HPP
#include "extractor/profile_properties.hpp"
#include "extractor/raster_source.hpp"
#include "util/lua_util.hpp"
2014-05-16 07:26:42 -04:00
#include <memory>
#include <mutex>
2016-05-27 15:05:04 -04:00
#include <string>
2014-05-16 07:26:42 -04:00
#include <tbb/enumerable_thread_specific.h>
struct lua_State;
2016-01-05 10:51:13 -05:00
namespace osrm
{
namespace extractor
{
/**
* Creates a lua context and binds osmium way, node and relation objects and
* ExtractionWay and ExtractionNode to lua objects.
*
* Each thread has its own lua state which is implemented with thread specific
* storage from TBB.
*/
2014-05-09 10:17:31 -04:00
class ScriptingEnvironment
{
public:
struct Context
{
ProfileProperties properties;
SourceContainer sources;
util::LuaState state;
};
explicit ScriptingEnvironment(const std::string &file_name);
ScriptingEnvironment(const ScriptingEnvironment &) = delete;
ScriptingEnvironment &operator=(const ScriptingEnvironment &) = delete;
Context &GetContex();
2014-05-16 07:26:42 -04:00
private:
void InitContext(Context &context);
2015-01-22 06:19:11 -05:00
std::mutex init_mutex;
2014-05-16 07:26:42 -04:00
std::string file_name;
tbb::enumerable_thread_specific<std::unique_ptr<Context>> script_contexts;
};
2016-01-05 10:51:13 -05:00
}
}
#endif /* SCRIPTING_ENVIRONMENT_HPP */