Mercurial > urweb
changeset 2298:6e580e319077
Fix condition for installing new cache entries
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Thu, 19 Nov 2015 16:02:04 -0500 (2015-11-19) |
parents | 6d56080f495c |
children | 47d5c94aeeb8 |
files | src/c/urweb.c src/lru_cache.sml tests/fib.ur |
diffstat | 3 files changed, 34 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/c/urweb.c Thu Nov 19 13:18:58 2015 -0500 +++ b/src/c/urweb.c Thu Nov 19 16:02:04 2015 -0500 @@ -504,8 +504,8 @@ size_t output_buffer_size; // Sqlcache. - int numRecording; - int recordingOffset; + int numRecording, recordingCapacity; + int *recordingOffsets; uw_Sqlcache_Update *cacheUpdate; uw_Sqlcache_Update *cacheUpdateTail; uw_Sqlcache_Unlock *cacheUnlock; @@ -596,7 +596,8 @@ ctx->output_buffer_size = 1; ctx->numRecording = 0; - ctx->recordingOffset = 0; + ctx->recordingCapacity = 0; + ctx->recordingOffsets = malloc(0); ctx->cacheUpdate = NULL; ctx->cacheUpdateTail = NULL; @@ -669,6 +670,8 @@ free(ctx->output_buffer); + free(ctx->recordingOffsets); + free(ctx); } @@ -692,6 +695,7 @@ ctx->usedSig = 0; ctx->needsResig = 0; ctx->remoteSock = -1; + ctx->numRecording = 0; } void uw_reset_keep_request(uw_context ctx) { @@ -1739,17 +1743,16 @@ } void uw_recordingStart(uw_context ctx) { - if (ctx->numRecording++ == 0) { - ctx->recordingOffset = ctx->page.front - ctx->page.start; + if (ctx->numRecording == ctx->recordingCapacity) { + ++ctx->recordingCapacity; + ctx->recordingOffsets = realloc(ctx->recordingOffsets, sizeof(int) * ctx->recordingCapacity); } + ctx->recordingOffsets[ctx->numRecording] = ctx->page.front - ctx->page.start; + ++ctx->numRecording; } char *uw_recordingRead(uw_context ctx) { - // Only the outermost recorder can read unless the recording is empty. - char *recording = ctx->page.start + ctx->recordingOffset; - if (--ctx->numRecording > 0 && recording != ctx->page.front) { - return NULL; - } + char *recording = ctx->page.start + ctx->recordingOffsets[--ctx->numRecording]; return strdup(recording); } @@ -4709,6 +4712,7 @@ while (numKeys-- > 0) { buf = uw_Sqlcache_keyCopy(buf, keys[numKeys]); size_t len = buf - key; + entry = uw_Sqlcache_find(cache, key, len, 1); if (!entry) { entry = calloc(1, sizeof(uw_Sqlcache_Entry)); @@ -4720,7 +4724,7 @@ } free(key); } - if (entry->value && entry->value->timeValid < value->timeValid) { + if (!entry->value || entry->value->timeValid < value->timeValid) { uw_Sqlcache_freeValue(entry->value); entry->value = value; entry->value->timeValid = timeNow;
--- a/src/lru_cache.sml Thu Nov 19 13:18:58 2015 -0500 +++ b/src/lru_cache.sml Thu Nov 19 16:02:04 2015 -0500 @@ -65,6 +65,7 @@ val revArgs = paramRepeatRev (fn p => "p" ^ p) ", " + val argNums = List.tabulate (params, fn i => "p" ^ Int.toString i) in Print.box [string ("static uw_Sqlcache_Cache cacheStruct" ^ i ^ " = {"), @@ -119,7 +120,12 @@ newline, string " } else {", newline, - (*string (" puts(\"SQLCACHE: miss " ^ i ^ ".\");"), + (*string (" printf(\"SQLCACHE: miss " ^ i ^ " " ^ String.concatWith ", " (List.tabulate (params, fn _ => "%s")) ^ ".\\n\""), + (case argNums of + [] => Print.box [] + | _ => Print.box [string ", ", + p_list string argNums]), + string ");", newline,*) string " uw_recordingStart(ctx);", newline, @@ -159,6 +165,8 @@ newline, string (" uw_Sqlcache_flush(ctx, cache" ^ i ^ ", ks);"), newline, + (*string (" puts(\"SQLCACHE: flushed " ^ i ^ ".\");"), + newline,*) string " return uw_unit_v;", newline, string "}",