Commit 4e1b1cb8 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(sync_part): Use ldifftime() instead of difftime().

(pre_sync): Destruct cache_nodes for deleted conferences, persons and
	texts (thus making exists_b obsolete).
(throwable_p): Non-existing nodes are throwable even if they are dirty.
(limit_conf, limit_pers, limit_text_stat): Throw all throwable
	objects, not just the first throwable object.
(save_one_conf, save_one_pers, save_one_text): The fact that the
	node exists can be used instead of the exists_b flag.
parent 4cdf6925
/*
* $Id: simple-cache.c,v 0.44 1994/02/20 16:18:42 ceder Exp $
* $Id: simple-cache.c,v 0.45 1994/04/04 15:29:18 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -33,7 +33,7 @@
* New save algorithm by ceder.
*/
static char *rcsid = "$Id: simple-cache.c,v 0.44 1994/02/20 16:18:42 ceder Exp $";
static char *rcsid = "$Id: simple-cache.c,v 0.45 1994/04/04 15:29:18 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -51,14 +51,12 @@ USE(rcsid);
# define SEEK_END 2
#endif
#include <time.h>
#ifndef HAVE_DIFFTIME
# include "tmp-difftime.h"
#endif
#include <setjmp.h>
#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif
#include "ldifftime.h"
#include "exp.h"
#include "misc-types.h"
#include "s-string.h"
......@@ -1315,11 +1313,17 @@ pre_sync(void)
{
node = get_conf_node(i);
if ( node != NULL )
{
node->s.exists_b = node->s.exists;
if ( node == NULL )
continue;
if ( node->s.dirty != 0 && node->s.exists != 0)
if (node->s.exists == 0)
{
unlink_conf_lru(node);
destruct_cache_node(conf_mcb, i);
}
else
{
if (node->s.dirty != 0)
{
free_conference(node->snap_shot);
......@@ -1330,10 +1334,8 @@ pre_sync(void)
node->ptr = NULL;
}
else
{
node->snap_shot = copy_conference(node->ptr);
}
node->s.dirty = 0;
}
}
......@@ -1343,11 +1345,17 @@ pre_sync(void)
{
node = get_pers_node(i);
if ( node != NULL )
{
node->s.exists_b = node->s.exists;
if ( node == NULL )
continue;
if ( node->s.dirty != 0 && node->s.exists != 0)
if (node->s.exists == 0)
{
unlink_pers_lru(node);
destruct_cache_node(pers_mcb, i);
}
else
{
if (node->s.dirty != 0)
{
free_person(node->snap_shot);
......@@ -1358,10 +1366,7 @@ pre_sync(void)
node->ptr = NULL;
}
else
{
node->snap_shot
= copy_person(node->ptr);
}
node->snap_shot = copy_person(node->ptr);
node->s.dirty = 0;
}
......@@ -1372,11 +1377,17 @@ pre_sync(void)
{
node = get_text_node(i);
if ( node != NULL )
{
node->s.exists_b = node->s.exists;
if ( node == NULL )
continue;
if ( node->s.dirty != 0 && node->s.exists != 0)
if (node->s.exists == 0)
{
unlink_text_lru(node);
destruct_cache_node(text_mcb, i);
}
else
{
if (node->s.dirty != 0)
{
free_text_stat(node->snap_shot);
......@@ -1387,10 +1398,7 @@ pre_sync(void)
node->ptr = NULL;
}
else
{
node->snap_shot
= copy_text_stat(node->ptr);
}
node->snap_shot = copy_text_stat(node->ptr);
node->s.dirty = 0;
}
......@@ -1494,9 +1502,7 @@ save_one_conf(void)
{
cn->pos_b = ftell(file_b);
if ( cn->s.exists_b == 0 )
putc('@', file_b);
else if ( cn->snap_shot != NULL )
if ( cn->snap_shot != NULL )
{
fprintf(file_b, "+ ");
foutput_conference(file_b, cn->snap_shot);
......@@ -1550,9 +1556,7 @@ save_one_pers(void)
{
cn->pos_b = ftell(file_b);
if ( cn->s.exists_b == 0 )
putc('@', file_b);
else if ( cn->snap_shot != NULL )
if ( cn->snap_shot != NULL )
{
write_pers(file_b, cn->snap_shot);
}
......@@ -1608,7 +1612,6 @@ post_sync(void)
node->size = node->size_b;
free_conference(node->snap_shot);
node->snap_shot = NULL;
/* +++ Delete if it no longer exists. */
}
}
......@@ -1621,7 +1624,6 @@ post_sync(void)
node->size = node->size_b;
free_person(node->snap_shot);
node->snap_shot = NULL;
/* +++ Delete if it no longer exists. */
}
}
......@@ -1634,7 +1636,6 @@ post_sync(void)
node->size = node->size_b;
free_text_stat(node->snap_shot);
node->snap_shot = NULL;
/* +++ Delete if it no longer exists. */
}
}
}
......@@ -1664,9 +1665,7 @@ save_one_text(void)
{
cn->pos_b = ftell(file_b);
if ( cn->s.exists_b == 0 )
putc('@', file_b);
else if ( cn->snap_shot != NULL )
if ( cn->snap_shot != NULL )
{
fprintf(file_b, "+ ");
foutput_text_stat(file_b, cn->snap_shot);
......@@ -1677,9 +1676,7 @@ save_one_text(void)
foutput_text_stat(file_b, cn->ptr);
}
else
{
copy_file(file_a, file_b, cn->pos, cn->size - 1);
}
putc('\n', file_b);
cn->size_b = ftell(file_b) - cn->pos_b;
......@@ -1829,7 +1826,7 @@ sync_part(void)
return TRUE;
case sync_idle:
if ( difftime(time(NULL), last_sync_start) < 60 * param.sync_interval )
if (ldifftime(time(NULL), last_sync_start) < 60 * param.sync_interval)
{
#ifdef LOGACCESSES
syncing_or_saving = 0;
......@@ -1843,7 +1840,7 @@ sync_part(void)
break;
case sync_wait:
if (difftime(time(NULL), last_sync_start)
if (ldifftime(time(NULL), last_sync_start)
< 60*param.sync_retry_interval)
{
#ifdef LOGACCESSES
......@@ -2160,7 +2157,7 @@ free_all_cache (void)
static Bool
throwable_p(Cache_node *node)
{
return (node->s.dirty == 0
return ((node->s.dirty == 0 || node->s.exists == 0)
&& node->snap_shot == NULL
&& node->lock_cnt == 0);
}
......@@ -2169,6 +2166,7 @@ static void
limit_pers(void)
{
Cache_node *node;
Cache_node *next_node;
int i;
node = pers_mcb->mru;
......@@ -2186,15 +2184,16 @@ limit_pers(void)
/* Delete any remaining clean persons */
while ( node != NULL )
{
next_node = node->next;
if (throwable_p(node))
{
unlink_pers_lru(node);
free_person (node->ptr);
node->ptr = NULL;
/* +++ delete cache-node if non-existent. */
}
node = node->next;
node = next_node;
}
}
......@@ -2202,6 +2201,7 @@ static void
limit_conf(void)
{
Cache_node *node;
Cache_node *next_node;
int i;
node = conf_mcb->mru;
......@@ -2219,6 +2219,7 @@ limit_conf(void)
/* Delete any remaining clean confs. */
while ( node != NULL )
{
next_node = node->next;
if (throwable_p(node))
{
unlink_conf_lru(node);
......@@ -2226,8 +2227,7 @@ limit_conf(void)
node->ptr = NULL;
/* +++ delete if non-existent. */
}
node = node->next;
node = next_node;
}
}
......@@ -2236,6 +2236,7 @@ static void
limit_text_stat(void)
{
Cache_node *node;
Cache_node *next_node;
int i;
node = text_mcb->mru;
......@@ -2253,6 +2254,7 @@ limit_text_stat(void)
/* Delete any remaining clean text_stats. */
while ( node != NULL )
{
next_node = node->next;
if (throwable_p(node))
{
unlink_text_lru(node);
......@@ -2260,8 +2262,7 @@ limit_text_stat(void)
node->ptr = NULL;
/* +++ delete if non-existent. */
}
node = node->next;
node = next_node;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment