Revision 1229 branches/threaded2merge/src/linad99/thread_stuff.cpp

thread_stuff.cpp (revision 1229)
7 7
#  endif
8 8
#endif
9 9

  
10
pthread_mutex_t mutex_print;
11

  
12 10
typedef char * pchar;
13 11
typedef pchar *  ppchar;
14 12
typedef ofstream * pofstream;
......
29 27
  int i;
30 28
  buffer_size=bs;
31 29
  nslaves=ns;
32
  transfer_buffer=new pchar[ns];
33
  current_bptr=new pchar[ns];
34
  current_bptr--;
35
  buffend=new pchar[ns];
36
  transfer_buffer--;
37
  buffend--;
38 30
  // for timing 0 is for master 1-n for slaves
39 31
  if (logflag)
40 32
  {
......
163 155
  sflag.initialize();
164 156
  int i;
165 157
  buffer_size=bs;
166
  transfer_buffer=new pchar[ns];
167
  current_bptr=new pchar[ns];
168
  current_bptr--;
169
  buffend=new pchar[ns];
170
  transfer_buffer--;
171
  buffend--;
172 158
  // for timing 0 is for master 1-n for slaves
173 159
  if (logflag)
174 160
  {
......
182 168
      logfiles[i]=new ofstream(fname);
183 169
    }
184 170
  }
185
  
186
  for (i=1;i<=ns;i++)
187
  {
188
    transfer_buffer[i]=new char[bs];
189
    current_bptr[i]=transfer_buffer[i];
190
    buffend[i]=transfer_buffer[i]+bs-1;
191
  }
192 171
  smutex=new pthread_mutex_t[ns];
193 172
  smutex--;
194 173
  pthread_mutex_init(&copy_mutex,NULL);
......
305 284
    }
306 285
  }
307 286
}
308

  
309 287
void adpthread_manager::attach_code(pthreadfun pf)
310 288
{
311 289
  ppf[++num_code]=pf;
312 290
}
313

  
314
void adpthread_manager::check_buffer_size_read(int nbytes,int sno)
315
{
316
  
317
  // if the buffer is too small on read there is an error
318
  if (current_bptr[sno]+nbytes>buffend[sno])
319
  {
320
    std::ptrdiff_t pd=current_bptr[sno]-transfer_buffer[sno];
321
    std::ptrdiff_t pd1=buffend[sno]-transfer_buffer[sno];
322
    cout << "current offset is " << pd << " bytes " << endl;
323
    cout << "trying to read  " << nbytes << " bytes " << endl;
324
    cout << "buffend is at     " << pd1 << " bytes " << endl;
325
    cerr << "error reading from master slave buffer for slave "
326
         << sno << endl;
327
    ad_exit(1);
328
  }
329
}
330

  
331 291
void adpthread_manager::check_buffer_size_read(int nbytes,int s1,int s2)
332 292
{
333 293
  if (stransfer_buffer[s1][s2]== 0)
......
393 353
  }
394 354
  while(1);
395 355
}
396

  
397

  
398
/*
399
void adpthread_manager::check_buffer_size(int nbytes,int sno)
400
{
401
  // if the buffer is too small make it bigger and copy old
402
  // buffer contents
403
  if (current_bptr[sno]+nbytes>buffend[sno])
404
  {
405
    std::ptrdiff_t pd=current_bptr[sno]-transfer_buffer[sno];
406
    std::ptrdiff_t pd1=buffend[sno]-transfer_buffer[sno];
407
    cout << "current offset is " << pd << " bytes " << endl;
408
    cout << "trying to write " << nbytes << " bytes " << endl;
409
    cout << "current buffend is at " << pd1 << " bytes " << endl;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff