diff options
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.62 2009/11/18 13:13:47 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.63 2009/11/26 11:39:20 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -785,6 +785,21 @@ void luaC_step (lua_State *L) { | |||
785 | } | 785 | } |
786 | 786 | ||
787 | 787 | ||
788 | /* | ||
789 | ** advances the garbage collector until it reaches a "valid" state | ||
790 | ** (defined by the caller) | ||
791 | */ | ||
792 | void luaC_runtilstate (lua_State *L, int validstates) { | ||
793 | global_State *g = G(L); | ||
794 | while (!(g->gcstate & validstates)) | ||
795 | singlestep(L); | ||
796 | } | ||
797 | |||
798 | |||
799 | /* | ||
800 | ** performs a full GC cycle; if "isememrgency", does not call | ||
801 | ** finalizers (which could change stack positions) | ||
802 | */ | ||
788 | void luaC_fullgc (lua_State *L, int isemergency) { | 803 | void luaC_fullgc (lua_State *L, int isemergency) { |
789 | global_State *g = G(L); | 804 | global_State *g = G(L); |
790 | lua_assert(g->gckind == KGC_NORMAL); | 805 | lua_assert(g->gckind == KGC_NORMAL); |
@@ -796,16 +811,13 @@ void luaC_fullgc (lua_State *L, int isemergency) { | |||
796 | g->gcstate = GCSsweepstring; | 811 | g->gcstate = GCSsweepstring; |
797 | } | 812 | } |
798 | /* finish any pending sweep phase */ | 813 | /* finish any pending sweep phase */ |
799 | while (issweep(g)) singlestep(L); | 814 | luaC_runtilstate(L, ~(GCSsweepstring | GCSsweep)); |
800 | markroot(L); /* start a new collection */ | 815 | markroot(L); /* start a new collection */ |
801 | /* run collector up to finalizers */ | 816 | /* run collector up to finalizers */ |
802 | while (g->gcstate != GCSfinalize) | 817 | luaC_runtilstate(L, GCSfinalize); |
803 | singlestep(L); | ||
804 | g->gckind = KGC_NORMAL; | 818 | g->gckind = KGC_NORMAL; |
805 | if (!isemergency) { /* do not run finalizers during emergency GC */ | 819 | if (!isemergency) /* do not run finalizers during emergency GC */ |
806 | while (g->gcstate != GCSpause) | 820 | luaC_runtilstate(L, ~GCSfinalize); |
807 | singlestep(L); | ||
808 | } | ||
809 | g->GCthreshold = (g->totalbytes/100) * g->gcpause; | 821 | g->GCthreshold = (g->totalbytes/100) * g->gcpause; |
810 | } | 822 | } |
811 | 823 | ||