[vala] Use atomic ref/unref for closure data
- From: Sebastian Dröge <sdroege src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Use atomic ref/unref for closure data
- Date: Wed, 23 Jun 2010 18:21:59 +0000 (UTC)
commit a1303f90cac903f5ded51d52c42ac20a28722e71
Author: Sebastian Dröge <sebastian droege collabora co uk>
Date: Tue Jun 22 12:55:37 2010 +0200
Use atomic ref/unref for closure data
This prevents potential problems if it's used from
multiple threads, which could happen with GStreamer
for example.
Fixes bug #622476.
codegen/valaccodebasemodule.vala | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 1d2691f..41c6a59 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1841,7 +1841,10 @@ public class Vala.CCodeBaseModule : CCodeModule {
ref_fun.modifiers = CCodeModifiers.STATIC;
source_declarations.add_type_member_declaration (ref_fun.copy ());
ref_fun.block = new CCodeBlock ();
- ref_fun.block.add_statement (new CCodeExpressionStatement (new CCodeUnaryExpression (CCodeUnaryOperator.PREFIX_INCREMENT, new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "_ref_count_"))));
+
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_atomic_int_inc"));
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "_ref_count_")));
+ ref_fun.block.add_statement (new CCodeExpressionStatement (ccall));
ref_fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_data%d_".printf (block_id))));
source_type_member_definition.append (ref_fun);
@@ -1850,8 +1853,11 @@ public class Vala.CCodeBaseModule : CCodeModule {
unref_fun.modifiers = CCodeModifiers.STATIC;
source_declarations.add_type_member_declaration (unref_fun.copy ());
unref_fun.block = new CCodeBlock ();
- var dec = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeUnaryExpression (CCodeUnaryOperator.PREFIX_DECREMENT, new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "_ref_count_")), new CCodeConstant ("0"));
- unref_fun.block.add_statement (new CCodeIfStatement (dec, free_block));
+
+ ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_atomic_int_dec_and_test"));
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "_ref_count_")));
+ unref_fun.block.add_statement (new CCodeIfStatement (ccall, free_block));
+
source_type_member_definition.append (unref_fun);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]