Skip to content

Commit da01f2f

Browse files
committed
Added a new spin-wait method. Spins + yields for a system tick and then sleeps a tick.
[SVN r85505]
1 parent 856d0d3 commit da01f2f

18 files changed

+588
-221
lines changed

Jamfile.v2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import testing ;
22

33
# Tests from Jamfiles in individual library test subdirectories
44
build-project example ; # test-suite interprocess_example
5-
build-project test ; # test-suite interprocess_test
5+
build-project test ; # test-suite interprocess_test

doc/interprocess.qbk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6716,7 +6716,8 @@ thank them:
67166716
[section:release_notes_boost_1_55_00 Boost 1.55 Release]
67176717

67186718
* Fixed bugs [@https://svn.boost.org/trac/boost/ticket/7164 #7164],
6719-
[@https://svn.boost.org/trac/boost/ticket/8277 #8277].
6719+
[@https://svn.boost.org/trac/boost/ticket/8277 #8277],
6720+
[@https://svn.boost.org/trac/boost/ticket/8277 #9908].
67206721

67216722
[endsect]
67226723

include/boost/interprocess/detail/intermodule_singleton_common.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <boost/interprocess/exceptions.hpp>
2424
#include <boost/type_traits/type_with_alignment.hpp>
2525
#include <boost/interprocess/detail/mpl.hpp>
26+
#include <boost/interprocess/sync/spin/wait.hpp>
2627
#include <boost/assert.hpp>
2728
#include <cstddef>
2829
#include <cstdio>
@@ -145,15 +146,15 @@ class intermodule_singleton_common
145146
//If previous state was initializing, this means that another winner thread is
146147
//trying to initialize the singleton. Just wait until completes its work.
147148
else if(previous_module_singleton_initialized == Initializing){
148-
unsigned int k = 0;
149+
spin_wait swait;
149150
while(1){
150151
previous_module_singleton_initialized = atomic_read32(&this_module_singleton_initialized);
151152
if(previous_module_singleton_initialized >= Initialized){
152153
//Already initialized, or exception thrown by initializer thread
153154
break;
154155
}
155156
else if(previous_module_singleton_initialized == Initializing){
156-
yield(k++);
157+
swait.yield();
157158
}
158159
else{
159160
//This can't be happening!
@@ -207,7 +208,7 @@ class intermodule_singleton_common
207208
static void initialize_global_map_handle()
208209
{
209210
//Obtain unique map name and size
210-
unsigned k = 0;
211+
spin_wait swait;
211212
while(1){
212213
//Try to pass map state to initializing
213214
::boost::uint32_t tmp = atomic_cas32(&this_module_map_initialized, Initializing, Uninitialized);
@@ -220,7 +221,7 @@ class intermodule_singleton_common
220221
}
221222
//If some other thread is doing the work wait
222223
else if(tmp == Initializing){
223-
yield(k++);
224+
swait.yield();
224225
}
225226
else{ //(tmp == Uninitialized)
226227
//If not initialized try it again?

include/boost/interprocess/detail/managed_open_or_create_impl.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <boost/interprocess/permissions.hpp>
2626
#include <boost/type_traits/alignment_of.hpp>
2727
#include <boost/type_traits/type_with_alignment.hpp>
28+
#include <boost/interprocess/sync/spin/wait.hpp>
2829
#include <boost/move/move.hpp>
2930
#include <boost/cstdint.hpp>
3031

@@ -354,7 +355,7 @@ class managed_open_or_create_impl
354355
//file and know if we have really created it or just open it
355356
//drop me a e-mail!
356357
bool completed = false;
357-
unsigned k = 0;
358+
spin_wait swait;
358359
while(!completed){
359360
try{
360361
create_device<FileBased>(dev, id, size, perm, file_like_t());
@@ -385,7 +386,7 @@ class managed_open_or_create_impl
385386
catch(...){
386387
throw;
387388
}
388-
yield(k++);
389+
swait.yield();
389390
}
390391
}
391392

@@ -432,12 +433,12 @@ class managed_open_or_create_impl
432433
else{
433434
if(FileBased){
434435
offset_t filesize = 0;
435-
unsigned k = 0;
436+
spin_wait swait;
436437
while(filesize == 0){
437438
if(!get_file_size(file_handle_from_mapping_handle(dev.get_mapping_handle()), filesize)){
438439
throw interprocess_exception(error_info(system_error_code()));
439440
}
440-
yield(k++);
441+
swait.yield();
441442
}
442443
if(filesize == 1){
443444
throw interprocess_exception(error_info(corrupted_error));
@@ -449,9 +450,9 @@ class managed_open_or_create_impl
449450
boost::uint32_t *patomic_word = static_cast<boost::uint32_t*>(region.get_address());
450451
boost::uint32_t value = atomic_read32(patomic_word);
451452

452-
unsigned k = 0;
453+
spin_wait swait;
453454
while(value == InitializingSegment || value == UninitializedSegment){
454-
yield(k++);
455+
swait.yield();
455456
value = atomic_read32(patomic_word);
456457
}
457458

0 commit comments

Comments
 (0)