mirror of
https://review.haiku-os.org/buildtools
synced 2025-01-31 18:44:48 +01:00
[taken from the Zeta-headers]
Fix a race condition in std::string allocation/deallocation code. git-svn-id: file:///srv/svn/repos/haiku/trunk/buildtools@9614 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
98cc8eab03
commit
d2046ed9e3
@ -61,6 +61,13 @@ extern void __length_error (const char *);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __BEOS__
|
||||
// Needed for atomic_add():
|
||||
typedef long int32;
|
||||
typedef volatile long vint32;
|
||||
extern "C" int32 atomic_add(vint32* value, int32 addvalue);
|
||||
#endif /* __BEOS__ */
|
||||
|
||||
template <class charT, class traits = string_char_traits<charT>,
|
||||
class Allocator = alloc >
|
||||
class basic_string
|
||||
@ -72,6 +79,10 @@ private:
|
||||
|
||||
charT* data () { return reinterpret_cast<charT *>(this + 1); }
|
||||
charT& operator[] (size_t s) { return data () [s]; }
|
||||
#ifdef __BEOS__
|
||||
charT* grab () { if (selfish) return clone (); atomic_add((vint32*) &ref, 1); return data (); }
|
||||
void release() { if (atomic_add((int32*) &ref, -1) == 1) delete this; }
|
||||
#else
|
||||
charT* grab () { if (selfish) return clone (); ++ref; return data (); }
|
||||
#if defined __i486__ || defined __i586__ || defined __i686__
|
||||
void release ()
|
||||
@ -108,7 +119,7 @@ private:
|
||||
#else
|
||||
void release () { if (--ref == 0) delete this; }
|
||||
#endif
|
||||
|
||||
#endif /* __BEOS__ */
|
||||
inline static void * operator new (size_t, size_t);
|
||||
inline static void operator delete (void *);
|
||||
inline static Rep* create (size_t);
|
||||
|
Loading…
x
Reference in New Issue
Block a user