blob: 4469d26e9829aed7bc596f03eb0ccc3ac27b6e44 [file] [log] [blame]
Jakub Grajciar07363a42020-04-02 10:02:17 +02001/*
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
18package memif
19
20import (
21 "unsafe"
22)
23
24// readHead reads ring head directly form the shared memory
25func (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
31func (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
37func (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
43func (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
48func (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
53func (q *Queue) getFlags() int {
54 return (int)(*(*uint16)(unsafe.Pointer(&q.i.regions[q.ring.region].data[q.ring.offset+ringFlagsOffset])))
55}