After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 741579 - Unlock LGI lock
Unlock LGI lock
Status: RESOLVED FIXED
Product: libpeas
Classification: Platform
Component: lua
git master
Other Linux
: Normal normal
: ---
Assigned To: libpeas-maint
libpeas-maint
Depends on:
Blocks:
 
 
Reported: 2014-12-15 22:44 UTC by Garrett Regier
Modified: 2014-12-16 11:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix Lua plugins to work with multiple threads (7.59 KB, patch)
2014-12-15 22:48 UTC, Garrett Regier
none Details | Review
Fix Lua plugins to work with multiple threads v2 (7.66 KB, patch)
2014-12-16 09:43 UTC, Garrett Regier
committed Details | Review
Test that plugins are multi-thread safe (7.53 KB, patch)
2014-12-16 10:32 UTC, Garrett Regier
committed Details | Review

Description Garrett Regier 2014-12-15 22:44:38 UTC
See the LGI bug for more details

https://github.com/pavouk/lgi/issues/92
Comment 1 Garrett Regier 2014-12-15 22:48:03 UTC
Created attachment 292781 [details] [review]
Fix Lua plugins to work with multiple threads

Unlock the LGI lock after init and acquire and release it
as necessary. This allows plugins to be used from multiple
threads and global plugin loader limitations.
Comment 2 Ignacio Casal Quinteiro (nacho) 2014-12-16 09:31:34 UTC
Review of attachment 292781 [details] [review]:

See the comments.

::: loaders/lua5.1/peas-plugin-loader-lua.c
@@ +403,3 @@
     }
 
+  /* Initially the lock is taken,

why? me from the ignorance from lua, who has it?

@@ +432,3 @@
 
+  /* Make sure to take the lock before calling Lua code */
+  lua_loader->priv->lgi_enter_func (lua_loader->priv->lgi_lock);

why not a leave after the lua_close?
Comment 3 Garrett Regier 2014-12-16 09:36:46 UTC
(In reply to comment #2)
> Review of attachment 292781 [details] [review]:
> 
> See the comments.
> 
> ::: loaders/lua5.1/peas-plugin-loader-lua.c
> @@ +403,3 @@
>      }
> 
> +  /* Initially the lock is taken,
> 
> why? me from the ignorance from lua, who has it?
> 

LGI does, because it is the lgi_lock ;)

> @@ +432,3 @@
> 
> +  /* Make sure to take the lock before calling Lua code */
> +  lua_loader->priv->lgi_enter_func (lua_loader->priv->lgi_lock);
> 
> why not a leave after the lua_close?

Because lua_close will be calling Lua code and the lock is only valid while the lua_State is valid/open. Also a callback could be running Lua code so we should block until the callback is done.
Comment 4 Garrett Regier 2014-12-16 09:43:02 UTC
Created attachment 292795 [details] [review]
Fix Lua plugins to work with multiple threads v2

Updated comments
Comment 5 Ignacio Casal Quinteiro (nacho) 2014-12-16 09:46:31 UTC
Review of attachment 292795 [details] [review]:

One more comment, sorry for not spotting before

::: loaders/lua5.1/peas-plugin-loader-lua.c
@@ +390,3 @@
+      lua_loader->priv->lgi_leave_func == NULL)
+    {
+      g_warning ("Failed to find 'lgi.lock', 'lgi.enter' and 'lgi.leave'");

I know it is not so clean but you should probably do individual checks
get the lock and check if it is null and then already return without checking the next one
Comment 6 Garrett Regier 2014-12-16 09:49:53 UTC
(In reply to comment #5)
> Review of attachment 292795 [details] [review]:
> 
> One more comment, sorry for not spotting before
> 
> ::: loaders/lua5.1/peas-plugin-loader-lua.c
> @@ +390,3 @@
> +      lua_loader->priv->lgi_leave_func == NULL)
> +    {
> +      g_warning ("Failed to find 'lgi.lock', 'lgi.enter' and 'lgi.leave'");
> 
> I know it is not so clean but you should probably do individual checks
> get the lock and check if it is null and then already return without checking
> the next one

All of these fields were added at the same time, if any of them are missing either the LGI version is too old (a release hasn't been made yet) or LGI is terribly broken. I don't really think we should need to check each individually, this is going to become just a basic sanity check once an LGI release is made.

Thoughts?
Comment 7 Garrett Regier 2014-12-16 10:32:02 UTC
Created attachment 292796 [details] [review]
Test that plugins are multi-thread safe
Comment 8 Garrett Regier 2014-12-16 11:44:42 UTC
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.