/usr/include/ace/Bound_Ptr.inl is in libace-dev 6.3.3+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | /* -*- C++ -*- */
// Bound_Ptr.i
#include "ace/Guard_T.h"
#if !defined (ACE_NEW_THROWS_EXCEPTIONS)
# include "ace/Log_Category.h"
#endif /* ACE_NEW_THROWS_EXCEPTIONS */
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
template <class ACE_LOCK> inline ACE_Bound_Ptr_Counter<ACE_LOCK> *
ACE_Bound_Ptr_Counter<ACE_LOCK>::internal_create (long init_obj_ref_count)
{
ACE_Bound_Ptr_Counter<ACE_LOCK> *temp = 0;
ACE_NEW_RETURN (temp,
ACE_Bound_Ptr_Counter<ACE_LOCK> (init_obj_ref_count),
0);
return temp;
}
template <class ACE_LOCK> inline ACE_Bound_Ptr_Counter<ACE_LOCK> *
ACE_Bound_Ptr_Counter<ACE_LOCK>::create_strong (void)
{
// Set initial object reference count to 1.
ACE_Bound_Ptr_Counter<ACE_LOCK> *temp = internal_create (1);
#if defined (ACE_NEW_THROWS_EXCEPTIONS)
if (temp == 0)
ACE_throw_bad_alloc;
#else
ACE_ASSERT (temp != 0);
#endif /* ACE_NEW_THROWS_EXCEPTIONS */
return temp;
}
template <class ACE_LOCK> inline long
ACE_Bound_Ptr_Counter<ACE_LOCK>::attach_strong (ACE_Bound_Ptr_Counter<ACE_LOCK>* counter)
{
ACE_GUARD_RETURN (ACE_LOCK, guard, counter->lock_, -1);
// Can't attach a strong pointer to an object that has already been deleted.
if (counter->obj_ref_count_ == -1)
return -1;
long new_obj_ref_count = ++counter->obj_ref_count_;
++counter->self_ref_count_;
return new_obj_ref_count;
}
template <class ACE_LOCK> inline long
ACE_Bound_Ptr_Counter<ACE_LOCK>::detach_strong (ACE_Bound_Ptr_Counter<ACE_LOCK>* counter)
{
ACE_Bound_Ptr_Counter<ACE_LOCK> *counter_del = 0;
long new_obj_ref_count;
{
ACE_GUARD_RETURN (ACE_LOCK, guard, counter->lock_, -1);
if ((new_obj_ref_count = --counter->obj_ref_count_) == 0)
// Change the object reference count to -1 to indicate that the
// object has been deleted, as opposed to a weak pointer that
// simply hasn't had any strong pointers created from it yet.
counter->obj_ref_count_ = -1;
if (--counter->self_ref_count_ == 0)
// Since counter contains the lock held by the guard, the
// guard needs to be released before freeing the memory holding
// the lock. So save the pointer to free, then release, then
// free.
counter_del = counter;
} // Release the lock
delete counter_del;
return new_obj_ref_count;
}
template <class ACE_LOCK> inline ACE_Bound_Ptr_Counter<ACE_LOCK> *
ACE_Bound_Ptr_Counter<ACE_LOCK>::create_weak (void)
{
// Set initial object reference count to 0.
ACE_Bound_Ptr_Counter<ACE_LOCK> *temp = internal_create (0);
#if defined (ACE_NEW_THROWS_EXCEPTIONS)
if (temp == 0)
ACE_throw_bad_alloc;
#else
ACE_ASSERT (temp != 0);
#endif /* ACE_NEW_THROWS_EXCEPTIONS */
return temp;
}
template <class ACE_LOCK> inline void
ACE_Bound_Ptr_Counter<ACE_LOCK>::attach_weak (ACE_Bound_Ptr_Counter<ACE_LOCK>* counter)
{
ACE_GUARD (ACE_LOCK, guard, counter->lock_);
++counter->self_ref_count_;
}
template <class ACE_LOCK> inline void
ACE_Bound_Ptr_Counter<ACE_LOCK>::detach_weak (ACE_Bound_Ptr_Counter<ACE_LOCK>* counter)
{
ACE_Bound_Ptr_Counter<ACE_LOCK> *counter_del = 0;
{
ACE_GUARD (ACE_LOCK, guard, counter->lock_);
if (--counter->self_ref_count_ == 0)
// Since counter contains the lock held by the guard, the
// guard needs to be released before freeing the memory holding
// the lock. So save the pointer to free, then release, then
// free.
counter_del = counter;
} // Release the lock
delete counter_del;
}
template <class ACE_LOCK> inline bool
ACE_Bound_Ptr_Counter<ACE_LOCK>::object_was_deleted (ACE_Bound_Ptr_Counter<ACE_LOCK> *counter)
{
ACE_GUARD_RETURN (ACE_LOCK, guard, counter->lock_, 0);
return counter->obj_ref_count_ == -1;
}
template <class ACE_LOCK> inline
ACE_Bound_Ptr_Counter<ACE_LOCK>::ACE_Bound_Ptr_Counter (long init_obj_ref_count)
: obj_ref_count_ (init_obj_ref_count),
self_ref_count_ (1)
{
}
template <class ACE_LOCK> inline
ACE_Bound_Ptr_Counter<ACE_LOCK>::~ACE_Bound_Ptr_Counter (void)
{
}
template <class X, class ACE_LOCK> inline
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::ACE_Strong_Bound_Ptr (X *p)
: counter_ (COUNTER::create_strong ()),
ptr_ (p)
{
}
template <class X, class ACE_LOCK> inline
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::ACE_Strong_Bound_Ptr (auto_ptr<X> p)
: counter_ (COUNTER::create_strong ()),
ptr_ (p.release())
{
}
template <class X, class ACE_LOCK> inline
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::ACE_Strong_Bound_Ptr (const ACE_Strong_Bound_Ptr<X, ACE_LOCK> &r)
: counter_ (r.counter_),
ptr_ (r.ptr_)
{
COUNTER::attach_strong (this->counter_);
}
template <class X, class ACE_LOCK> inline
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::ACE_Strong_Bound_Ptr (const ACE_Weak_Bound_Ptr<X, ACE_LOCK> &r)
: counter_ (r.counter_),
ptr_ (r.ptr_)
{
// When creating a strong pointer from a weak one we can't assume that the
// underlying object still exists. Therefore we must check for a return value
// of -1, which indicates that the object has been destroyed.
if (COUNTER::attach_strong (this->counter_) == -1)
{
// Underlying object has already been deleted, so set this pointer to null.
this->counter_ = COUNTER::create_strong ();
this->ptr_ = 0;
}
}
template <class X, class ACE_LOCK> inline
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::~ACE_Strong_Bound_Ptr (void)
{
if (COUNTER::detach_strong (this->counter_) == 0)
delete this->ptr_;
}
template <class X, class ACE_LOCK> inline void
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::operator = (const ACE_Strong_Bound_Ptr<X, ACE_LOCK> &rhs)
{
// This will work if &r == this, by first increasing the ref count, but
// why go through all that?
if (&rhs == this)
return;
COUNTER *new_counter = rhs.counter_;
X_t *new_ptr = rhs.ptr_;
COUNTER::attach_strong (new_counter);
if (COUNTER::detach_strong (this->counter_) == 0)
delete this->ptr_;
this->counter_ = new_counter;
this->ptr_ = new_ptr;
}
template <class X, class ACE_LOCK> inline void
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::operator = (const ACE_Weak_Bound_Ptr<X, ACE_LOCK> &rhs)
{
// This will work if &r == this, by first increasing the ref count, but
// why go through all that?
if (&rhs == this)
return;
COUNTER *new_counter = rhs.counter_;
X_t *new_ptr = rhs.ptr_;
// When creating a strong pointer from a weak one we can't assume that the
// underlying object still exists. Therefore we must check for a return value
// of -1, which indicates that the object has been destroyed.
if (COUNTER::attach_strong (new_counter) == -1)
{
// Underlying object has already been deleted, so set this pointer to null.
new_counter = COUNTER::create_strong ();
new_ptr = 0;
}
if (COUNTER::detach_strong (this->counter_) == 0)
delete this->ptr_;
this->counter_ = new_counter;
this->ptr_ = new_ptr;
}
template <class X, class ACE_LOCK> inline bool
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::operator== (const ACE_Strong_Bound_Ptr<X, ACE_LOCK> &r) const
{
return this->ptr_ == r.ptr_;
}
template <class X, class ACE_LOCK> inline bool
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::operator== (const ACE_Weak_Bound_Ptr<X, ACE_LOCK> &r) const
{
// Use the weak pointer's operator== since it will check for null.
return r == *this;
}
template <class X, class ACE_LOCK> inline bool
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::operator== (X *p) const
{
return this->ptr_ == p;
}
template <class X, class ACE_LOCK> inline bool
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::operator!= (const ACE_Strong_Bound_Ptr<X, ACE_LOCK> &r) const
{
return this->ptr_ != r.ptr_;
}
template <class X, class ACE_LOCK> inline bool
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::operator!= (const ACE_Weak_Bound_Ptr<X, ACE_LOCK> &r) const
{
// Use the weak pointer's operator!= since it will check for null.
return r != *this;
}
template <class X, class ACE_LOCK> inline bool
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::operator!= (X *p) const
{
return this->ptr_ != p;
}
template <class X, class ACE_LOCK> inline X *
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::operator-> (void) const
{
return this->ptr_;
}
template<class X, class ACE_LOCK> inline X &
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::operator *() const
{
return *this->ptr_;
}
template <class X, class ACE_LOCK> inline X*
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::get (void) const
{
return this->ptr_;
}
template <class X, class ACE_LOCK> inline bool
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::null (void) const
{
return this->ptr_ == 0;
}
template<class X, class ACE_LOCK> inline void
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::reset (X *p)
{
COUNTER *old_counter = this->counter_;
X_t *old_ptr = this->ptr_;
this->counter_ = COUNTER::create_strong ();
this->ptr_ = p;
if (COUNTER::detach_strong (old_counter) == 0)
delete old_ptr;
}
template<class X, class ACE_LOCK> inline void
ACE_Strong_Bound_Ptr<X, ACE_LOCK>::reset (auto_ptr<X> p)
{
COUNTER *old_counter = this->counter_;
X_t *old_ptr = this->ptr_;
this->counter_ = COUNTER::create_strong ();
this->ptr_ = p.release ();
if (COUNTER::detach_strong (old_counter) == 0)
delete old_ptr;
}
template <class X, class ACE_LOCK> inline
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::ACE_Weak_Bound_Ptr (X *p)
: counter_ (COUNTER::create_weak ()),
ptr_ (p)
{
}
template <class X, class ACE_LOCK> inline
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::ACE_Weak_Bound_Ptr (const ACE_Weak_Bound_Ptr<X, ACE_LOCK> &r)
: counter_ (r.counter_),
ptr_ (r.ptr_)
{
COUNTER::attach_weak (this->counter_);
}
template <class X, class ACE_LOCK> inline
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::ACE_Weak_Bound_Ptr (const ACE_Strong_Bound_Ptr<X, ACE_LOCK> &r)
: counter_ (r.counter_),
ptr_ (r.ptr_)
{
COUNTER::attach_weak (this->counter_);
}
template <class X, class ACE_LOCK> inline
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::~ACE_Weak_Bound_Ptr (void)
{
COUNTER::detach_weak (this->counter_);
}
template <class X, class ACE_LOCK> inline void
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::operator = (const ACE_Weak_Bound_Ptr<X, ACE_LOCK> &rhs)
{
// This will work if &rhs == this, by first increasing the ref count
COUNTER *new_counter = rhs.counter_;
COUNTER::attach_weak (new_counter);
COUNTER::detach_weak (this->counter_);
this->counter_ = new_counter;
this->ptr_ = rhs.ptr_;
}
template <class X, class ACE_LOCK> inline void
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::operator = (const ACE_Strong_Bound_Ptr<X, ACE_LOCK> &rhs)
{
// This will work if &rhs == this, by first increasing the ref count
COUNTER *new_counter = rhs.counter_;
COUNTER::attach_weak (new_counter);
COUNTER::detach_weak (this->counter_);
this->counter_ = new_counter;
this->ptr_ = rhs.ptr_;
}
template <class X, class ACE_LOCK> inline bool
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::operator== (const ACE_Weak_Bound_Ptr<X, ACE_LOCK> &r) const
{
// A weak pointer must behave as though it is automatically set to null
// if the underlying object has been deleted.
if (COUNTER::object_was_deleted (this->counter_))
return r.ptr_ == 0;
return this->ptr_ == r.ptr_;
}
template <class X, class ACE_LOCK> inline bool
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::operator== (const ACE_Strong_Bound_Ptr<X, ACE_LOCK> &r) const
{
// A weak pointer must behave as though it is automatically set to null
// if the underlying object has been deleted.
if (COUNTER::object_was_deleted (this->counter_))
return r.ptr_ == 0;
return this->ptr_ == r.ptr_;
}
template <class X, class ACE_LOCK> inline bool
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::operator== (X *p) const
{
// A weak pointer must behave as though it is automatically set to null
// if the underlying object has been deleted.
if (COUNTER::object_was_deleted (this->counter_))
return p == 0;
return this->ptr_ == p;
}
template <class X, class ACE_LOCK> inline bool
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::operator!= (const ACE_Weak_Bound_Ptr<X, ACE_LOCK> &r) const
{
// A weak pointer must behave as though it is automatically set to null
// if the underlying object has been deleted.
if (COUNTER::object_was_deleted (this->counter_))
return r.ptr_ != 0;
return this->ptr_ != r.ptr_;
}
template <class X, class ACE_LOCK> inline bool
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::operator!= (const ACE_Strong_Bound_Ptr<X, ACE_LOCK> &r) const
{
// A weak pointer must behave as though it is automatically set to null
// if the underlying object has been deleted.
if (COUNTER::object_was_deleted (this->counter_))
return r.ptr_ != 0;
return this->ptr_ != r.ptr_;
}
template <class X, class ACE_LOCK> inline bool
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::operator!= (X *p) const
{
// A weak pointer must behave as though it is automatically set to null
// if the underlying object has been deleted.
if (COUNTER::object_was_deleted (this->counter_))
return p != 0;
return this->ptr_ != p;
}
template <class X, class ACE_LOCK> inline ACE_Strong_Bound_Ptr<X, ACE_LOCK>
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::operator-> (void) const
{
return ACE_Strong_Bound_Ptr<X, ACE_LOCK> (*this);
}
template <class X, class ACE_LOCK> inline ACE_Strong_Bound_Ptr<X, ACE_LOCK>
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::strong (void) const
{
return ACE_Strong_Bound_Ptr<X, ACE_LOCK> (*this);
}
template <class X, class ACE_LOCK> inline X*
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::unsafe_get (void) const
{
// We do not check if the object has been deleted, since this operation
// is defined to be unsafe!
return this->ptr_;
}
template <class X, class ACE_LOCK> inline bool
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::null (void) const
{
// A weak pointer must behave as though it is automatically set to null
// if the underlying object has been deleted.
if (COUNTER::object_was_deleted (this->counter_))
return true;
return this->ptr_ == 0;
}
template<class X, class ACE_LOCK> inline void
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::reset (X *p)
{
COUNTER *old_counter = this->counter_;
this->counter_ = COUNTER::create_weak ();
this->ptr_ = p;
COUNTER::detach_weak (old_counter);
}
template<class X, class ACE_LOCK> inline long
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::add_ref ()
{
return COUNTER::attach_strong (counter_);
}
template<class X, class ACE_LOCK> inline long
ACE_Weak_Bound_Ptr<X, ACE_LOCK>::remove_ref ()
{
long new_obj_ref_count = COUNTER::detach_strong (counter_);
if (new_obj_ref_count == 0)
{
delete this->ptr_;
this->ptr_ = 0;
}
return new_obj_ref_count;
}
ACE_END_VERSIONED_NAMESPACE_DECL
|