~ubuntu-branches/ubuntu/trusty/postfix/trusty

« back to all changes in this revision

Viewing changes to src/util/ctable.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones, LaMont Jones, localization folks
  • Date: 2014-02-11 07:44:30 UTC
  • mfrom: (58.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140211074430-kwkoxdz0fbajn0fj
Tags: 2.11.0-1
[LaMont Jones]

* New upstream release: 2.11.0

[localization folks]

* l10n: Updated German translations.  Closes: #734893 (Helge Kreutzmann)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
/*      CTABLE  *cache;
17
17
/*      const char *key;
18
18
/*
 
19
/*      const void *ctable_refresh(cache, key)
 
20
/*      CTABLE  *cache;
 
21
/*      const char *key;
 
22
/*
 
23
/*      const void *ctable_newcontext(cache, context)
 
24
/*      CTABLE  *cache;
 
25
/*      void    *context;
 
26
/*
19
27
/*      void    ctable_free(cache)
20
28
/*      CTABLE  *cache;
21
29
/*
33
41
/*      specify pointers to call-back functions that create a value, given
34
42
/*      a key, and delete a given value, respectively. The context argument
35
43
/*      is passed on to the call-back routines.
 
44
/*      The create() and delete() functions must not modify the cache.
36
45
/*
37
46
/*      ctable_locate() looks up or generates the value that corresponds to
38
47
/*      the specified key, and returns that value.
39
48
/*
 
49
/*      ctable_refresh() flushes the value (if any) associated with
 
50
/*      the specified key, and returns the same result as ctable_locate().
 
51
/*
 
52
/*      ctable_newcontext() updates the context that is passed on
 
53
/*      to call-back routines.
 
54
/*
40
55
/*      ctable_free() destroys the specified cache, including its contents.
41
56
/*
42
57
/*      ctable_walk() iterates over all elements in the cache, and invokes
43
58
/*      the action function for each cache element with the corresponding
44
59
/*      key and value as arguments. This function is useful mainly for
45
60
/*      cache performance debugging.
 
61
/*      Note: the action() function must not modify the cache.
46
62
/* DIAGNOSTICS
47
63
/*      Fatal errors: out of memory. Panic: interface violation.
48
64
/* LICENSE
161
177
    return (entry->value);
162
178
}
163
179
 
 
180
/* ctable_refresh - page-in fresh data for given key */
 
181
 
 
182
const void *ctable_refresh(CTABLE *cache, const char *key)
 
183
{
 
184
    const char *myname = "ctable_refresh";
 
185
    CTABLE_ENTRY *entry;
 
186
 
 
187
    /* Materialize entry if missing. */
 
188
    if ((entry = (CTABLE_ENTRY *) htable_find(cache->table, key)) == 0)
 
189
        return ctable_locate(cache, key);
 
190
 
 
191
    /* Otherwise, refresh its content. */
 
192
    cache->delete(entry->value, cache->context);
 
193
    entry->value = cache->create(key, cache->context);
 
194
 
 
195
    /* Update its MRU linkage. */
 
196
    if (entry != RING_TO_CTABLE_ENTRY(ring_succ(RING_PTR_OF(cache)))) {
 
197
        ring_detach(RING_PTR_OF(entry));
 
198
        ring_append(RING_PTR_OF(cache), RING_PTR_OF(entry));
 
199
    }
 
200
    if (msg_verbose)
 
201
        msg_info("%s: refresh entry key %s", myname, entry->key);
 
202
    return (entry->value);
 
203
}
 
204
 
 
205
/* ctable_newcontext - update call-back context */
 
206
 
 
207
void    ctable_newcontext(CTABLE *cache, void *context)
 
208
{
 
209
    cache->context = context;
 
210
}
 
211
 
164
212
static CTABLE *ctable_free_cache;
165
213
 
166
214
/* ctable_free_callback - callback function */