A wrapper around ModuleHandle that uses RAII to manage its lifetime.
| 787 | |
| 788 | // A wrapper around ModuleHandle that uses RAII to manage its lifetime. |
| 789 | class ScopedModuleHandle { |
| 790 | public: |
| 791 | explicit ScopedModuleHandle(StreamExecutor *executor, |
| 792 | ModuleHandle module_handle) |
| 793 | : executor_(executor), module_handle_(module_handle) {} |
| 794 | |
| 795 | ScopedModuleHandle(ScopedModuleHandle &&other) { |
| 796 | executor_ = other.executor_; |
| 797 | module_handle_ = other.module_handle_; |
| 798 | other.executor_ = nullptr; |
| 799 | other.module_handle_ = ModuleHandle(); |
| 800 | } |
| 801 | |
| 802 | ScopedModuleHandle &operator=(ScopedModuleHandle &&other) { |
| 803 | executor_ = other.executor_; |
| 804 | module_handle_ = other.module_handle_; |
| 805 | other.executor_ = nullptr; |
| 806 | other.module_handle_ = ModuleHandle(); |
| 807 | return *this; |
| 808 | } |
| 809 | |
| 810 | ~ScopedModuleHandle() { |
| 811 | if (static_cast<bool>(module_handle_)) { |
| 812 | CHECK(executor_->UnloadModule(module_handle_)); |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | private: |
| 817 | StreamExecutor *executor_; |
| 818 | ModuleHandle module_handle_; |
| 819 | |
| 820 | TF_DISALLOW_COPY_AND_ASSIGN(ScopedModuleHandle); |
| 821 | }; |
| 822 | |
| 823 | //////////// |
| 824 | // Inlines |
no test coverage detected