MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / addCommand_

Method addCommand_

source/MRViewer/MRCommandLoop.cpp:115–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115void CommandLoop::addCommand_( CommandFunc func, bool blockThread, StartPosition state )
116{
117 std::exception_ptr exception;
118 if ( blockThread )
119 {
120 // Adjust the `func` to store thrown exceptions.
121 func = [next = std::move( func ), &exception]
122 {
123 try
124 {
125 next();
126 }
127 catch ( ... )
128 {
129 exception = std::current_exception();
130 }
131 };
132 }
133
134 auto& inst = instance_();
135 std::shared_ptr<Command> cmd = std::make_shared<Command>();
136 cmd->state = state;
137 cmd->func = func;
138 cmd->threadId = std::this_thread::get_id();
139 std::unique_lock<std::mutex> lock( inst.mutex_ );
140 if ( inst.queueClosed_ )
141 {
142 spdlog::debug( "CommandLoop::addCommand_: cannot accept new command because it is closed" );
143 return;
144 }
145 inst.commands_.push( cmd );
146
147 getViewerInstance().postEmptyEvent();
148 if ( blockThread )
149 {
150 cmd->callerThreadCV.wait( lock );
151
152 if ( exception )
153 std::rethrow_exception( exception );
154 }
155}
156
157void skipFramesAfterInput()
158{

Callers

nothing calls this directly

Calls 2

postEmptyEventMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected