diff options
| author | Behdad Esfahbod <behdad@behdad.org> | 2008-08-22 18:08:07 -0400 |
|---|---|---|
| committer | Behdad Esfahbod <behdad@behdad.org> | 2009-02-13 16:53:59 -0800 |
| commit | 241fbde1ab28d7beb9b861d8804d0416f0d5589c (patch) | |
| tree | 32405b222c99ada793a631e3c40b0174740d81f4 | |
| parent | 03dcaaa08fe324a058c427ab2da993fddaa7b3fd (diff) | |
Add FcConfigReference() (#17124)
| -rw-r--r-- | doc/fcconfig.fncs | 20 | ||||
| -rw-r--r-- | fontconfig/fontconfig.h | 3 | ||||
| -rw-r--r-- | src/fccfg.c | 20 | ||||
| -rw-r--r-- | src/fcint.h | 2 |
4 files changed, 42 insertions, 3 deletions
diff --git a/doc/fcconfig.fncs b/doc/fcconfig.fncs index 16d1000b..3ceab921 100644 --- a/doc/fcconfig.fncs +++ b/doc/fcconfig.fncs @@ -29,14 +29,28 @@ 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 @FUNC@ FcConfigDestroy @TYPE1@ FcConfig * @ARG1@ config @PURPOSE@ Destroy a configuration @DESC@ -Destroys a configuration and any data associated with it. Note that calling -this function with the return from FcConfigGetCurrent will place the library -in an indeterminate state. +Decrements the config reference count. If all references are gone, destroys +the configuration and any data associated with it. +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 diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h index 55e1763b..41490728 100644 --- a/fontconfig/fontconfig.h +++ b/fontconfig/fontconfig.h @@ -342,6 +342,9 @@ FcConfigFilename (const FcChar8 *url); FcPublic FcConfig * FcConfigCreate (void); +FcPublic FcConfig * +FcConfigReference (FcConfig *config); + FcPublic void FcConfigDestroy (FcConfig *config); diff --git a/src/fccfg.c b/src/fccfg.c index 85ad0f51..70748c86 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -92,6 +92,8 @@ FcConfigCreate (void) config->rescanTime = time(0); config->rescanInterval = 30; + + config->ref = 1; return config; @@ -191,11 +193,29 @@ FcSubstDestroy (FcSubst *s) } } +FcConfig * +FcConfigReference (FcConfig *config) +{ + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + + config->ref++; + + return config; +} + void FcConfigDestroy (FcConfig *config) { FcSetName set; + if (--config->ref > 0) + return; + if (config == _fcConfig) _fcConfig = 0; diff --git a/src/fcint.h b/src/fcint.h index 5798702b..370dd7e8 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -483,6 +483,8 @@ struct _FcConfig { */ time_t rescanTime; /* last time information was scanned */ int rescanInterval; /* interval between scans */ + + int ref; /* reference count */ }; extern FcPrivate FcConfig *_fcConfig; |
