Skip to content

Commit

Permalink
Merge pure GPS into GLONASS; Add Ruby Ractor support
Browse files Browse the repository at this point in the history
  • Loading branch information
fenrir-naru committed Feb 2, 2025
2 parents caa4be4 + 92af11a commit 9e256df
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI_firmware_tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
(cd ./tool && make clean all && (cd build_GCC && touch ${GITHUB_SHA}.commit && tar zvcf ubuntu.${GITHUB_REF##*/}.tar.gz *.out *.commit) )
(cd ./tool && BUILD_DIR=build_GCC_ARM CXX=arm-linux-gnueabihf-g++ make clean all && (cd build_GCC_ARM && touch ${GITHUB_SHA}.commit && tar zvcf raspi.${GITHUB_REF##*/}.tar.gz *.out *.commit) )
- name: upload_artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
path: |
tool/build_*/*.tar.gz
Expand Down
6 changes: 6 additions & 0 deletions tool/swig/Coordinate.i
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

%feature("autodoc", "1");

%init %{
#ifdef HAVE_RB_EXT_RACTOR_SAFE
rb_ext_ractor_safe(true);
#endif
%}

%define MAKE_SETTER(name, type)
%rename(%str(name ## =)) set_ ## name;
type set_ ## name (const type &v) {
Expand Down
6 changes: 6 additions & 0 deletions tool/swig/GPS.i
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ inline std::string to_string(const T &value){
%include exception.i
%include std_except.i

%init %{
#ifdef HAVE_RB_EXT_RACTOR_SAFE
rb_ext_ractor_safe(true);
#endif
%}

#if !defined(SWIGIMPORTED)
%exceptionclass native_exception;
%typemap(throws,noblock=1) native_exception {
Expand Down
6 changes: 6 additions & 0 deletions tool/swig/NavigationModel.i
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@

%feature("autodoc", "1");

%init %{
#ifdef HAVE_RB_EXT_RACTOR_SAFE
rb_ext_ractor_safe(true);
#endif
%}

%define CONCRETIZE(type)
%template(MagneticField) MagneticFieldGeneric<type>;
%template(IGRF11) MagneticFieldGeneric2<type, IGRF11Generic>;
Expand Down
22 changes: 20 additions & 2 deletions tool/swig/SylphideMath.i
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

%module SylphideMath

#define ENABLE_IOSTREAM 1

%{
#include <string>
#include <sstream>
Expand All @@ -33,6 +31,12 @@
%include exception.i
%include std_except.i

%init %{
#ifdef HAVE_RB_EXT_RACTOR_SAFE
rb_ext_ractor_safe(true);
#endif
%}

%ignore native_exception;
#if !defined(SWIGIMPORTED)
%exceptionclass native_exception;
Expand Down Expand Up @@ -1022,6 +1026,20 @@ struct MatrixUtil {
}
return res;
}

VALUE to_shareable() const {
Matrix_Frozen<T, Array2D_Type, ViewType > *ptr(
new Matrix_Frozen<T, Array2D_Type, ViewType >(*$self));
VALUE res(SWIG_NewPointerObj(
ptr,
$descriptor(Matrix_Frozen<T, Array2D_Type, ViewType > *),
SWIG_POINTER_OWN));
rb_obj_freeze(res);
%#if defined(HAVE_RB_EXT_RACTOR_SAFE)
RB_FL_SET(res, RUBY_FL_SHAREABLE);
%#endif
return res;
}
#endif
%typemap(in)
Matrix<T, Array2D_Dense<T> > &output_L,
Expand Down
31 changes: 31 additions & 0 deletions tool/swig/spec/SylphideMath_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,37 @@
}
end
end
describe 'parallelization with Ractor' do
it "supports instantiation in sub Ractor" do
expect{
rac = Ractor::new{
mat_type, r, c = receive
# @see https://docs.ruby-lang.org/en/master/ractor_md.html#label-Return+value+of+a+block+for+Ractor.new
# When the block return value is available, ...,
# so any values can be sent with this communication path
# without any modification.
mat_type::new(r, c)
}
rac.send([mat_type, params[:rc]].flatten.freeze)
mat = rac.take
[:row_size, :column_size].zip(params[:rc]).each{|k, v|
expect(mat.send(k)).to eq(v)
}
}.not_to raise_error
end
it "supports messaging by using to_shareable between Ractors" do
expect{
rac = Ractor::new{
mat = receive
}
rac.send(mat_type::new(*params[:rc]).to_shareable)
mat = rac.take
[:row_size, :column_size].zip(params[:rc]).each{|k, v|
expect(mat.send(k)).to eq(v)
}
}.not_to raise_error
end
end if defined?(Ractor)
end

=begin
Expand Down
2 changes: 2 additions & 0 deletions tool/util/bit_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ struct BitCounter {

/**
* Count rightmost zeros before the first one (Number of trailing zeros)
* Be careful, if input equals to 0, then total number of corresponding type bits
* will be returned like (unsigned int)0 => 32.
* @param bits results
*/
static T ntz(const T &v) {
Expand Down

0 comments on commit 9e256df

Please sign in to comment.