disk-end-of-atomic.c 2.22 KB
Newer Older
Linus Tolke Y's avatar
Linus Tolke Y committed
1
/*
2
 * $Id: disk-end-of-atomic.c,v 0.15 1998/07/08 13:41:44 ceder Exp $
Per Cederqvist's avatar
Per Cederqvist committed
3
 * Copyright (C) 1991, 1992, 1993, 1994  Lysator Academic Computer Association.
Linus Tolke Y's avatar
Linus Tolke Y committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * This file is part of the LysKOM server.
 * 
 * LysKOM is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 1, or (at your option) 
 * any later version.
 * 
 * LysKOM is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with LysKOM; see the file COPYING.  If not, write to
 * Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
 * or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 * MA 02139, USA.
 *
 * Please mail bug reports to bug-lyskom@lysator.liu.se. 
 */
Per Cederqvist's avatar
Per Cederqvist committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38
/*
 * end-of-atomic.c
 *
 * This is the magic function which is called at the end of every atomic
 * call to the server. It is responisble for
 *	Free:ing all tmp_alloc:ated memory
 *	Throw out some cached data if necessary
 *	Forget some old texts if necessary
 *	Save some items to disk if saving
 *
 * idle is TRUE if the server has no pending calls. That might be a good time
 * to forget old texts.
 */

39 40
static const char *
rcsid = "$Id: disk-end-of-atomic.c,v 0.15 1998/07/08 13:41:44 ceder Exp $";
41 42
#include "rcs.h"
USE(rcsid);
Per Cederqvist's avatar
Per Cederqvist committed
43

Per Cederqvist's avatar
Per Cederqvist committed
44 45 46
#ifdef HAVE_STDDEF_H
#  include <stddef.h>
#endif
Per Cederqvist's avatar
Per Cederqvist committed
47
#include <sys/types.h>
Per Cederqvist's avatar
Per Cederqvist committed
48

Per Cederqvist's avatar
Per Cederqvist committed
49
#include "misc-types.h"
50
#include "s-string.h"
Per Cederqvist's avatar
Per Cederqvist committed
51 52 53 54
#include "kom-types.h"
#include "end-of-atomic.h"
#include "cache.h"
#include "server/smalloc.h"
Per Cederqvist's avatar
Per Cederqvist committed
55
#include "config.h"
Per Cederqvist's avatar
Per Cederqvist committed
56
#include "text-garb.h"
Per Cederqvist's avatar
Per Cederqvist committed
57
#include "disk-cache.h"
58
#include "param.h"
Per Cederqvist's avatar
Per Cederqvist committed
59 60 61 62

long
end_of_atomic( Bool  idle )
{
63
    int timeout = param.timeout;
64
    static int limit = 0;
Per Cederqvist's avatar
Per Cederqvist committed
65 66

    free_tmp();
67 68 69 70 71 72 73

    /* FIXME-- make limit_text_stat smarter instead. */
    if (limit++ > 100)
    {
	cache_limit_size();
	limit = 0;
    }
Per Cederqvist's avatar
Per Cederqvist committed
74 75 76

    if ( idle )
	if ( garb_text() == FALSE )
77
	    timeout = param.garbtimeout;
Per Cederqvist's avatar
Per Cederqvist committed
78 79

    if ( sync_part() == FALSE )
80
	timeout = param.synctimeout;
Per Cederqvist's avatar
Per Cederqvist committed
81 82 83

    return timeout;
}