source: XIOS/dev/branch_yushan/src/buffer_server.cpp @ 1102

Last change on this file since 1102 was 1085, checked in by yushan, 7 years ago

save modif for local compilation

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1#include "xios_spl.hpp"
2#include "exception.hpp"
3#include "buffer_server.hpp"
4
5namespace xios
6{
7
8  CServerBuffer::CServerBuffer(StdSize buffSize)
9  {
10    size = 3 * buffSize;
11    first = 0;
12    current = 1;
13    end = size;
14    buffer = new char[size]; // use MPI_ALLOC_MEM later?
15  }
16
17  CServerBuffer::~CServerBuffer()
18  {
19    delete [] buffer ;
20  }
21
22
23  bool CServerBuffer::isBufferFree(size_t count)
24  {
25    bool ret ;
26
27    if (count==0) return true ;
28
29    if (current>first)
30    {
31      if (current+count<size)
32      {
33        ret=true ;
34      }
35      else if (current+count==size)
36      {
37        if (first>0)
38        {
39          ret=true ;
40        }
41        else
42        {
43          ret=false ;
44        }
45      }
46      else
47      {
48        if (count<first)
49        {
50          ret=true ;
51        }
52        else
53        {
54          ret=false ;
55        }
56      }
57    }
58    else
59    {
60      if (current+count<first)
61      {
62        ret=true ;
63      }
64      else
65      {
66         ret=false ;
67      }
68    }
69
70    return ret ;
71  }
72
73
74  void* CServerBuffer::getBuffer(size_t count)
75  {
76    char* ret ;
77
78    if (count==0) return buffer+current ;
79
80    if (current>first)
81    {
82      if (current+count<size)
83      {
84        ret=buffer+current ;
85        current+=count ;
86      }
87      else if (current+count==size)
88      {
89        if (first>0)
90        {
91          ret=buffer+current ;
92          current=0 ;
93        }
94        else
95        {
96          ERROR("void* CServerBuffer::getBuffer(size_t count)",
97                 <<"cannot allocate required size in buffer") ;
98        }
99      }
100      else
101      {
102        end=current ;
103        if (count<first)
104        {
105          ret=buffer ;
106          current=count ;
107        }
108        else
109        {
110          ERROR("void* CServerBuffer::getBuffer(size_t count)",
111                 <<"cannot allocate required size in buffer") ;
112        }
113      }
114    }
115    else
116    {
117      if (current+count<first)
118      {
119        ret=buffer+current ;
120        current+=count ;
121      }
122      else
123      {
124          ERROR("void* CServerBuffer::getBuffer(size_t count)",
125                 <<"cannot allocate required size in buffer") ;
126      }
127    }
128
129    return ret ;
130  }
131
132  void CServerBuffer::freeBuffer(size_t count)
133  {
134    if (count==0) return ;
135
136    if (first==end-1)
137    {
138      first=0 ;
139      count-- ;
140      end=size ;
141    }
142
143    if (first<=current)
144    {
145      if (first+count <current)
146      {
147        first+=count ;
148      }
149      else
150      {
151          ERROR("void CServerBuffer::freeBuffer(size_t count)",
152                 <<"cannot free required size in buffer") ;
153      }
154
155    }
156    else
157    {
158      if (first+count<end)
159      {
160        first+=count ;
161      }
162      else
163      {
164          ERROR("void CServerBuffer::freeBuffer(size_t count)",
165                 <<"cannot free required size in buffer") ;
166      }
167    }
168  }
169
170}
Note: See TracBrowser for help on using the repository browser.