blitz_gc.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef BLITZ_GC_H
  2. #define BLITZ_GC_H
  3. #include "blitz_types.h"
  4. #ifdef __cplusplus
  5. extern "C"{
  6. #endif
  7. #define BBGC_MANYREFS 0x40000000
  8. //for bbGCSetMode
  9. #define BBGC_AUTOMATIC 1
  10. #define BBGC_MANUAL 2
  11. #define BBGC_AGGRESSIVE -1
  12. //for bbGCSetDebug
  13. #define BBGC_NODEBUG 0
  14. #define BBGC_STDOUTDEBUG 1
  15. //for bbGCAlloc
  16. #define BBGC_ATOMIC 1
  17. #define BBGC_FINALIZE 2
  18. //Probably shouldn't be here...
  19. #if __ppc__
  20. #define BBGC_NUM_ROOTREGS 19
  21. #else
  22. #define BBGC_NUM_ROOTREGS 4
  23. #endif
  24. void* bbGCRootRegs( void *p );
  25. void bbGCStartup();
  26. void bbGCSetMode( int mode );
  27. void bbGCSetDebug( int debug );
  28. void* bbGCMalloc( int size,int flags );
  29. BBObject* bbGCAllocObject( int size,BBClass *clas,int flags );
  30. int bbGCValidate( void *p );
  31. int bbGCMemAlloced();
  32. int bbGCCollect();
  33. void bbGCSuspend();
  34. void bbGCResume();
  35. void bbGCRetain( BBObject *p );
  36. void bbGCRelease( BBObject *p );
  37. // BBRETAIN/BBRELEASE should be used to prevent an object from garbage collection.
  38. //
  39. // This is mainly of use if an object is being stored outside of BlitzMax's 'sight' - say, in a C++ table.
  40. //
  41. // You can also use bbGCRetain/bbGCRelease functions above if necessary - MACROS are just faster.
  42. // For ref counting GC...
  43. //
  44. #ifdef BB_GC_RC
  45. #define BBRETAIN(X) {++(X)->refs;}
  46. #define BBRELEASE(X) {if( !--(X)->refs ) bbGCFree(X);}
  47. #endif
  48. // For Mark Sibly GC...
  49. //
  50. #ifdef BB_GC_MS
  51. #define BBRETAIN(X) bbGCRetain( ((BBObject*)(X)) );
  52. #define BBRELEASE(X) bbGCRelease( ((BBObject*)(X)) );
  53. #endif
  54. // For BDW GC...
  55. //
  56. #ifdef BB_GC_BDW
  57. #define BBRETAIN(X) {}
  58. #define BBRELEASE(X) {}
  59. #endif
  60. // Internal use only
  61. #ifdef BB_GC_RC
  62. void bbGCFree( BBObject *p ); //called when refs==0 - MAY be eligble for GC
  63. void bbGCDeallocObject( BBObject *p,int size ); //called after destruction - Sayonara!
  64. #define BBINCREFS(X) {++(X)->refs;}
  65. #define BBDECREFS(X) {if( !--(X)->refs ) bbGCFree(X);}
  66. #else
  67. #define BBINCREFS(X) {}
  68. #define BBDECREFS(X) {}
  69. #endif
  70. #ifdef __cplusplus
  71. }
  72. #endif
  73. #endif