~drizzle-trunk/libdrizzle/jenkins-Libdrizzle-78

« back to all changes in this revision

Viewing changes to libdrizzle/structs.h

  • Committer: Continuous Integration
  • Date: 2013-01-27 06:03:16 UTC
  • mfrom: (99.1.4 libdrizzle-5.1)
  • Revision ID: ci@drizzle.org-20130127060316-bpl5rb8is079kbc7
Merge lp:~brianaker/libdrizzle/push-pop-rework Build: jenkins-Libdrizzle-58

Show diffs side-by-side

added added

removed removed

Lines of Context:
256
256
private:
257
257
  size_t _state_stack_count;
258
258
  Packet *_state_stack_list;
 
259
  Packet _stack_packets[DRIZZLE_STATE_STACK_SIZE];
 
260
  size_t _free_packet_count;
 
261
  Packet *_free_packet_list;
259
262
public:
260
263
 
261
264
  drizzle_st() :
299
302
    stmt(NULL),
300
303
    binlog(NULL),
301
304
    _state_stack_count(0),
302
 
    _state_stack_list(NULL)
 
305
    _state_stack_list(NULL),
 
306
    _free_packet_count(0),
 
307
    _free_packet_list(NULL)
303
308
  {
304
309
    db[0]= '\0';
305
310
    password[0]= '\0';
309
314
    last_error[0]= '\0';
310
315
    buffer= (unsigned char*)malloc(DRIZZLE_DEFAULT_BUFFER_SIZE);
311
316
    buffer_ptr= buffer;
 
317
 
 
318
    assert(DRIZZLE_STATE_STACK_SIZE);
 
319
    for (size_t x= 0; x < DRIZZLE_STATE_STACK_SIZE; ++x)
 
320
    {
 
321
      Packet *packet= &(_stack_packets[x]);
 
322
      packet->init(this);
 
323
      LIBDRIZZLE_LIST_ADD(_free_packet, packet);
 
324
      assert(_free_packet_list);
 
325
    }
312
326
  }
313
327
 
314
328
  ~drizzle_st()
318
332
 
319
333
  bool push_state(drizzle_state_fn* func_)
320
334
  {
321
 
    Packet *tmp= new (std::nothrow) Packet(func_);
 
335
    Packet *tmp;
 
336
    if (_free_packet_count)
 
337
    {
 
338
      tmp= _free_packet_list;
 
339
      LIBDRIZZLE_LIST_DEL(_free_packet, tmp);
 
340
      tmp->func(func_);
 
341
    }
 
342
    else
 
343
    {
 
344
      tmp= new (std::nothrow) Packet(this, func_);
 
345
    }
 
346
 
322
347
    if (tmp)
323
348
    {
324
349
      LIBDRIZZLE_LIST_ADD(_state_stack, tmp);
335
360
 
336
361
  drizzle_return_t current_state()
337
362
  {
338
 
    return _state_stack_list->func(this);
 
363
    return _state_stack_list->func();
339
364
  }
340
365
 
341
366
  void pop_state()
344
369
    if (tmp)
345
370
    {
346
371
      LIBDRIZZLE_LIST_DEL(_state_stack, tmp);
347
 
      delete tmp;
 
372
 
 
373
      if (tmp->stack())
 
374
      {
 
375
        tmp->clear();
 
376
        LIBDRIZZLE_LIST_ADD(_free_packet, tmp);
 
377
      }
 
378
      else
 
379
      {
 
380
        delete tmp;
 
381
      }
348
382
    }
349
383
  }
350
384