osrm-backend/include/extractor/scripting_environment.hpp

41 lines
877 B
C++
Raw Normal View History

#ifndef SCRIPTING_ENVIRONMENT_HPP
#define SCRIPTING_ENVIRONMENT_HPP
2014-05-16 07:26:42 -04:00
#include <string>
#include <memory>
#include <mutex>
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:
ScriptingEnvironment() = delete;
explicit ScriptingEnvironment(const std::string &file_name);
2016-01-04 05:44:23 -05:00
lua_State *GetLuaState();
2014-05-16 07:26:42 -04:00
private:
2016-01-04 05:44:23 -05:00
void InitLuaState(lua_State *lua_state);
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::shared_ptr<lua_State>> script_contexts;
};
2016-01-05 10:51:13 -05:00
}
}
#endif /* SCRIPTING_ENVIRONMENT_HPP */