MCPcopy Create free account
hub / github.com/COVESA/vsomeip / start

Method start

implementation/runtime/src/application_impl.cpp:309–534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

307}
308
309void application_impl::start() {
310#if defined(__linux__)
311 // only set threadname if calling thread isn't the main thread
312 if (getpid() != static_cast<pid_t>(syscall(SYS_gettid))) {
313 start_thread_ = pthread_self();
314 std::stringstream s;
315 s << hex4(client_) << "_io" << std::setw(2) << 0;
316 pthread_setname_np(start_thread_, s.str().c_str());
317 }
318#endif
319 {
320 std::scoped_lock its_initialized_lock{initialize_mutex_};
321 if (!is_initialized_) {
322 VSOMEIP_ERROR << "Trying to start uninitialized application \"" << name_ << "\" (" << hex4(client_) << ")";
323 return;
324 }
325 }
326
327 const size_t io_thread_count = configuration_->get_io_thread_count(name_);
328 const int io_thread_nice_level = configuration_->get_io_thread_nice_level(name_);
329 {
330 std::scoped_lock its_lock{start_stop_mutex_};
331
332 {
333 std::scoped_lock its_lock_inner{handlers_mutex_};
334 if (!dispatchers_.empty() || !io_threads_.empty()) {
335 VSOMEIP_ERROR << "Trying to start an already started application (" << hex4(client_) << ") ";
336 return;
337 }
338 }
339
340 if (io_.stopped()) {
341 io_.restart();
342 }
343
344 VSOMEIP_INFO << "Starting vsomeip application \"" << name_ << "\" (" << hex4(client_) << ") using " << io_thread_count << " threads"
345#if defined(__linux__) || defined(__QNX__)
346 << " I/O nice " << io_thread_nice_level
347#endif
348 ;
349
350 {
351 std::scoped_lock its_lock_inner{handlers_mutex_};
352 is_dispatching_ = true;
353 elapse_unactive_dispatchers_ = false;
354 std::packaged_task<void()> dispatcher_task_(std::bind(&application_impl::main_dispatch, shared_from_this()));
355 auto its_main_dispatcher = std::make_shared<std::thread>(std::move(dispatcher_task_));
356
357 dispatchers_[its_main_dispatcher->get_id()] = its_main_dispatcher;
358 }
359 if (routing_app_) {
360 routing_app_->start();
361 }
362 if (routing_)
363 routing_->start();
364
365 for (size_t i = 0; i < io_thread_count - 1; i++) {
366 auto its_thread = std::make_shared<std::thread>([this, i, io_thread_nice_level] {

Callers

nothing calls this directly

Calls 15

hex4Function · 0.85
hex2Function · 0.85
get_idFunction · 0.85
get_io_thread_countMethod · 0.80
get_pluginsMethod · 0.80
endMethod · 0.80
unlockMethod · 0.80
save_threadMethod · 0.80
detachMethod · 0.80
restartMethod · 0.45
get_idMethod · 0.45

Tested by

no test coverage detected