| 3230 | } |
| 3231 | |
| 3232 | ProducerBase* add_producer(ProducerBase* producer) |
| 3233 | { |
| 3234 | // Handle failed memory allocation |
| 3235 | if (producer == nullptr) { |
| 3236 | return nullptr; |
| 3237 | } |
| 3238 | |
| 3239 | producerCount.fetch_add(1, std::memory_order_relaxed); |
| 3240 | |
| 3241 | // Add it to the lock-free list |
| 3242 | auto prevTail = producerListTail.load(std::memory_order_relaxed); |
| 3243 | do { |
| 3244 | producer->next = prevTail; |
| 3245 | } while (!producerListTail.compare_exchange_weak(prevTail, producer, std::memory_order_release, std::memory_order_relaxed)); |
| 3246 | |
| 3247 | #ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG |
| 3248 | if (producer->isExplicit) { |
| 3249 | auto prevTailExplicit = explicitProducers.load(std::memory_order_relaxed); |
| 3250 | do { |
| 3251 | static_cast<ExplicitProducer*>(producer)->nextExplicitProducer = prevTailExplicit; |
| 3252 | } while (!explicitProducers.compare_exchange_weak(prevTailExplicit, static_cast<ExplicitProducer*>(producer), std::memory_order_release, std::memory_order_relaxed)); |
| 3253 | } |
| 3254 | else { |
| 3255 | auto prevTailImplicit = implicitProducers.load(std::memory_order_relaxed); |
| 3256 | do { |
| 3257 | static_cast<ImplicitProducer*>(producer)->nextImplicitProducer = prevTailImplicit; |
| 3258 | } while (!implicitProducers.compare_exchange_weak(prevTailImplicit, static_cast<ImplicitProducer*>(producer), std::memory_order_release, std::memory_order_relaxed)); |
| 3259 | } |
| 3260 | #endif |
| 3261 | |
| 3262 | return producer; |
| 3263 | } |
| 3264 | |
| 3265 | void reown_producers() |
| 3266 | { |
no outgoing calls
no test coverage detected