diff options
Diffstat (limited to 'grc')
-rw-r--r-- | grc/blocks/options.xml | 16 | ||||
-rw-r--r-- | grc/python/flow_graph.tmpl | 19 |
2 files changed, 33 insertions, 2 deletions
diff --git a/grc/blocks/options.xml b/grc/blocks/options.xml index c1c94e4e24..6588dc72d0 100644 --- a/grc/blocks/options.xml +++ b/grc/blocks/options.xml @@ -158,6 +158,22 @@ part#slurp <key>1</key> </option> </param> + <param> + <name>Thread-safe setters</name> + <key>thread_safe_setters</key> + <value></value> + <type>enum</type> + <hide>part</hide> + <option> + <name>Off</name> + <key></key> + </option> + <option> + <name>On</name> + <key>1</key> + </option> + <tab>Advanced</tab> + </param> <check>len($window_size) == 2</check> <check>300 <= $(window_size)[0] <= 4096</check> <check>300 <= $(window_size)[1] <= 4096</check> diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl index 45d5d608b9..814b513213 100644 --- a/grc/python/flow_graph.tmpl +++ b/grc/python/flow_graph.tmpl @@ -31,6 +31,9 @@ $DIVIDER #end if # Generated: $time.ctime() $DIVIDER +#if $flow_graph.get_option('thread_safe_setters') +import threading +#end if ## Call XInitThreads as the _very_ first thing. ## After some Qt import, it's too late @@ -141,6 +144,10 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))]) self.message_port_register_hier_in("$pad['label']") #end for #end if +#if $flow_graph.get_option('thread_safe_setters') + + self._lock = threading.RLock() +#end if ######################################################## ##Create Parameters ## Set the parameter to a property of self. @@ -264,10 +271,18 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))]) return self.$id def set_$(id)(self, $id): + #if $flow_graph.get_option('thread_safe_setters') + with self._lock: + self.$id = $id + #for $callback in $var_id2cbs[$id] + $indent($callback) + #end for + #else self.$id = $id - #for $callback in $var_id2cbs[$id] + #for $callback in $var_id2cbs[$id] $indent($callback) - #end for + #end for + #end if #end for ######################################################## |