Home / Function/ offer() — netty Function Reference

offer() — netty Function Reference

Architecture documentation for the offer() function in MpscIntQueue.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  fb7f0fff_a870_3ec4_c353_7341bc7fdd2e["offer()"]
  c00a7e8d_e19a_6d4a_6887_5d0634281bed["MpscAtomicIntegerArrayQueue"]
  fb7f0fff_a870_3ec4_c353_7341bc7fdd2e -->|defined in| c00a7e8d_e19a_6d4a_6887_5d0634281bed
  6c53d641_1124_ccce_e265_4ede0841b9c5["poll()"]
  fb7f0fff_a870_3ec4_c353_7341bc7fdd2e -->|calls| 6c53d641_1124_ccce_e265_4ede0841b9c5
  style fb7f0fff_a870_3ec4_c353_7341bc7fdd2e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

common/src/main/java/io/netty/util/concurrent/MpscIntQueue.java lines 125–158

        @Override
        public boolean offer(int value) {
            if (value == emptyValue) {
                throw new IllegalArgumentException("Cannot offer the \"empty\" value: " + emptyValue);
            }
            // use a cached view on consumer index (potentially updated in loop)
            final int mask = this.mask;
            long producerLimit = this.producerLimit;
            long pIndex;
            do {
                pIndex = producerIndex;
                if (pIndex >= producerLimit) {
                    final long cIndex = consumerIndex;
                    producerLimit = cIndex + mask + 1;
                    if (pIndex >= producerLimit) {
                        // FULL :(
                        return false;
                    } else {
                        // update producer limit to the next index that we must recheck the consumer index
                        // this is racy, but the race is benign
                        PRODUCER_LIMIT.lazySet(this, producerLimit);
                    }
                }
            } while (!PRODUCER_INDEX.compareAndSet(this, pIndex, pIndex + 1));
            /*
             * NOTE: the new producer index value is made visible BEFORE the element in the array. If we relied on
             * the index visibility to poll() we would need to handle the case where the element is not visible.
             */
            // Won CAS, move on to storing
            final int offset = (int) (pIndex & mask);
            lazySet(offset, value);
            // AWESOME :)
            return true;
        }

Domain

Subdomains

Calls

Frequently Asked Questions

What does offer() do?
offer() is a function in the netty codebase, defined in common/src/main/java/io/netty/util/concurrent/MpscIntQueue.java.
Where is offer() defined?
offer() is defined in common/src/main/java/io/netty/util/concurrent/MpscIntQueue.java at line 125.
What does offer() call?
offer() calls 1 function(s): poll.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free