| 67 | std::once_flag g_objects_counter_init_flag; // flag used to initialise "g_objects_counter" with "std::call_once" |
| 68 | |
| 69 | void create_context_impl(McContext* pOutContext, McFlags flags, uint32_t helperThreadCount) |
| 70 | { |
| 71 | #if !defined(MCUT_WITH_COMPUTE_HELPER_THREADPOOL) |
| 72 | UNUSED(helperThreadCount); |
| 73 | #endif |
| 74 | |
| 75 | MCUT_ASSERT(pOutContext != nullptr); |
| 76 | |
| 77 | std::call_once(g_objects_counter_init_flag, []() { g_objects_counter.store(0xDECAF); /*any non-ero value*/ }); |
| 78 | |
| 79 | const McContext handle = reinterpret_cast<McContext>(g_objects_counter.fetch_add(1, std::memory_order_relaxed)); |
| 80 | |
| 81 | // Here we actually create the context object (as shared ptr) and stored in a global |
| 82 | // variable g_contexts. Note that g_contexts can be accessed by multiple threads |
| 83 | // simultaneously. |
| 84 | g_contexts.push_front(std::shared_ptr<context_t>( |
| 85 | new context_t(handle, flags |
| 86 | #if defined(MCUT_WITH_COMPUTE_HELPER_THREADPOOL) |
| 87 | , |
| 88 | helperThreadCount |
| 89 | #endif |
| 90 | ))); |
| 91 | |
| 92 | *pOutContext = handle; |
| 93 | } |
| 94 | |
| 95 | void debug_message_callback_impl( |
| 96 | McContext contextHandle, |
no test coverage detected