aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpgme.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <[email protected]>2009-06-16 14:43:38 +0000
committerMarcus Brinkmann <[email protected]>2009-06-16 14:43:38 +0000
commit3320cc1742b541e9878dec1f6949f04811292cd3 (patch)
tree273fc30aff84eac8b611f9a70ce72456143dcc15 /src/gpgme.c
parentAdd new functions to import and export keys specified by gpgme_key_t. (diff)
downloadgpgme-3320cc1742b541e9878dec1f6949f04811292cd3.tar.gz
gpgme-3320cc1742b541e9878dec1f6949f04811292cd3.zip
doc/
2009-06-16 Marcus Brinkmann <[email protected]> * gpgme.texi (Result Management): New section. src/ 2009-06-16 Marcus Brinkmann <[email protected]> * gpgme.c (result_ref_lock): New global variable. (gpgme_result_ref, gpgme_result_unref): use it.
Diffstat (limited to 'src/gpgme.c')
-rw-r--r--src/gpgme.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/gpgme.c b/src/gpgme.c
index 2372a06a..73788e7e 100644
--- a/src/gpgme.c
+++ b/src/gpgme.c
@@ -45,6 +45,10 @@ static char *def_lc_messages;
gpgme_error_t _gpgme_selftest = GPG_ERR_NOT_OPERATIONAL;
+/* Protects all reference counters in result structures. All other
+ accesses to a key are read only. */
+DEFINE_STATIC_LOCK (result_ref_lock);
+
/* Create a new context as an environment for GPGME crypto
operations. */
@@ -178,29 +182,39 @@ gpgme_release (gpgme_ctx_t ctx)
void
gpgme_result_ref (void *result)
{
- struct ctx_op_data *data = result - sizeof (struct ctx_op_data);
+ struct ctx_op_data *data;
if (! result)
return;
+ data = result - sizeof (struct ctx_op_data);
+
+ LOCK (result_ref_lock);
data->references++;
+ UNLOCK (result_ref_lock);
}
void
gpgme_result_unref (void *result)
{
- struct ctx_op_data *data = result - sizeof (struct ctx_op_data);
+ struct ctx_op_data *data;
if (! result)
return;
- if (--data->references == 0)
+ data = result - sizeof (struct ctx_op_data);
+
+ LOCK (result_ref_lock);
+ if (--data->references)
{
- if (data->cleanup)
- (*data->cleanup) (data->hook);
- free (data);
+ UNLOCK (result_ref_lock);
+ return;
}
+
+ if (data->cleanup)
+ (*data->cleanup) (data->hook);
+ free (data);
}