github.com/scaleoutsean/fusego@v0.0.0-20220224074057-4a6429e46bb8/freelists.go (about) 1 // Copyright 2015 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package fuse 16 17 import ( 18 "unsafe" 19 20 "github.com/scaleoutsean/fusego/internal/buffer" 21 ) 22 23 //////////////////////////////////////////////////////////////////////// 24 // buffer.InMessage 25 //////////////////////////////////////////////////////////////////////// 26 27 // LOCKS_EXCLUDED(c.mu) 28 func (c *Connection) getInMessage() *buffer.InMessage { 29 c.mu.Lock() 30 x := (*buffer.InMessage)(c.inMessages.Get()) 31 c.mu.Unlock() 32 33 if x == nil { 34 x = new(buffer.InMessage) 35 } 36 37 return x 38 } 39 40 // LOCKS_EXCLUDED(c.mu) 41 func (c *Connection) putInMessage(x *buffer.InMessage) { 42 c.mu.Lock() 43 c.inMessages.Put(unsafe.Pointer(x)) 44 c.mu.Unlock() 45 } 46 47 //////////////////////////////////////////////////////////////////////// 48 // buffer.OutMessage 49 //////////////////////////////////////////////////////////////////////// 50 51 // LOCKS_EXCLUDED(c.mu) 52 func (c *Connection) getOutMessage() *buffer.OutMessage { 53 c.mu.Lock() 54 x := (*buffer.OutMessage)(c.outMessages.Get()) 55 c.mu.Unlock() 56 57 if x == nil { 58 x = new(buffer.OutMessage) 59 } 60 x.Reset() 61 62 return x 63 } 64 65 // LOCKS_EXCLUDED(c.mu) 66 func (c *Connection) putOutMessage(x *buffer.OutMessage) { 67 c.mu.Lock() 68 c.outMessages.Put(unsafe.Pointer(x)) 69 c.mu.Unlock() 70 }