comparison src/c/urweb.c @ 2298:6e580e319077

Fix condition for installing new cache entries
author Adam Chlipala <adam@chlipala.net>
date Thu, 19 Nov 2015 16:02:04 -0500
parents 6d56080f495c
children ace43b90b388
comparison
equal deleted inserted replaced
2297:6d56080f495c 2298:6e580e319077
502 502
503 char *output_buffer; 503 char *output_buffer;
504 size_t output_buffer_size; 504 size_t output_buffer_size;
505 505
506 // Sqlcache. 506 // Sqlcache.
507 int numRecording; 507 int numRecording, recordingCapacity;
508 int recordingOffset; 508 int *recordingOffsets;
509 uw_Sqlcache_Update *cacheUpdate; 509 uw_Sqlcache_Update *cacheUpdate;
510 uw_Sqlcache_Update *cacheUpdateTail; 510 uw_Sqlcache_Update *cacheUpdateTail;
511 uw_Sqlcache_Unlock *cacheUnlock; 511 uw_Sqlcache_Unlock *cacheUnlock;
512 512
513 int remoteSock; 513 int remoteSock;
594 594
595 ctx->output_buffer = malloc(1); 595 ctx->output_buffer = malloc(1);
596 ctx->output_buffer_size = 1; 596 ctx->output_buffer_size = 1;
597 597
598 ctx->numRecording = 0; 598 ctx->numRecording = 0;
599 ctx->recordingOffset = 0; 599 ctx->recordingCapacity = 0;
600 ctx->recordingOffsets = malloc(0);
600 ctx->cacheUpdate = NULL; 601 ctx->cacheUpdate = NULL;
601 ctx->cacheUpdateTail = NULL; 602 ctx->cacheUpdateTail = NULL;
602 603
603 ctx->remoteSock = -1; 604 ctx->remoteSock = -1;
604 605
666 if (ctx->globals[i].free) 667 if (ctx->globals[i].free)
667 ctx->globals[i].free(ctx->globals[i].data); 668 ctx->globals[i].free(ctx->globals[i].data);
668 free(ctx->globals); 669 free(ctx->globals);
669 670
670 free(ctx->output_buffer); 671 free(ctx->output_buffer);
672
673 free(ctx->recordingOffsets);
671 674
672 free(ctx); 675 free(ctx);
673 } 676 }
674 677
675 void uw_reset_keep_error_message(uw_context ctx) { 678 void uw_reset_keep_error_message(uw_context ctx) {
690 ctx->nextId = 0; 693 ctx->nextId = 0;
691 ctx->amInitializing = 0; 694 ctx->amInitializing = 0;
692 ctx->usedSig = 0; 695 ctx->usedSig = 0;
693 ctx->needsResig = 0; 696 ctx->needsResig = 0;
694 ctx->remoteSock = -1; 697 ctx->remoteSock = -1;
698 ctx->numRecording = 0;
695 } 699 }
696 700
697 void uw_reset_keep_request(uw_context ctx) { 701 void uw_reset_keep_request(uw_context ctx) {
698 uw_reset_keep_error_message(ctx); 702 uw_reset_keep_error_message(ctx);
699 ctx->error_message[0] = 0; 703 ctx->error_message[0] = 0;
1737 uw_write_unsafe(ctx, s); 1741 uw_write_unsafe(ctx, s);
1738 *ctx->page.front = 0; 1742 *ctx->page.front = 0;
1739 } 1743 }
1740 1744
1741 void uw_recordingStart(uw_context ctx) { 1745 void uw_recordingStart(uw_context ctx) {
1742 if (ctx->numRecording++ == 0) { 1746 if (ctx->numRecording == ctx->recordingCapacity) {
1743 ctx->recordingOffset = ctx->page.front - ctx->page.start; 1747 ++ctx->recordingCapacity;
1744 } 1748 ctx->recordingOffsets = realloc(ctx->recordingOffsets, sizeof(int) * ctx->recordingCapacity);
1749 }
1750 ctx->recordingOffsets[ctx->numRecording] = ctx->page.front - ctx->page.start;
1751 ++ctx->numRecording;
1745 } 1752 }
1746 1753
1747 char *uw_recordingRead(uw_context ctx) { 1754 char *uw_recordingRead(uw_context ctx) {
1748 // Only the outermost recorder can read unless the recording is empty. 1755 char *recording = ctx->page.start + ctx->recordingOffsets[--ctx->numRecording];
1749 char *recording = ctx->page.start + ctx->recordingOffset;
1750 if (--ctx->numRecording > 0 && recording != ctx->page.front) {
1751 return NULL;
1752 }
1753 return strdup(recording); 1756 return strdup(recording);
1754 } 1757 }
1755 1758
1756 char *uw_Basis_attrifyInt(uw_context ctx, uw_Basis_int n) { 1759 char *uw_Basis_attrifyInt(uw_context ctx, uw_Basis_int n) {
1757 char *result; 1760 char *result;
4707 char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); 4710 char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys);
4708 char *buf = key; 4711 char *buf = key;
4709 while (numKeys-- > 0) { 4712 while (numKeys-- > 0) {
4710 buf = uw_Sqlcache_keyCopy(buf, keys[numKeys]); 4713 buf = uw_Sqlcache_keyCopy(buf, keys[numKeys]);
4711 size_t len = buf - key; 4714 size_t len = buf - key;
4715
4712 entry = uw_Sqlcache_find(cache, key, len, 1); 4716 entry = uw_Sqlcache_find(cache, key, len, 1);
4713 if (!entry) { 4717 if (!entry) {
4714 entry = calloc(1, sizeof(uw_Sqlcache_Entry)); 4718 entry = calloc(1, sizeof(uw_Sqlcache_Entry));
4715 entry->key = strdup(key); 4719 entry->key = strdup(key);
4716 entry->value = NULL; 4720 entry->value = NULL;
4718 uw_Sqlcache_add(cache, entry, len); 4722 uw_Sqlcache_add(cache, entry, len);
4719 } 4723 }
4720 } 4724 }
4721 free(key); 4725 free(key);
4722 } 4726 }
4723 if (entry->value && entry->value->timeValid < value->timeValid) { 4727 if (!entry->value || entry->value->timeValid < value->timeValid) {
4724 uw_Sqlcache_freeValue(entry->value); 4728 uw_Sqlcache_freeValue(entry->value);
4725 entry->value = value; 4729 entry->value = value;
4726 entry->value->timeValid = timeNow; 4730 entry->value->timeValid = timeNow;
4727 } 4731 }
4728 pthread_rwlock_unlock(&cache->lockIn); 4732 pthread_rwlock_unlock(&cache->lockIn);