gvltest 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5688674c565e5193465e8b9aba96a1d5841029f7b44d4892b3e7a32c475400e7
4
- data.tar.gz: d02cc2f5d9baf5fe9d3e1b7964e492b5fc53d9d2ec4ea4445c27b9dd8c92c2e1
3
+ metadata.gz: b3099832fb7cf4b13b0a56e5c967d4b56940ceeb6484485674898eed70b5c717
4
+ data.tar.gz: f955e38ad859a6641d19e7902c94035fa90c8d2174a24116aca7aa45c313b0c3
5
5
  SHA512:
6
- metadata.gz: 53037d6ab481d4b96bb0c8eb5f4dccc7540121f705da473dde5a7d1d485997113b31a1d173de95e2840f10c579dad652c5e6294b596c1d39c35f13333ee233f3
7
- data.tar.gz: ba2c6750a6445f9c070f7b091c30c8073866167e6fade7e2c80010b007ccc4fed5343da758c537b134460de8fb28e5e035dedc553b4a8511d14f9c72338a4519
6
+ metadata.gz: ca4be5f938a7b9f0584c651ba4d309cdf4e1dff0f2f6b8c8572352bd177ac943f169a0669899fa47a4e99db23a212869fc94971d6ad5ac9a3deb991a349566d1
7
+ data.tar.gz: 4a5023ab815279ebd88aa94b61c3947845357ae720851ccd96861dd4e9123167449f1267655d151ad2d0b61910a8485cb1b65c562a39e7ab5c3ff4854039c426
data/Rakefile CHANGED
@@ -1,6 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
4
12
  require "rake/extensiontask"
5
13
 
6
14
  task build: :compile
@@ -11,4 +19,4 @@ Rake::ExtensionTask.new("gvltest", GEMSPEC) do |ext|
11
19
  ext.lib_dir = "lib/gvltest"
12
20
  end
13
21
 
14
- task default: %i[clobber compile]
22
+ task default: %i[clobber compile test]
@@ -1,26 +1,56 @@
1
1
  #include "gvltest.h"
2
2
 
3
+ #include <ruby/thread.h>
3
4
  #include <time.h>
4
5
  #include <errno.h>
5
6
 
6
- VALUE rb_mGVLTest;
7
-
8
- VALUE sleep_holding_gvl(VALUE self, VALUE timev) {
9
- double time = NUM2DBL(timev);
10
- unsigned long long int ns = time * 1E9;
11
- struct timespec ts = { ns / 1000000000LL, ns % 1000000000LL };
7
+ static VALUE rb_mGVLTest;
12
8
 
9
+ static void durable_sleep(struct timespec ts) {
13
10
  int res;
14
11
  do {
15
12
  res = nanosleep(&ts, &ts);
16
13
  } while (res && errno == EINTR);
14
+ }
17
15
 
16
+ static VALUE sleep_holding_gvl(VALUE self, VALUE timev) {
17
+ double time = NUM2DBL(timev);
18
+ unsigned long long int ns = time * 1E9;
19
+ struct timespec ts = { ns / 1000000000LL, ns % 1000000000LL };
20
+ durable_sleep(ts);
18
21
  return timev;
19
22
  }
20
23
 
24
+ static void *sleep_without_gvl_i(void *tsv) {
25
+ struct timespec *ts = tsv;
26
+ durable_sleep(*ts);
27
+ return NULL;
28
+ }
29
+
30
+ static VALUE sleep_without_gvl(VALUE self, VALUE timev) {
31
+ double time = NUM2DBL(timev);
32
+ unsigned long long int ns = time * 1E9;
33
+ struct timespec ts = { ns / 1000000000LL, ns % 1000000000LL };
34
+
35
+ rb_thread_call_without_gvl(sleep_without_gvl_i, &ts, NULL, NULL);
36
+ return Qnil;
37
+ }
38
+
39
+
40
+ static void *nop(void *unused) {
41
+ return NULL;
42
+ }
43
+
44
+ static VALUE nogvl_nop(VALUE self) {
45
+ rb_thread_call_without_gvl(nop, NULL, NULL, NULL);
46
+ return Qnil;
47
+ }
48
+
21
49
  RUBY_FUNC_EXPORTED void
22
50
  Init_gvltest(void)
23
51
  {
24
52
  rb_mGVLTest = rb_define_module("GVLTest");
25
53
  rb_define_singleton_method(rb_mGVLTest, "sleep_holding_gvl", sleep_holding_gvl, 1);
54
+ rb_define_singleton_method(rb_mGVLTest, "sleep_without_gvl", sleep_without_gvl, 1);
55
+ rb_define_singleton_method(rb_mGVLTest, "nogvl_nop", nogvl_nop, 0);
26
56
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GVLTest
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gvltest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-23 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gvl_timing
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  description: Some test methods for experimenting with CRuby's GVL
14
42
  email:
15
43
  - john@hawthorn.email
@@ -49,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
77
  - !ruby/object:Gem::Version
50
78
  version: '0'
51
79
  requirements: []
52
- rubygems_version: 3.5.3
80
+ rubygems_version: 3.4.19
53
81
  signing_key:
54
82
  specification_version: 4
55
83
  summary: Some test methods for experimenting with CRuby's GVL