跨线程传递 XPCOM 接口指针

发布于 2024-12-20 07:13:03 字数 316 浏览 4 评论 0原文

我是使用 XPCOM 开发 Firefox 扩展的新手。目前,我正在使用后台线程在 XPCOM 中执行一些工作,并且需要将一个 XPCOM 接口(例如 nsIDomwindow)的指针从主线程传递到该线程。但如果在Windows API函数Createthread中使用该指针作为参数并使用它,则会导致Firefox崩溃。

如何解决这个问题?在MS com中是否有类似的方法来使用CoMarshalInterThreadInterfaceInStream/CoGetInterfaceAndReleaseStream? XPCOM只支持单线程吗?

期待您的所有建议和示例代码!提前致谢!

I am new to develop Firefox extension with XPCOM. Currently I am using a background thread to do some work in XPCOM and need to pass a pointer of one XPCOM interface (eg nsIDomwindow) from main thread to that thread. But if use the pointer as the parameter in windows API fundtion Createthread and use it then, that will cause Firefox crash.

How to solve this issue? Is there any similar way to use CoMarshalInterThreadInterfaceInStream/CoGetInterfaceAndReleaseStream in MS com? Does the XPCOM only support single thread?

Look forward all your advice and sample code! Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒冷纷飞旳雪 2024-12-27 07:13:04

许多 XPCOM 对象不是线程安全的,特别是任何 DOM 对象只能从主线程访问。要检查对象是否是线程安全的,您必须将其 QueryInterfacensIClassInfo 并检查 nsIClassInfo.flags 是否包含 nsIClassInfo.THREADSAFE 标志。如果是,那么您可以简单地在线程之间传递接口指针。

Many XPCOM objects aren't thread-safe, in particular any DOM objects can only be accessed from the main thread. To check whether an object is thread-safe you have to QueryInterface it to nsIClassInfo and check whether nsIClassInfo.flags contains nsIClassInfo.THREADSAFE flag. If it is then you can simply pass the interface pointer between threads.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文