Panda3D
configVariableFilename.cxx
1 // Filename: configVariableFilename.cxx
2 // Created by: drose (22Nov04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "configVariableFilename.h"
16 #include "executionEnvironment.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: ConfigVariableFilename::reload_cache
20 // Access: Private
21 // Description: Recopies the config variable into the Filename for
22 // returning its value.
23 ////////////////////////////////////////////////////////////////////
24 void ConfigVariableFilename::
25 reload_cache() {
26  // NB. MSVC doesn't guarantee that this mutex is initialized in a
27  // thread-safe manner. But chances are that the first time this is called
28  // is at static init time, when there is no risk of data races.
29  static MutexImpl lock;
30  lock.acquire();
31 
32  // We check again for cache validity since another thread may have beaten
33  // us to the punch while we were waiting for the lock.
34  if (!is_cache_valid(_local_modified)) {
35  nassertv(_core != (ConfigVariableCore *)NULL);
36 
37  const ConfigDeclaration *decl = _core->get_declaration(0);
38  const ConfigPage *page = decl->get_page();
39 
40  Filename page_filename(page->get_name());
41  Filename page_dirname = page_filename.get_dirname();
42  ExecutionEnvironment::shadow_environment_variable("THIS_PRC_DIR", page_dirname.to_os_specific());
43 
44  _cache = Filename::expand_from(decl->get_string_value());
45  ExecutionEnvironment::clear_shadow("THIS_PRC_DIR");
46 
47  mark_cache_valid(_local_modified);
48  }
49  lock.release();
50 }
string get_dirname() const
Returns the directory part of the filename.
Definition: filename.I:424
The internal definition of a ConfigVariable.
static Filename expand_from(const string &user_string, Type type=T_general)
Returns the same thing as from_os_specific(), but embedded environment variable references (e...
Definition: filename.cxx:418
const string & get_name() const
Returns the name of the page.
Definition: configPage.I:44
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
ConfigPage * get_page() const
Returns the page on which this declaration can be found.
A page of ConfigDeclarations that may be loaded or unloaded.
Definition: configPage.h:33
static void clear_shadow(const string &var)
Removes a value set by a previous call to shadow_environment_variable(), and lets the actual value of...
A fake mutex implementation for single-threaded applications that don't need any synchronization cont...
A single declaration of a config variable, typically defined as one line in a .prc file...
static void shadow_environment_variable(const string &var, const string &value)
Changes the apparent definition of the indicated environment variable by masking it within this class...
const string & get_string_value() const
Returns the value assigned to this variable.