Annotation of parser3/src/main/pa_code_cache.C, revision 1.1
1.1 ! moko 1: /** @file
! 2: Parser: compiled code cache.
! 3:
! 4: Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com)
! 5: Authors: Konstantin Morshnev <moko@design.ru>
! 6: */
! 7:
! 8: #include "pa_code_cache.h"
! 9:
! 10: volatile const char * IDENT_PA_CODE_CACHE_C="$Id$" IDENT_PA_CODE_CACHE_H;
! 11:
! 12: #ifdef CODE_CACHE
! 13:
! 14: Code_cache::Code_cache(const String& afile_spec): file_spec(afile_spec), file_no(0), fsize(0), fmtime(0) {
! 15: time_t atime, ctime;
! 16: file_stat(file_spec, fsize, atime, fmtime, ctime, false);
! 17: }
! 18:
! 19: void Code_cache::add(Kind kind, const String* name, Method* method) {
! 20: Action action={kind, name, method, Operation::Origin::create(0, 0, 0)};
! 21: actions+=action;
! 22: }
! 23:
! 24: void Code_cache::add_use(const String* name, Operation::Origin origin) {
! 25: Action action={USE, name, 0, origin};
! 26: actions+=action;
! 27: }
! 28:
! 29: bool Code_cache::unchanged() {
! 30: uint64_t size;
! 31: time_t atime, mtime, ctime;
! 32: return file_stat(file_spec, size, atime, mtime, ctime, false) && size==fsize && mtime==fmtime;
! 33: }
! 34:
! 35: // filled while the httpd config runs, only read in the subsequent requests
! 36: static HashString<Code_cache*>* code_cache=0;
! 37: // file_list of the config run
! 38: static Array<String::Body>* code_cache_files=0;
! 39:
! 40: static bool code_cache_recording=false;
! 41: static bool code_cache_enabled=true;
! 42:
! 43: void Code_cache_manager::start() {
! 44: code_cache=new HashString<Code_cache*>;
! 45: code_cache_recording=true;
! 46: }
! 47:
! 48: void Code_cache_manager::finish(Request& r) {
! 49: code_cache_recording=false;
! 50: if(code_cache_enabled) {
! 51: code_cache_files=new Array<String::Body>;
! 52: code_cache_files->append(r.file_list);
! 53: } else
! 54: code_cache=0;
! 55: }
! 56:
! 57: void Code_cache_manager::set_enabled(bool aenabled) {
! 58: if(code_cache_recording)
! 59: code_cache_enabled=aenabled;
! 60: }
! 61:
! 62: void Code_cache_manager::add_files(Array<String::Body>& file_list) {
! 63: if(code_cache_files) // the request has only the pseudo files yet, the same as in the config run
! 64: file_list.append(*code_cache_files, file_list.count());
! 65: }
! 66:
! 67: Code_cache* Code_cache_manager::get(const String& file_spec) {
! 68: if(code_cache && !code_cache_recording)
! 69: if(Code_cache* code=code_cache->get(file_spec))
! 70: if(code->unchanged())
! 71: return code;
! 72: return 0;
! 73: }
! 74:
! 75: Code_cache* Code_cache_manager::create(const String& file_spec) {
! 76: // size and time are taken before reading
! 77: return code_cache_recording ? new Code_cache(file_spec) : 0;
! 78: }
! 79:
! 80: void Code_cache_manager::put(Code_cache& code) {
! 81: code_cache->put(code.file_spec, &code);
! 82: }
! 83:
! 84: #endif
E-mail: