source:
vendors/XIOS/r_357/src/buffer_server.cpp
@
8339
Last change on this file since 8339 was 3428, checked in by rblod, 12 years ago | |
---|---|
File size: 2.9 KB |
Line | |
---|---|
1 | #include "xmlioserver_spl.hpp" |
2 | #include "exception.hpp" |
3 | #include "buffer_server.hpp" |
4 | #include "cxios.hpp" |
5 | |
6 | namespace xios |
7 | { |
8 | |
9 | CServerBuffer::CServerBuffer(void) |
10 | { |
11 | bufferSizeByClient=CXios::bufferSize*CXios::bufferServerFactorSize ; |
12 | size=bufferSizeByClient ; |
13 | first=0 ; |
14 | current=1 ; |
15 | end=size ; |
16 | buffer=new char[size] ; // change later for MPI_ALLOC_MEM later |
17 | } |
18 | |
19 | CServerBuffer::~CServerBuffer() |
20 | { |
21 | delete [] buffer ; |
22 | } |
23 | |
24 | |
25 | bool CServerBuffer::isBufferFree(size_t count) |
26 | { |
27 | bool ret ; |
28 | |
29 | if (count==0) return true ; |
30 | |
31 | if (current>first) |
32 | { |
33 | if (current+count<size) |
34 | { |
35 | ret=true ; |
36 | } |
37 | else if (current+count==size) |
38 | { |
39 | if (first>0) |
40 | { |
41 | ret=true ; |
42 | } |
43 | else |
44 | { |
45 | ret=false ; |
46 | } |
47 | } |
48 | else |
49 | { |
50 | if (count<first) |
51 | { |
52 | ret=true ; |
53 | } |
54 | else |
55 | { |
56 | ret=false ; |
57 | } |
58 | } |
59 | } |
60 | else |
61 | { |
62 | if (current+count<first) |
63 | { |
64 | ret=true ; |
65 | } |
66 | else |
67 | { |
68 | ret=false ; |
69 | } |
70 | } |
71 | |
72 | return ret ; |
73 | } |
74 | |
75 | |
76 | void* CServerBuffer::getBuffer(size_t count) |
77 | { |
78 | char* ret ; |
79 | |
80 | if (count==0) return buffer+current ; |
81 | |
82 | if (current>first) |
83 | { |
84 | if (current+count<size) |
85 | { |
86 | ret=buffer+current ; |
87 | current+=count ; |
88 | } |
89 | else if (current+count==size) |
90 | { |
91 | if (first>0) |
92 | { |
93 | ret=buffer+current ; |
94 | current=0 ; |
95 | } |
96 | else |
97 | { |
98 | ERROR("void* CServerBuffer::getBuffer(size_t count)", |
99 | <<"cannot allocate required size in buffer") ; |
100 | } |
101 | } |
102 | else |
103 | { |
104 | end=current ; |
105 | if (count<first) |
106 | { |
107 | ret=buffer ; |
108 | current=count ; |
109 | } |
110 | else |
111 | { |
112 | ERROR("void* CServerBuffer::getBuffer(size_t count)", |
113 | <<"cannot allocate required size in buffer") ; |
114 | } |
115 | } |
116 | } |
117 | else |
118 | { |
119 | if (current+count<first) |
120 | { |
121 | ret=buffer+current ; |
122 | current+=count ; |
123 | } |
124 | else |
125 | { |
126 | ERROR("void* CServerBuffer::getBuffer(size_t count)", |
127 | <<"cannot allocate required size in buffer") ; |
128 | } |
129 | } |
130 | |
131 | return ret ; |
132 | } |
133 | |
134 | void CServerBuffer::freeBuffer(size_t count) |
135 | { |
136 | if (count==0) return ; |
137 | |
138 | if (first==end-1) |
139 | { |
140 | first=0 ; |
141 | count-- ; |
142 | end=size ; |
143 | } |
144 | |
145 | if (first<=current) |
146 | { |
147 | if (first+count <current) |
148 | { |
149 | first+=count ; |
150 | } |
151 | else |
152 | { |
153 | ERROR("void CServerBuffer::freeBuffer(size_t count)", |
154 | <<"cannot free required size in buffer") ; |
155 | } |
156 | |
157 | } |
158 | else |
159 | { |
160 | if (first+count<end) |
161 | { |
162 | first+=count ; |
163 | } |
164 | else |
165 | { |
166 | ERROR("void CServerBuffer::freeBuffer(size_t count)", |
167 | <<"cannot free required size in buffer") ; |
168 | } |
169 | } |
170 | } |
171 | |
172 | } |
Note: See TracBrowser
for help on using the repository browser.