~ubuntu-branches/ubuntu/utopic/tinymux/utopic

« back to all changes in this revision

Viewing changes to src/attrcache.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ervin Hearn III
  • Date: 2008-04-11 23:18:25 UTC
  • mfrom: (1.1.5 upstream) (6.1.1 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080411231825-1pq4trckagyk8roo
Tags: 2.6.5.27-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// svdocache.cpp -- Attribute caching module.
2
 
//
3
 
// $Id: attrcache.cpp,v 1.21 2006/01/07 06:26:07 sdennis Exp $
4
 
//
5
 
// MUX 2.4
6
 
// Copyright (C) 1998 through 2004 Solid Vertical Domains, Ltd. All
7
 
// rights not explicitly given are reserved.
8
 
//
 
1
/*! \file attrcache.cpp
 
2
 *  Attribute caching module.
 
3
 *
 
4
 * $Id: attrcache.cpp 3049 2007-12-30 06:35:41Z brazilofmux $
 
5
 *
 
6
 * The functions here manage the upper-level attribute value cache for
 
7
 * disk-based mode. It's not used in memory-based builds. The lower-level
 
8
 * cache is managed in svdhash.cpp
 
9
 *
 
10
 * The upper-level cache is organized by a CHashTable and a linked list. The
 
11
 * former allows random access while the linked list helps find the
 
12
 * least-recently-used attribute.
 
13
 */
 
14
 
9
15
#include "copyright.h"
10
16
#include "autoconf.h"
11
17
#include "config.h"
12
18
#include "externs.h"
13
19
 
 
20
#if !defined(MEMORY_BASED)
 
21
 
14
22
static CHashFile hfAttributeFile;
15
23
static bool cache_initted = false;
16
24
 
35
43
    struct tagCacheEntryHeader *pPrevEntry;
36
44
    struct tagCacheEntryHeader *pNextEntry;
37
45
    Aname attrKey;
38
 
    unsigned int nSize;
 
46
    size_t nSize;
39
47
} CENT_HDR, *PCENT_HDR;
40
48
 
41
49
static PCENT_HDR pCacheHead = 0;
42
50
static PCENT_HDR pCacheTail = 0;
43
 
static unsigned int CacheSize = 0;
 
51
static size_t CacheSize = 0;
44
52
 
45
53
int cache_init(const char *game_dir_file, const char *game_pag_file,
46
54
    int nCachePages)
66
74
    for (int i = 0; i < N_TEMP_FILES; i++)
67
75
    {
68
76
        char TempFileName[20];
69
 
        sprintf(TempFileName, "$convtemp.%d", i);
70
 
        TempFiles[i] = fopen(TempFileName, "wb+");
 
77
        mux_sprintf(TempFileName, sizeof(TempFileName), "$convtemp.%d", i);
 
78
        mux_assert(mux_fopen(&TempFiles[i], TempFileName, "wb+"));
71
79
        mux_assert(TempFiles[i]);
72
80
        setvbuf(TempFiles[i], NULL, _IOFBF, 16384);
73
81
    }
106
114
        }
107
115
        fclose(TempFiles[i]);
108
116
        char TempFileName[20];
109
 
        sprintf(TempFileName, "$convtemp.%d", i);
 
117
        mux_sprintf(TempFileName, sizeof(TempFileName), "$convtemp.%d", i);
110
118
        RemoveFile(TempFileName);
111
119
        fprintf(stderr, ENDLINE);
112
120
    }
113
121
}
114
122
 
 
123
void cache_cleanup(void)
 
124
{
 
125
    for (int i = 0; i < N_TEMP_FILES; i++)
 
126
    {
 
127
        fclose(TempFiles[i]);
 
128
        char TempFileName[20];
 
129
        mux_sprintf(TempFileName, sizeof(TempFileName), "$convtemp.%d", i);
 
130
        RemoveFile(TempFileName);
 
131
    }
 
132
}
 
133
 
115
134
void cache_close(void)
116
135
{
117
136
    hfAttributeFile.CloseAll();
218
237
    }
219
238
}
220
239
 
221
 
const char *cache_get(Aname *nam, int *pLen)
 
240
const char *cache_get(Aname *nam, size_t *pLen)
222
241
{
223
242
    if (  nam == (Aname *) 0
224
243
       || !cache_initted)
255
274
    }
256
275
 
257
276
    UINT32 nHash = CRC32_ProcessInteger2(nam->object, nam->attrnum);
 
277
    UINT32 iDir = hfAttributeFile.FindFirstKey(nHash);
258
278
 
259
 
    HP_DIRINDEX iDir;
260
 
    iDir = hfAttributeFile.FindFirstKey(nHash);
261
279
    while (iDir != HF_FIND_END)
262
280
    {
263
281
        HP_HEAPLENGTH nRecord;
358
376
        return true;
359
377
    }
360
378
 
361
 
    HP_DIRINDEX iDir = hfAttributeFile.FindFirstKey(nHash);
 
379
    UINT32 iDir = hfAttributeFile.FindFirstKey(nHash);
362
380
    while (iDir != HF_FIND_END)
363
381
    {
364
382
        HP_HEAPLENGTH nRecord;
447
465
#endif
448
466
 
449
467
    UINT32 nHash = CRC32_ProcessInteger2(nam->object, nam->attrnum);
 
468
    UINT32 iDir = hfAttributeFile.FindFirstKey(nHash);
450
469
 
451
 
    HP_DIRINDEX iDir = hfAttributeFile.FindFirstKey(nHash);
452
470
    while (iDir != HF_FIND_END)
453
471
    {
454
472
        HP_HEAPLENGTH nRecord;
480
498
        }
481
499
    }
482
500
}
 
501
 
 
502
#endif // MEMORY_BASED