Fix non-thread-safe code.

2.0
castano 15 years ago
parent dc8fe745c0
commit 82f99ea9d2

@ -115,6 +115,7 @@ namespace nv
{
NVCORE_API void dumpInfo();
// These functions are not thread safe.
NVCORE_API void setMessageHandler( MessageHandler * messageHandler );
NVCORE_API void resetMessageHandler();

@ -545,8 +545,6 @@ const char * Path::extension(const char * str)
}
// static
String String::s_null(String::null);
/// Clone this string
String String::clone() const
@ -557,13 +555,13 @@ String String::clone() const
void String::setString(const char * str)
{
if( str == NULL ) {
data = s_null.data;
if (str == NULL) {
data = NULL;
}
else {
allocString( str );
addRef();
}
addRef();
}
void String::setString(const char * str, int length)
@ -576,11 +574,11 @@ void String::setString(const char * str, int length)
void String::setString(const StringBuilder & str)
{
if( str.str() == NULL ) {
data = s_null.data;
if (str.str() == NULL) {
data = NULL;
}
else {
allocString(str);
addRef();
}
addRef();
}

@ -151,15 +151,14 @@ namespace nv
/// Constructs a null string. @sa isNull()
String()
{
data = s_null.data;
addRef();
data = NULL;
}
/// Constructs a shared copy of str.
String(const String & str)
{
data = str.data;
addRef();
if (data != NULL) addRef();
}
/// Constructs a shared string from a standard string.
@ -256,7 +255,7 @@ namespace nv
}
/// Returns true if this string is the null string.
bool isNull() const { nvDebugCheck(data != NULL); return data == s_null.data; }
bool isNull() const { return data == NULL; }
/// Return the exact length.
uint length() const { nvDebugCheck(data != NULL); return uint(strlen(data)); }
@ -265,44 +264,45 @@ namespace nv
uint hash() const { nvDebugCheck(data != NULL); return strHash(data); }
/// const char * cast operator.
operator const char * () const { nvDebugCheck(data != NULL); return data; }
operator const char * () const { return data; }
/// Get string pointer.
const char * str() const { nvDebugCheck(data != NULL); return data; }
const char * str() const { return data; }
private:
enum null_t { null };
// Private constructor for null string.
String(null_t) {
setString("");
}
// Add reference count.
void addRef() {
nvDebugCheck(data != NULL);
setRefCount(getRefCount() + 1);
void addRef()
{
if (data != NULL)
{
setRefCount(getRefCount() + 1);
}
}
// Decrease reference count.
void release() {
nvDebugCheck(data != NULL);
const uint16 count = getRefCount();
setRefCount(count - 1);
if( count - 1 == 0 ) {
mem::free(data - 2);
data = NULL;
void release()
{
if (data != NULL)
{
const uint16 count = getRefCount();
setRefCount(count - 1);
if (count - 1 == 0) {
mem::free(data - 2);
data = NULL;
}
}
}
uint16 getRefCount() const {
uint16 getRefCount() const
{
nvDebugCheck(data != NULL);
return *reinterpret_cast<const uint16 *>(data - 2);
}
void setRefCount(uint16 count) {
nvDebugCheck(data != NULL);
nvCheck(count < 0xFFFF);
*reinterpret_cast<uint16 *>(const_cast<char *>(data - 2)) = uint16(count);
}
@ -341,8 +341,6 @@ namespace nv
private:
NVCORE_API static String s_null;
const char * data;
};

Loading…
Cancel
Save