Jakub Grajciar | 07363a4 | 2020-04-02 10:02:17 +0200 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * Copyright (c) 2020 Cisco and/or its affiliates. |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | *------------------------------------------------------------------ |
| 16 | */ |
| 17 | |
| 18 | package memif |
| 19 | |
| 20 | import ( |
| 21 | "unsafe" |
| 22 | ) |
| 23 | |
| 24 | // readHead reads ring head directly form the shared memory |
| 25 | func (q *Queue) readHead() (head int) { |
| 26 | return (int)(*(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringHeadOffset]))) |
| 27 | // return atomicload16(&q.i.regions[q.region].data[q.offset + descHeadOffset]) |
| 28 | } |
| 29 | |
| 30 | // readTail reads ring tail directly form the shared memory |
| 31 | func (q *Queue) readTail() (tail int) { |
| 32 | return (int)(*(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringTailOffset]))) |
| 33 | // return atomicload16(&q.i.regions[q.region].data[q.offset + descTailOffset]) |
| 34 | } |
| 35 | |
| 36 | // writeHead writes ring head directly to the shared memory |
| 37 | func (q *Queue) writeHead(value int) { |
| 38 | *(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringHeadOffset])) = *(*uint16)(unsafe.Pointer(&value)) |
| 39 | //atomicstore16(&q.i.regions[q.region].data[q.offset + descHeadOffset], value) |
| 40 | } |
| 41 | |
| 42 | // writeTail writes ring tail directly to the shared memory |
| 43 | func (q *Queue) writeTail(value int) { |
| 44 | *(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringTailOffset])) = *(*uint16)(unsafe.Pointer(&value)) |
| 45 | //atomicstore16(&q.i.regions[q.region].data[q.offset + descTailOffset], value) |
| 46 | } |
| 47 | |
| 48 | func (q *Queue) setDescLength(slot int, length int) { |
| 49 | *(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringSize+slot*descSize+descLengthOffset])) = *(*uint16)(unsafe.Pointer(&length)) |
| 50 | } |
| 51 | |
| 52 | // getFlags reads ring flags directly from the shared memory |
| 53 | func (q *Queue) getFlags() int { |
| 54 | return (int)(*(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringFlagsOffset]))) |
| 55 | } |