|
|
1.1 root 1: #ifndef _JS_CACHE_H_
2: #define _JS_CACHE_H_
3:
4: #include "link_list.h"
5: #include "jscntxt.h"
6: #include "jsscript.h"
7:
8: /* JS Compile Cache Stuff */
9: struct context_cache {
10: JSContext *cx;
11: link_list_t cache;
12: };
13:
14: struct cache_data {
15: char filename[MAX_PATH+1];
16: time_t mtime,ctime; /* st_mtime/st_ctime from last stat() call */
17: off_t size; /* File size when loaded */
18: ulong runcount; /* Number of times this script has been used */
19: time_t lastrun; /* Time script was last ran */
20: time_t laststat; /* Time of last call to stat() */
21: JSScript *script;
22: int running; /* Count of currently running scripts */
23: int expired; /* TRUE if last stat() makes this as stale and
24: * running was non-zero */
25: };
26:
27: typedef struct {
28: DWORD size; /* sizeof(js_cache_startup_t) */
29: time_t max_age; /* Max age in seconds for lastrun */
30: ulong max_scripts; /* Max number of scripts to hold in cache */
31: time_t stale_timeout; /* Minimum time between calls to stat() */
32: ulong expire_period; /* Time between servicing the exipry cache... milliseconds */
33: } js_cache_startup_t;
34:
35: #ifdef __cplusplus
36: extern "C" {
37: #endif
38:
39: /*
40: * Gets the compiled script from the cache if available and
41: * laststat is less than stale time or a new stat() matches
42: * the mtime, ctime, and size.
43: * Compiles it and adds to the cache if not.
44: * Increments running value.
45: */
46: JSScript *js_get_compiled_script(JSContext *cx, char *filename);
47:
48: /*
49: * Starts the caching thread. The caching thread periodically
50: * checks the caches for entries to be expired. They are expired
51: * by weigth where weight=(age in seconds)/(number of times ran)
52: * does NOT check the laststat nor does it do a stat().
53: * It also does not expire an entry for which running is non-zero.
54: */
55: void js_cache_thread(void *args);
56:
57: /*
58: * Decrements the running value, increments runcount, and updates
59: * lastrun
60: */
61: void js_script_done(struct cached_data *entry);
62:
63: /*
64: * Sets the expired member for any existing cached copies of filename
65: * Required for self-modifying scripts.
66: */
67: void js_cache_expire(char *filename);
68:
69: /*
70: * Creates a new cached runtime and context
71: */
72: JSContext *js_get_cached_context(size_t maxbytes, size_t stacksize);
73: #ifdef __cplusplus
74: }
75: #endif
76:
77: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.