aboutsummaryrefslogtreecommitdiff
path: root/src/keeper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keeper.c')
-rw-r--r--src/keeper.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/keeper.c b/src/keeper.c
index 7eda598..05e9a02 100644
--- a/src/keeper.c
+++ b/src/keeper.c
@@ -65,6 +65,8 @@ typedef struct
65 lua_Integer limit; 65 lua_Integer limit;
66} keeper_fifo; 66} keeper_fifo;
67 67
68static int const CONTENTS_TABLE = 1;
69
68// replaces the fifo ud by its uservalue on the stack 70// replaces the fifo ud by its uservalue on the stack
69static keeper_fifo* prepare_fifo_access( lua_State* L, int idx_) 71static keeper_fifo* prepare_fifo_access( lua_State* L, int idx_)
70{ 72{
@@ -74,7 +76,7 @@ static keeper_fifo* prepare_fifo_access( lua_State* L, int idx_)
74 idx_ = lua_absindex( L, idx_); 76 idx_ = lua_absindex( L, idx_);
75 STACK_GROW( L, 1); 77 STACK_GROW( L, 1);
76 // we can replace the fifo userdata in the stack without fear of it being GCed, there are other references around 78 // we can replace the fifo userdata in the stack without fear of it being GCed, there are other references around
77 lua_getuservalue( L, idx_); 79 lua_getiuservalue( L, idx_, CONTENTS_TABLE);
78 lua_replace( L, idx_); 80 lua_replace( L, idx_);
79 } 81 }
80 return fifo; 82 return fifo;
@@ -86,12 +88,13 @@ static void fifo_new( lua_State* L)
86{ 88{
87 keeper_fifo* fifo; 89 keeper_fifo* fifo;
88 STACK_GROW( L, 2); 90 STACK_GROW( L, 2);
89 fifo = (keeper_fifo*) lua_newuserdata( L, sizeof( keeper_fifo)); 91 // a fifo full userdata has one uservalue, the table that holds the actual fifo contents
92 fifo = (keeper_fifo*)lua_newuserdatauv( L, sizeof( keeper_fifo), 1);
90 fifo->first = 1; 93 fifo->first = 1;
91 fifo->count = 0; 94 fifo->count = 0;
92 fifo->limit = -1; 95 fifo->limit = -1;
93 lua_newtable( L); 96 lua_newtable( L);
94 lua_setuservalue( L, -2); 97 lua_setiuservalue( L, -2, CONTENTS_TABLE);
95} 98}
96 99
97// in: expect fifo ... on top of the stack 100// in: expect fifo ... on top of the stack
@@ -422,7 +425,7 @@ int keepercall_set( lua_State* L)
422 should_wake_writers = (fifo->limit > 0) && (fifo->count >= fifo->limit); 425 should_wake_writers = (fifo->limit > 0) && (fifo->count >= fifo->limit);
423 lua_remove( L, -2); // fifos fifo 426 lua_remove( L, -2); // fifos fifo
424 lua_newtable( L); // fifos fifo {} 427 lua_newtable( L); // fifos fifo {}
425 lua_setuservalue( L, -2); // fifos fifo 428 lua_setiuservalue( L, -2, CONTENTS_TABLE); // fifos fifo
426 fifo->first = 1; 429 fifo->first = 1;
427 fifo->count = 0; 430 fifo->count = 0;
428 } 431 }
@@ -450,7 +453,7 @@ int keepercall_set( lua_State* L)
450 should_wake_writers = (fifo->limit > 0) && (fifo->count >= fifo->limit) && (count < fifo->limit); 453 should_wake_writers = (fifo->limit > 0) && (fifo->count >= fifo->limit) && (count < fifo->limit);
451 // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged! 454 // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged!
452 lua_newtable( L); // fifos key [val [, ...]] fifo {} 455 lua_newtable( L); // fifos key [val [, ...]] fifo {}
453 lua_setuservalue( L, -2); // fifos key [val [, ...]] fifo 456 lua_setiuservalue( L, -2, CONTENTS_TABLE); // fifos key [val [, ...]] fifo
454 fifo->first = 1; 457 fifo->first = 1;
455 fifo->count = 0; 458 fifo->count = 0;
456 } 459 }