Skip to content

Commit e22eb8e

Browse files
committed
Refs #23079. Enable thread support for directors and release lock in server run().
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent 8b32483 commit e22eb8e

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ import "FastCdrCommon.stg"
2020
main(ctx, definitions) ::= <<
2121
$fileHeader(ctx=ctx, file=[ctx.filename, ".i"], description=["This header file contains the SWIG interface of the described types in the IDL file."])$
2222

23-
%module(directors="1",moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('$ctx.filename$.dll')\nif __package__ or '.' in __name__:\n from . import _$ctx.filename$Wrapper\nelse:\n import _$ctx.filename$Wrapper") $ctx.filename$
23+
%module($if(ctx.thereIsInterface)$threads="1",$endif$directors="1",moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('$ctx.filename$.dll')\nif __package__ or '.' in __name__:\n from . import _$ctx.filename$Wrapper\nelse:\n import _$ctx.filename$Wrapper") $ctx.filename$
24+
25+
$if(ctx.thereIsInterface)$
26+
// We have enabled threads because the RPC server directors will call the target language environment
27+
// from the C++ server threads, but we don't want the calls from the target language to release their
28+
// locks (e.g. Python GIL) when calling the C++ methods.
29+
// See a very nice explanation at https://github.com/swig/swig/issues/927#issuecomment-289279243
30+
%feature("nothreadallow");
31+
$endif$
2432

2533
// If using windows in debug, it would try to use python_d, which would not be found.
2634
%begin %{
@@ -376,6 +384,16 @@ $export_list$
376384
%shared_ptr($interface.scopedname$);
377385
$if(!interface.annotatedAsNested)$
378386
%shared_ptr($interface.scopedname$Server);
387+
%extend $interface.scopedname$Server
388+
{
389+
void run()
390+
{
391+
Py_BEGIN_ALLOW_THREADS
392+
self->run();
393+
Py_END_ALLOW_THREADS
394+
}
395+
}
396+
379397
%shared_ptr($interface.scopedname$Server_IServerImplementation);
380398
%shared_ptr($interface.scopedname$ServerImplementation);
381399
%feature("director") $interface.scopedname$ServerImplementation;

0 commit comments

Comments
 (0)