XRootD
XrdPssAioCB.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d P s s A i o C B . c c */
4 /* */
5 /* (c) 2016 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Andrew Hanushevsky for Stanford University under contract */
8 /* DE-AC02-76-SFO0515 with the Department of Energy */
9 /* */
10 /* This file is part of the XRootD software suite. */
11 /* */
12 /* XRootD is free software: you can redistribute it and/or modify it under */
13 /* the terms of the GNU Lesser General Public License as published by the */
14 /* Free Software Foundation, either version 3 of the License, or (at your */
15 /* option) any later version. */
16 /* */
17 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20 /* License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25 /* */
26 /* The copyright holder's institutional names and contributor's names may not */
27 /* be used to endorse or promote products derived from this software without */
28 /* specific prior written permission of the institution or contributor. */
29 /******************************************************************************/
30 
31 #include <cerrno>
32 
33 #include "XrdPss/XrdPssAioCB.hh"
34 #include "XrdSfs/XrdSfsAio.hh"
35 
36 /******************************************************************************/
37 /* S t a t i c M e m b e r s */
38 /******************************************************************************/
39 
40 XrdSysMutex XrdPssAioCB::myMutex;
41 XrdPssAioCB *XrdPssAioCB::freeCB = 0;
42 int XrdPssAioCB::numFree = 0;
43 int XrdPssAioCB::maxFree = 100;
44 
45 /******************************************************************************/
46 /* A l l o c */
47 /******************************************************************************/
48 
49 XrdPssAioCB *XrdPssAioCB::Alloc(XrdSfsAio *aiop, bool isWr, bool pgrw)
50 {
51  XrdPssAioCB *newCB;
52 
53 // Try to allocate an prexisting object otherwise get a new one
54 //
55  myMutex.Lock();
56  if ((newCB = freeCB)) {freeCB = newCB->next; numFree--;}
57  else newCB = new XrdPssAioCB;
58  myMutex.UnLock();
59 
60 // Initialize the callback and return it
61 //
62  newCB->theAIOP = aiop;
63  newCB->isWrite = isWr;
64  newCB->isPGrw = pgrw;
65  return newCB;
66 }
67 
68 /******************************************************************************/
69 /* C o m p l e t e */
70 /******************************************************************************/
71 
72 #include <iostream>
73 void XrdPssAioCB::Complete(ssize_t result)
74 {
75 
76 // Set correct result
77 //
78 // std::cerr <<"AIO fin " <<(isWrite ? " write ":" read ")
79 // <<theAIOP->sfsAio.aio_nbytes <<'@' <<theAIOP->sfsAio.aio_offset
80 // <<" result " <<result <<std::endl;
81  theAIOP->Result = (result < 0 ? -errno : result);
82 
83 // Perform post processing for pgRead or pgWrite if successful
84 //
85  if (isPGrw && result >= 0)
86  {if (isWrite)
87  {
88  } else {
89  if (csVec.size() && theAIOP->cksVec)
90  memcpy(theAIOP->cksVec, csVec.data(), csVec.size()*sizeof(uint32_t));
91  }
92  }
93 
94 // Invoke the callback
95 //
96  if (isWrite) theAIOP->doneWrite();
97  else theAIOP->doneRead();
98 
99 // Now recycle ourselves
100 //
101  Recycle();
102 }
103 
104 /******************************************************************************/
105 /* R e c y c l e */
106 /******************************************************************************/
107 
109 {
110 // Perform recycling
111 //
112  myMutex.Lock();
113  if (numFree >= maxFree) delete this;
114  else {next = freeCB;
115  freeCB = this;
116  numFree++;
117  csVec.clear();
118  }
119  myMutex.UnLock();
120 }
std::vector< uint32_t > csVec
Definition: XrdPssAioCB.hh:53
void Recycle()
Definition: XrdPssAioCB.cc:108
virtual void Complete(ssize_t Result)
Definition: XrdPssAioCB.cc:73
static XrdPssAioCB * Alloc(XrdSfsAio *aiop, bool isWr, bool pgrw=false)
Definition: XrdPssAioCB.cc:49