Add FcConfigReference() (#17124)

This commit is contained in:
Behdad Esfahbod 2008-08-22 18:08:07 -04:00
parent 03dcaaa08f
commit 241fbde1ab
4 changed files with 42 additions and 3 deletions

View File

@ -29,14 +29,28 @@
Creates an empty configuration. Creates an empty configuration.
@@ @@
@RET@ FcConfig *
@FUNC@ FcConfigReference
@TYPE1@ FcConfig * @ARG1@ config
@PURPOSE@ Increment config reference count
@DESC@
Add another reference to <parameter>config</parameter>. Configs are freed only
when the reference count reaches zero.
If <parameter>config</parameter> is NULL, the current configuration is used.
In that case this function will be similar to FcConfigGetCurrent() except that
it increments the reference count before returning and the user is responsible
for destroying the configuration when not needed anymore.
@@
@RET@ void @RET@ void
@FUNC@ FcConfigDestroy @FUNC@ FcConfigDestroy
@TYPE1@ FcConfig * @ARG1@ config @TYPE1@ FcConfig * @ARG1@ config
@PURPOSE@ Destroy a configuration @PURPOSE@ Destroy a configuration
@DESC@ @DESC@
Destroys a configuration and any data associated with it. Note that calling Decrements the config reference count. If all references are gone, destroys
this function with the return from FcConfigGetCurrent will place the library the configuration and any data associated with it.
in an indeterminate state. Note that calling this function with the return from FcConfigGetCurrent will
cause a new configuration to be created for use as current configuration.
@@ @@
@RET@ FcBool @RET@ FcBool

View File

@ -342,6 +342,9 @@ FcConfigFilename (const FcChar8 *url);
FcPublic FcConfig * FcPublic FcConfig *
FcConfigCreate (void); FcConfigCreate (void);
FcPublic FcConfig *
FcConfigReference (FcConfig *config);
FcPublic void FcPublic void
FcConfigDestroy (FcConfig *config); FcConfigDestroy (FcConfig *config);

View File

@ -93,6 +93,8 @@ FcConfigCreate (void)
config->rescanTime = time(0); config->rescanTime = time(0);
config->rescanInterval = 30; config->rescanInterval = 30;
config->ref = 1;
return config; return config;
bail8: bail8:
@ -191,11 +193,29 @@ FcSubstDestroy (FcSubst *s)
} }
} }
FcConfig *
FcConfigReference (FcConfig *config)
{
if (!config)
{
config = FcConfigGetCurrent ();
if (!config)
return 0;
}
config->ref++;
return config;
}
void void
FcConfigDestroy (FcConfig *config) FcConfigDestroy (FcConfig *config)
{ {
FcSetName set; FcSetName set;
if (--config->ref > 0)
return;
if (config == _fcConfig) if (config == _fcConfig)
_fcConfig = 0; _fcConfig = 0;

View File

@ -483,6 +483,8 @@ struct _FcConfig {
*/ */
time_t rescanTime; /* last time information was scanned */ time_t rescanTime; /* last time information was scanned */
int rescanInterval; /* interval between scans */ int rescanInterval; /* interval between scans */
int ref; /* reference count */
}; };
extern FcPrivate FcConfig *_fcConfig; extern FcPrivate FcConfig *_fcConfig;