Error correction for Visual and Clang

[SVN r77909]
This commit is contained in:
Ion Gaztañaga
2012-04-11 06:25:04 +00:00
parent f7da76b974
commit 14401bcb38
3 changed files with 38 additions and 4 deletions

View File

@@ -90,7 +90,7 @@ class heap_allocator_v1
//!Returns the segment manager. Never throws
segment_manager* get_segment_manager()const
{ return ipcdetail::to_raw_pointer(mp_mngr); }
/*
//!Returns address of mutable object. Never throws
pointer address(reference value) const
{ return pointer(addressof(value)); }
@@ -98,7 +98,7 @@ class heap_allocator_v1
//!Returns address of non mutable object. Never throws
const_pointer address(const_reference value) const
{ return const_pointer(addressof(value)); }
*/
//!Constructor from the segment manager. Never throws
heap_allocator_v1(segment_manager *segment_mngr)
: mp_mngr(segment_mngr) { }
@@ -115,7 +115,11 @@ class heap_allocator_v1
//!Allocates memory for an array of count elements.
//!Throws boost::interprocess::bad_alloc if there is no enough memory
pointer allocate(size_type count, cvoid_ptr hint = 0)
{ (void)hint; return ::new value_type[count]; }
{
(void)hint;
char *raw_mem = ::new char[sizeof(value_type)*count];
return boost::intrusive::pointer_traits<pointer>::pointer_to(reinterpret_cast<value_type &>(*raw_mem));
}
//!Deallocates memory previously allocated. Never throws
void deallocate(const pointer &ptr, size_type)

View File

@@ -97,6 +97,30 @@ class recursive_named_semaphore_test_wrapper
int recursive_named_semaphore_test_wrapper::count_ = 0;
bool test_named_semaphore_specific()
{
//Test persistance
{
named_semaphore sem(create_only, SemName, 3);
}
{
named_semaphore sem(open_only, SemName);
BOOST_INTERPROCES_CHECK(sem.try_wait() == true);
BOOST_INTERPROCES_CHECK(sem.try_wait() == true);
BOOST_INTERPROCES_CHECK(sem.try_wait() == true);
BOOST_INTERPROCES_CHECK(sem.try_wait() == false);
sem.post();
}
{
named_semaphore sem(open_only, SemName);
BOOST_INTERPROCES_CHECK(sem.try_wait() == true);
BOOST_INTERPROCES_CHECK(sem.try_wait() == false);
}
named_semaphore::remove(SemName);
return true;
}
int main ()
{
try{
@@ -105,6 +129,7 @@ int main ()
test::test_all_lock<named_semaphore_test_wrapper>();
test::test_all_recursive_lock<recursive_named_semaphore_test_wrapper>();
test::test_all_mutex<false, named_semaphore_test_wrapper>();
test_named_semaphore_specific();
}
catch(std::exception &ex){
named_semaphore::remove(SemName);

View File

@@ -20,7 +20,8 @@
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <stdio.h>
using namespace boost::interprocess;
namespace boost {
namespace interprocess {
//Force instantiations to catch compile-time errors
typedef basic_string<char> my_string;
@@ -30,6 +31,10 @@ typedef basic_vectorstream<my_vector> my_vectorstream_t;
template class basic_vectorstream<my_string>;
template class basic_vectorstream<std::vector<char> >;
}}
using namespace boost::interprocess;
static int vectorstream_test()
{
{ //Test high watermarking initialization