Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scheduler/common/pass_register.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "pass_register.hpp"

namespace deepx
{

PassRegistry &PassRegistry::instance()
{
static PassRegistry registry_ins;
return registry_ins;
}

void PassRegistry::register_pass(const std::string &name, pass_func func)
{
registry_[name] = func;
}
}
38 changes: 38 additions & 0 deletions scheduler/common/pass_register.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>
#include <string>
#include <unordered_map>
#include <functional>

/**
* 使用REGISTER_PASS 宏用于注册pass
*/
namespace deepx
{
using pass_func = std::function<void()>;

class PassRegistry
{
public:
static PassRegistry& instance();

void register_pass(const std::string &name, pass_func func);

PassRegistry(const PassRegistry&) = delete;
PassRegistry& operator=(const PassRegistry&) = delete;

private:
PassRegistry() = default;

private:
std::unordered_map<std::string, pass_func> registry_;
};
}


#define REGISTER_PASS(name, func) \
struct Register##name { \
Register##name() { \
PassRegistry::instance().register_pass(#name, func); \
} \
}; \
static Register##name register_##name;