fastthread 0.6.3 → 0.6.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +2 -2
  2. data/ext/fastthread/fastthread.c +90 -21
  3. metadata +3 -3
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake/testtask'
4
4
  require 'rake/gempackagetask'
5
5
  require 'tools/rakehelp'
6
6
 
7
- GEM_VERSION="0.6.3"
7
+ GEM_VERSION="0.6.4.1"
8
8
 
9
9
  setup_extension('fastthread', 'fastthread')
10
10
 
@@ -49,7 +49,7 @@ end
49
49
 
50
50
  setup_clean ["ext/fastthread/*.{bundle,so,obj,pdb,lib,def,exp}", "ext/fastthread/Makefile", "pkg", "lib/*.bundle", "*.gem", ".config"]
51
51
 
52
- task :install => [:default] do
52
+ task :install => [:default, :package] do
53
53
  sh %{ sudo gem install pkg/fastthread-#{GEM_VERSION}.gem }
54
54
  end
55
55
 
@@ -134,6 +134,23 @@ push_multiple_list(list, values, count)
134
134
  }
135
135
  }
136
136
 
137
+ static void recycle_entries _((List *, Entry *, Entry *));
138
+
139
+ static void
140
+ recycle_entries(list, first_entry, last_entry)
141
+ List *list;
142
+ Entry *first_entry;
143
+ Entry *last_entry;
144
+ {
145
+ if (USE_MEM_POOLS) {
146
+ last_entry->next = list->entry_pool;
147
+ list->entry_pool = first_entry;
148
+ } else {
149
+ last_entry->next = NULL;
150
+ free_entries(first_entry);
151
+ }
152
+ }
153
+
137
154
  static VALUE shift_list _((List *));
138
155
 
139
156
  static VALUE
@@ -154,16 +171,32 @@ shift_list(list)
154
171
  --list->size;
155
172
 
156
173
  value = entry->value;
157
- if (USE_MEM_POOLS) {
158
- entry->next = list->entry_pool;
159
- list->entry_pool = entry;
160
- } else {
161
- free(entry);
162
- }
174
+ recycle_entries(list, entry, entry);
163
175
 
164
176
  return value;
165
177
  }
166
178
 
179
+ static void remove_one _((List *, VALUE));
180
+
181
+ static void
182
+ remove_one(list, value)
183
+ List *list;
184
+ VALUE value;
185
+ {
186
+ Entry **ref;
187
+ Entry *entry;
188
+ for (ref = &list->entries, entry = list->entries;
189
+ entry != NULL;
190
+ ref = &entry->next, entry = entry->next)
191
+ {
192
+ if (entry->value == value) {
193
+ *ref = entry->next;
194
+ recycle_entries(list, entry, entry);
195
+ break;
196
+ }
197
+ }
198
+ }
199
+
167
200
  static void clear_list _((List *));
168
201
 
169
202
  static void
@@ -171,12 +204,7 @@ clear_list(list)
171
204
  List *list;
172
205
  {
173
206
  if (list->last_entry) {
174
- if (USE_MEM_POOLS) {
175
- list->last_entry->next = list->entry_pool;
176
- list->entry_pool = list->entries;
177
- } else {
178
- free_entries(list->entries);
179
- }
207
+ recycle_entries(list, list->entries, list->last_entry);
180
208
  list->entries = NULL;
181
209
  list->last_entry = NULL;
182
210
  list->size = 0;
@@ -246,6 +274,39 @@ wake_all(list)
246
274
  return Qnil;
247
275
  }
248
276
 
277
+ static VALUE wait_list_inner _((List *));
278
+
279
+ static VALUE
280
+ wait_list_inner(list)
281
+ List *list;
282
+ {
283
+ push_list(list, rb_thread_current());
284
+ rb_thread_stop();
285
+ return Qnil;
286
+ }
287
+
288
+ static VALUE wait_list_cleanup _((List *));
289
+
290
+ static VALUE
291
+ wait_list_cleanup(list)
292
+ List *list;
293
+ {
294
+ /* cleanup in case of spurious wakeups */
295
+ rb_thread_critical = 1;
296
+ remove_one(list, rb_thread_current());
297
+ rb_thread_critical = 0;
298
+ return Qnil;
299
+ }
300
+
301
+ static void wait_list _((List *));
302
+
303
+ static void
304
+ wait_list(list)
305
+ List *list;
306
+ {
307
+ rb_ensure(wait_list_inner, (VALUE)list, wait_list_cleanup, (VALUE)list);
308
+ }
309
+
249
310
  static void assert_no_survivors _((List *, const char *, void *));
250
311
 
251
312
  static void
@@ -365,9 +426,7 @@ lock_mutex(mutex)
365
426
  rb_thread_critical = 1;
366
427
 
367
428
  while (RTEST(mutex->owner)) {
368
- push_list(&mutex->waiting, current);
369
- rb_thread_stop();
370
-
429
+ wait_list(&mutex->waiting);
371
430
  rb_thread_critical = 1;
372
431
  }
373
432
  mutex->owner = current;
@@ -571,8 +630,7 @@ wait_condvar(condvar, mutex)
571
630
  rb_raise(private_eThreadError, "Not owner");
572
631
  }
573
632
  mutex->owner = Qnil;
574
- push_list(&condvar->waiting, rb_thread_current());
575
- rb_thread_stop();
633
+ wait_list(&condvar->waiting);
576
634
 
577
635
  lock_mutex(mutex);
578
636
  }
@@ -598,8 +656,7 @@ legacy_wait(unused, args)
598
656
  VALUE unused;
599
657
  legacy_wait_args *args;
600
658
  {
601
- push_list(&args->condvar->waiting, rb_thread_current());
602
- rb_thread_stop();
659
+ wait_list(&args->condvar->waiting);
603
660
  rb_funcall(args->mutex, rb_intern("lock"), 0);
604
661
  return Qnil;
605
662
  }
@@ -1048,9 +1105,21 @@ static VALUE setup_classes(unused)
1048
1105
  void
1049
1106
  Init_fastthread()
1050
1107
  {
1108
+ VALUE global_variables;
1109
+ VALUE fastthread_avoid_mem_pools;
1051
1110
  int saved_critical;
1052
-
1053
- avoid_mem_pools = rb_gv_get("$fastthread_avoid_mem_pools");
1111
+ int i;
1112
+
1113
+ avoid_mem_pools = Qnil;
1114
+ fastthread_avoid_mem_pools = rb_str_new2("$fastthread_avoid_mem_pools");
1115
+ global_variables = rb_f_global_variables();
1116
+ for ( i = 0 ; i < RARRAY(global_variables)->len ; i++ ) {
1117
+ if (RTEST(rb_equal(RARRAY(global_variables)->ptr[i], fastthread_avoid_mem_pools))) {
1118
+ avoid_mem_pools = rb_gv_get("$fastthread_avoid_mem_pools");
1119
+ break;
1120
+ }
1121
+ }
1122
+
1054
1123
  rb_global_variable(&avoid_mem_pools);
1055
1124
  rb_define_variable("$fastthread_avoid_mem_pools", &avoid_mem_pools);
1056
1125
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: fastthread
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.6.3
7
- date: 2007-01-25 00:00:00 -05:00
6
+ version: 0.6.4.1
7
+ date: 2007-02-14 00:00:00 -05:00
8
8
  summary: Optimized replacement for thread.rb primitives
9
9
  require_paths:
10
10
  - lib
@@ -30,9 +30,9 @@ authors:
30
30
  files:
31
31
  - Rakefile
32
32
  - setup.rb
33
- - test/test_all.rb
34
33
  - test/test_condvar.rb
35
34
  - test/test_mutex.rb
35
+ - test/test_all.rb
36
36
  - test/test_queue.rb
37
37
  - ext/fastthread/fastthread.c
38
38
  - ext/fastthread/extconf.rb