github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/core/pools.go (about) 1 // Package core provides core metadata and in-cluster API 2 /* 3 * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package core 6 7 import ( 8 "sync" 9 10 "github.com/NVIDIA/aistore/cmn/debug" 11 ) 12 13 var ( 14 lomPool sync.Pool 15 lom0 LOM 16 17 putObjPool sync.Pool 18 putObj0 PutParams 19 20 coiPool sync.Pool 21 coi0 CopyParams 22 ) 23 24 ///////////// 25 // lomPool // 26 ///////////// 27 28 func AllocLOM(objName string) *LOM { 29 v := lomPool.Get() 30 if v == nil { 31 return &LOM{ObjName: objName} 32 } 33 lom := v.(*LOM) 34 debug.Assert(lom.ObjName == "" && lom.FQN == "") 35 lom.ObjName = objName 36 return lom 37 } 38 39 func FreeLOM(lom *LOM) { 40 debug.Assertf(lom.ObjName != "" || lom.FQN != "", "%q, %q", lom.ObjName, lom.FQN) 41 *lom = lom0 42 lomPool.Put(lom) 43 } 44 45 // 46 // PutParams pool 47 // 48 49 func AllocPutParams() (a *PutParams) { 50 if v := putObjPool.Get(); v != nil { 51 a = v.(*PutParams) 52 return 53 } 54 return &PutParams{} 55 } 56 57 func FreePutParams(a *PutParams) { 58 *a = putObj0 59 putObjPool.Put(a) 60 } 61 62 // 63 // CopyParams pool 64 // 65 66 func AllocCOI() (a *CopyParams) { 67 if v := coiPool.Get(); v != nil { 68 a = v.(*CopyParams) 69 return 70 } 71 return &CopyParams{} 72 } 73 74 func FreeCOI(a *CopyParams) { 75 *a = coi0 76 coiPool.Put(a) 77 }