summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2015-11-19 16:02:04 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2015-11-19 16:02:04 -0500
commit027ffcf5b2e3f71a42857547b17b0824d38a3f85 (patch)
tree326754f0948b772e98dec6eaea1915888f481412 /src
parent30dd885d1fc3013be0e3c2a45b2e0117f684f40a (diff)
Fix condition for installing new cache entries
Diffstat (limited to 'src')
-rw-r--r--src/c/urweb.c26
-rw-r--r--src/lru_cache.sml10
2 files changed, 24 insertions, 12 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 093a5294..54135666 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -504,8 +504,8 @@ struct uw_context {
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 @@ uw_context uw_init(int id, uw_loggers *lg) {
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 @@ void uw_free(uw_context ctx) {
free(ctx->output_buffer);
+ free(ctx->recordingOffsets);
+
free(ctx);
}
@@ -692,6 +695,7 @@ void uw_reset_keep_error_message(uw_context ctx) {
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_write(uw_context ctx, const char* s) {
}
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 @@ static void uw_Sqlcache_storeCommitOne(uw_Sqlcache_Cache *cache, char **keys, uw
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 @@ static void uw_Sqlcache_storeCommitOne(uw_Sqlcache_Cache *cache, char **keys, uw
}
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;
diff --git a/src/lru_cache.sml b/src/lru_cache.sml
index 851b4ccb..81000458 100644
--- a/src/lru_cache.sml
+++ b/src/lru_cache.sml
@@ -65,6 +65,7 @@ fun setupQuery {index, params} =
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 @@ fun setupQuery {index, params} =
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 @@ fun setupQuery {index, params} =
newline,
string (" uw_Sqlcache_flush(ctx, cache" ^ i ^ ", ks);"),
newline,
+ (*string (" puts(\"SQLCACHE: flushed " ^ i ^ ".\");"),
+ newline,*)
string " return uw_unit_v;",
newline,
string "}",