summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2002-12-28 02:29:40 +0000
committernanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2002-12-28 02:29:40 +0000
commit99bb944aa9bc5f0a9031c692409b84af98f4b17b (patch)
tree31a010995f5982e1a0e0956179941b10505bb42a
parent4bc8d4f9f7cd7733e632d6a4ee9a46632cb50e90 (diff)
downloadATCD-99bb944aa9bc5f0a9031c692409b84af98f4b17b.tar.gz
ChangeLogTag:Fri Dec 27 20:06:39 2002 Nanbor Wang <nanbor@cs.wustl.edu>
-rw-r--r--ace/MEM_SAP.cpp8
-rw-r--r--ace/Malloc_T.cpp23
-rw-r--r--ace/Malloc_T.h25
-rw-r--r--ace/Malloc_T.i6
4 files changed, 47 insertions, 15 deletions
diff --git a/ace/MEM_SAP.cpp b/ace/MEM_SAP.cpp
index e9b6fe6fd6c..1ee429f57c9 100644
--- a/ace/MEM_SAP.cpp
+++ b/ace/MEM_SAP.cpp
@@ -55,6 +55,14 @@ ACE_MEM_SAP::create_shm_malloc (const ACE_TCHAR *name,
options),
-1);
+ if (this->shm_malloc_->bad () != 0)
+ {
+ this->shm_malloc_->remove (); // Cleanup OS resources
+ delete this->shm_malloc_;
+ this->shm_malloc_ = 0;
+ return -1;
+ }
+
return 0;
}
diff --git a/ace/Malloc_T.cpp b/ace/Malloc_T.cpp
index 5554f81a713..faf7b0f942a 100644
--- a/ace/Malloc_T.cpp
+++ b/ace/Malloc_T.cpp
@@ -280,7 +280,8 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::open (void)
template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB>
ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T (const ACE_TCHAR *pool_name)
- : memory_pool_ (pool_name)
+ : memory_pool_ (pool_name),
+ bad_flag_ (0)
{
ACE_TRACE ("ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T");
if (pool_name == 0)
@@ -290,7 +291,7 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T (const ACE_TCHAR *p
ACE_DIRECTORY_SEPARATOR_CHAR)));
this->delete_lock_ = 1;
- if (this->open () == -1)
+ if ((this->bad_flag_ = this->open ()) == -1)
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT ("%p\n"),
ACE_LIB_TEXT ("ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T")));
@@ -300,7 +301,8 @@ template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB>
ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T (const ACE_TCHAR *pool_name,
const ACE_TCHAR *lock_name,
const ACE_MEM_POOL_OPTIONS *options)
- : memory_pool_ (pool_name, options)
+ : memory_pool_ (pool_name, options),
+ bad_flag_ (0)
{
ACE_TRACE ("ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T");
if (lock_name != 0)
@@ -310,7 +312,7 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T (const ACE_TCHAR *p
ACE_DIRECTORY_SEPARATOR_CHAR)));
this->delete_lock_ = 1;
- if (this->open () == -1)
+ if ((this->bad_flag_ = this->open ()) == -1)
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT ("%p\n"),
ACE_LIB_TEXT ("ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T")));
@@ -322,18 +324,20 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T (const ACE_TCHAR *p
const ACE_MEM_POOL_OPTIONS *options,
ACE_LOCK *lock)
: memory_pool_ (pool_name, options),
- lock_ (lock)
+ lock_ (lock),
+ delete_lock_ (0),
+ bad_flag_ (0)
{
ACE_TRACE ("ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T");
if (lock == 0)
{
+ this->bad_flag_ = -1;
errno = EINVAL;
return;
}
- this->delete_lock_ = 0;
- if (this->open () == -1)
+ if ((this->bad_flag_ = this->open ()) == -1)
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT ("%p\n"),
ACE_LIB_TEXT ("ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T")));
@@ -345,13 +349,14 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T (const ACE_TCHAR *p
const ACE_TCHAR *lock_name,
const void *options)
: memory_pool_ (pool_name,
- (const ACE_MEM_POOL_OPTIONS *) options)
+ (const ACE_MEM_POOL_OPTIONS *) options),
+ bad_flag_ (0)
{
ACE_TRACE ("ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T");
ACE_NEW (this->lock_, ACE_LOCK (lock_name));
this->delete_lock_ = 1;
- if (this->open () == -1)
+ if ((this->bad_flag_ = this->open ()) == -1)
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT ("%p\n"),
ACE_LIB_TEXT ("ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T")));
diff --git a/ace/Malloc_T.h b/ace/Malloc_T.h
index 95ac6c157e2..32b4b2a31dd 100644
--- a/ace/Malloc_T.h
+++ b/ace/Malloc_T.h
@@ -6,7 +6,7 @@
*
* $Id$
*
- * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> and
+ * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> and
* Irfan Pyarali <irfan@cs.wustl.edu>
*/
//==========================================================================
@@ -215,7 +215,7 @@ public:
/**
* Note that @a pool_name should be located in
* a directory with the appropriate visibility and protection so
- * that all processes that need to access it can do so.
+ * that all processes that need to access it can do so.
* This constructor must be inline to avoid bugs with some C++
* compilers. */
ACE_Allocator_Adapter (const char *pool_name,
@@ -238,7 +238,7 @@ public:
/**
* Note that @a pool_name should be located in
* a directory with the appropriate visibility and protection so
- * that all processes that need to access it can do so.
+ * that all processes that need to access it can do so.
* This constructor must be inline to avoid bugs with some C++
* compilers. */
ACE_Allocator_Adapter (const wchar_t *pool_name,
@@ -423,7 +423,7 @@ public:
*
* Note that @a pool_name should be located in
* a directory with the appropriate visibility and protection so
- * that all processes that need to access it can do so.
+ * that all processes that need to access it can do so.
*/
ACE_Malloc_T (const ACE_TCHAR *pool_name = 0);
@@ -436,7 +436,7 @@ public:
*
* Note that @a pool_name should be located in
* a directory with the appropriate visibility and protection so
- * that all processes that need to access it can do so.
+ * that all processes that need to access it can do so.
*/
ACE_Malloc_T (const ACE_TCHAR *pool_name,
const ACE_TCHAR *lock_name,
@@ -594,6 +594,16 @@ public:
/// Return cb_ptr value.
void *base_addr (void);
+ /**
+ * Bad flag. This operation should be called immediately after the
+ * construction of the Malloc object to query whether the object was
+ * constructed successfully. If not, the user should invoke @c
+ * remove and release the object (it is not usable.)
+ * @retval 0 if all is fine. non-zero if this malloc object is
+ * unuable.
+ */
+ int bad (void);
+
private:
/// Initialize the Malloc pool.
int open (void);
@@ -627,6 +637,9 @@ private:
/// Lock that ensures mutual exclusion for the memory pool.
ACE_LOCK *lock_;
int delete_lock_; // True if destructor should delete the lock
+
+ /// Keep track of failure in constructor.
+ int bad_flag_;
};
/**
@@ -784,7 +797,7 @@ public:
* initialize the underlying memory pool. Note that @a pool_name
* should be located in a directory with the appropriate visibility
* and protection so that all processes that need to access it can
- * do so.
+ * do so.
*/
ACE_Malloc (const ACE_TCHAR *pool_name,
const ACE_TCHAR *lock_name,
diff --git a/ace/Malloc_T.i b/ace/Malloc_T.i
index 53f3d5cd78e..6093977e5bc 100644
--- a/ace/Malloc_T.i
+++ b/ace/Malloc_T.i
@@ -221,6 +221,12 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ref_counter (void)
}
template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE int
+ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::bad (void)
+{
+ return this->bad_flag_;
+}
+
+template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE int
ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::release (int close)
{
ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);