ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.120 by root, Mon Oct 29 23:55:54 2012 UTC vs.
Revision 1.121 by root, Sun Nov 11 01:27:44 2012 UTC

460 refcnt_buf (void *data, size_t size); 460 refcnt_buf (void *data, size_t size);
461 461
462 refcnt_buf (const refcnt_buf &src) 462 refcnt_buf (const refcnt_buf &src)
463 { 463 {
464 data = src.data; 464 data = src.data;
465 ++_refcnt (); 465 inc ();
466 } 466 }
467 467
468 ~refcnt_buf (); 468 ~refcnt_buf ();
469 469
470 refcnt_buf &operator =(const refcnt_buf &src); 470 refcnt_buf &operator =(const refcnt_buf &src);
479 return _size (); 479 return _size ();
480 } 480 }
481 481
482protected: 482protected:
483 enum { 483 enum {
484 overhead = sizeof (unsigned int) * 2 484 overhead = sizeof (uint32_t) * 2
485 }; 485 };
486 486
487 unsigned int &_size () const 487 uint32_t &_size () const
488 { 488 {
489 return ((unsigned int *)data)[-2]; 489 return ((unsigned int *)data)[-2];
490 } 490 }
491 491
492 unsigned int &_refcnt () const 492 uint32_t &_refcnt () const
493 { 493 {
494 return ((unsigned int *)data)[-1]; 494 return ((unsigned int *)data)[-1];
495 } 495 }
496 496
497 void _alloc (unsigned int size) 497 void _alloc (uint32_t size)
498 { 498 {
499 data = ((char *)salloc<char> (size + overhead)) + overhead; 499 data = ((char *)salloc<char> (size + overhead)) + overhead;
500 _size () = size; 500 _size () = size;
501 _refcnt () = 1; 501 _refcnt () = 1;
502 } 502 }
503 503
504 void _dealloc ();
505
506 void inc ()
507 {
508 ++_refcnt ();
509 }
510
504 void dec () 511 void dec ()
505 { 512 {
506 if (!--_refcnt ()) 513 if (!--_refcnt ())
507 sfree<char> (data - overhead, size () + overhead); 514 _dealloc ();
508 } 515 }
509}; 516};
510 517
511INTERFACE_CLASS (attachable) 518INTERFACE_CLASS (attachable)
512struct refcnt_base 519struct refcnt_base

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines