XrdCmsRRData.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                       X r d C m s R R D a t a . c c                        */
00004 /*                                                                            */
00005 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010   
00011 //         $Id: XrdCmsRRData.cc 32231 2010-02-05 18:24:46Z ganis $
00012 
00013 const char *XrdCmsRRDataCVSID = "$Id: XrdCmsRRData.cc 32231 2010-02-05 18:24:46Z ganis $";
00014 
00015 #include <unistd.h>
00016 
00017 #include "XrdCms/XrdCmsRRData.hh"
00018 
00019 #include "XrdSys/XrdSysPlatform.hh"
00020 #include "XrdSys/XrdSysPthread.hh"
00021 
00022 using namespace XrdCms;
00023 
00024 /******************************************************************************/
00025 /*                               g e t B u f f                                */
00026 /******************************************************************************/
00027   
00028 int XrdCmsRRData::getBuff(size_t bsz)
00029 {  
00030    static size_t PageSize  = sysconf(_SC_PAGESIZE);
00031           size_t Alignment = PageSize;
00032 
00033    if (bsz < Alignment)
00034       {if (bsz <= 8) Alignment = bsz = 8;
00035           else {do {Alignment = Alignment >> 1;} while(bsz < Alignment);
00036                 Alignment = Alignment << 1; bsz = Alignment;
00037                }
00038       }
00039 
00040    if (Buff) free(Buff);
00041    if (posix_memalign((void **)&Buff, Alignment, bsz))
00042       {Buff = 0; return 0;}
00043 
00044    Blen = bsz;
00045    return 1;
00046 }
00047 
00048 /******************************************************************************/
00049 /*                             O b j e c t i f y                              */
00050 /******************************************************************************/
00051   
00052 XrdCmsRRData *XrdCmsRRData::Objectify(XrdCmsRRData *op)
00053 {
00054    static XrdSysMutex   myMutex;
00055    static XrdCmsRRData *Free;
00056 
00057 // Obtain a new object or recycle an old one
00058 //
00059    myMutex.Lock();
00060    if (op) {op->Next = Free; Free = op; op = 0;}
00061       else {if ((op = Free)) Free = op->Next;
00062                else {op = new XrdCmsRRData; op->Buff = 0; op->Blen = 0;}
00063             op->Ident = 0; op->Next = 0;
00064            }
00065 
00066    myMutex.UnLock();
00067 
00068    return op;
00069 }

Generated on Tue Jul 5 14:46:31 2011 for ROOT_528-00b_version by  doxygen 1.5.1