extensions/sqlite/driver/SqDatabase.cpp
changeset 4040 b6924c1a1d71
parent 3947 999d29e113db
     1.1 --- a/extensions/sqlite/driver/SqDatabase.cpp	Fri Aug 23 00:18:12 2013 -0700
     1.2 +++ b/extensions/sqlite/driver/SqDatabase.cpp	Fri Aug 23 00:18:13 2013 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /**
     1.5 - * vim: set ts=4 :
     1.6 + * vim: set ts=4 sw=4 tw=99 noet :
     1.7   * =============================================================================
     1.8   * SourceMod SQLite Extension
     1.9   * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
    1.10 @@ -34,47 +34,25 @@
    1.11  #include "SqQuery.h"
    1.12  
    1.13  SqDatabase::SqDatabase(sqlite3 *sq3, bool persistent) : 
    1.14 -	m_sq3(sq3), m_refcount(1), m_pFullLock(NULL), m_Persistent(persistent)
    1.15 +	m_sq3(sq3), m_Persistent(persistent)
    1.16  {
    1.17 -	m_pRefLock = threader->MakeMutex();
    1.18  }
    1.19  
    1.20  SqDatabase::~SqDatabase()
    1.21  {
    1.22 -	m_pRefLock->DestroyThis();
    1.23 -	if (m_pFullLock)
    1.24 -	{
    1.25 -		m_pFullLock->DestroyThis();
    1.26 -	}
    1.27 +	if (m_Persistent)
    1.28 +		g_SqDriver.RemovePersistent(this);
    1.29  	sqlite3_close(m_sq3);
    1.30  }
    1.31  
    1.32  void SqDatabase::IncReferenceCount()
    1.33  {
    1.34 -	m_pRefLock->Lock();
    1.35 -	m_refcount++;
    1.36 -	m_pRefLock->Unlock();
    1.37 +	AddRef();
    1.38  }
    1.39  
    1.40  bool SqDatabase::Close()
    1.41  {
    1.42 -	m_pRefLock->Lock();
    1.43 -	if (m_refcount > 1)
    1.44 -	{
    1.45 -		m_refcount--;
    1.46 -		m_pRefLock->Unlock();
    1.47 -		return false;
    1.48 -	}
    1.49 -	m_pRefLock->Unlock();
    1.50 -
    1.51 -	if (m_Persistent)
    1.52 -	{
    1.53 -		g_SqDriver.RemovePersistent(this);
    1.54 -	}
    1.55 -
    1.56 -	delete this;
    1.57 -
    1.58 -	return true;
    1.59 +	return !Release();
    1.60  }
    1.61  
    1.62  const char *SqDatabase::GetError(int *errorCode/* =NULL */)
    1.63 @@ -84,26 +62,17 @@
    1.64  
    1.65  bool SqDatabase::LockForFullAtomicOperation()
    1.66  {
    1.67 -	if (!m_pFullLock)
    1.68 -	{
    1.69 -		m_pFullLock = threader->MakeMutex();
    1.70 -		if (!m_pFullLock)
    1.71 -		{
    1.72 -			return false;
    1.73 -		}
    1.74 -	}
    1.75 +	if (!m_FullLock)
    1.76 +		m_FullLock = new ke::Mutex();
    1.77  
    1.78 -	m_pFullLock->Lock();
    1.79 -
    1.80 +	m_FullLock->Lock();
    1.81  	return true;
    1.82  }
    1.83  
    1.84  void SqDatabase::UnlockFromFullAtomicOperation()
    1.85  {
    1.86 -	if (m_pFullLock)
    1.87 -	{
    1.88 -		m_pFullLock->Unlock();
    1.89 -	}
    1.90 +	if (m_FullLock)
    1.91 +		m_FullLock->Unlock();
    1.92  }
    1.93  
    1.94  IDBDriver *SqDatabase::GetDriver()
    1.95 @@ -259,4 +228,4 @@
    1.96  {
    1.97  	// sqlite only supports utf8 and utf16 - by the time the database is created. It's too late here.
    1.98  	return false;
    1.99 -}
   1.100 \ No newline at end of file
   1.101 +}