Added lock and unlock method, plus a method to get
access to the actual data. This allows custom locking (e.g. a synchronised vector might want a [] and erase operation to be locked, to be sure to copy a element before erasing it). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7390 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
946526662a
commit
c164bfefc0
@ -71,7 +71,30 @@ public:
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
return v;
|
||||
} // get
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns a reference to the original data file. NOTE: all access to
|
||||
* the data files happen without mutex protection, so calls to lock
|
||||
* and unlock are necessary. This method is useful in cases that several
|
||||
* operations on the class must happen atomic.
|
||||
*/
|
||||
TYPE &getData()
|
||||
{
|
||||
return m_data;
|
||||
} // getData
|
||||
// ------------------------------------------------------------------------
|
||||
const TYPE &getData() const
|
||||
{
|
||||
return m_data;
|
||||
} // getData
|
||||
// ------------------------------------------------------------------------
|
||||
/** Locks the mutex. Note that calls to get() or set() will fail, since
|
||||
* they will try to lock the mutex as well!
|
||||
*/
|
||||
void lock() { pthread_mutex_lock(&m_mutex); }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Unlocks the mutex.
|
||||
*/
|
||||
void unlock() {pthread_mutex_unlock(&m_mutex); }
|
||||
private:
|
||||
// Make sure that no actual copying is taking place
|
||||
// ------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user