|
From: CVS C. to T. <the...@li...> - 2019-03-30 22:11:31
|
Revision: 739
http://sourceforge.net/p/themis/code/739
Author: mark_hellegers
Date: 2019-03-30 22:11:29 +0000 (Sat, 30 Mar 2019)
Log Message:
-----------
- Use a real lock for the write lock, so nobody else can acquire the lock while we have it.
- Add a new cache user properly, so it gets registered with the right usertoken.
- Use the return value from FindUser, so we can set the right writelockowner.
Modified Paths:
--------------
trunk/themis/common/cacheobject.cpp
trunk/themis/common/cacheobject.h
Modified: trunk/themis/common/cacheobject.cpp
===================================================================
--- trunk/themis/common/cacheobject.cpp 2018-03-12 21:55:53 UTC (rev 738)
+++ trunk/themis/common/cacheobject.cpp 2019-03-30 22:11:29 UTC (rev 739)
@@ -148,7 +148,7 @@
BAutolock alock(lock);
if (alock.IsLocked()) {
if (!IsUsedBy(usertoken)) {
- ulist->AddItem(new CacheUser(usertoken));
+ ulist->AddItem(new CacheUser(0, usertoken));
UpdateAccessTime();
}
@@ -203,14 +203,15 @@
bool CacheObject::AcquireWriteLock(uint32 usertoken) {
bool successful=false;
- BAutolock alock(lock);
- if (alock.IsLocked()) {
+ writeLock.Lock();
+ if (writeLock.IsLocked()) {
CacheUser *user=FindUser(usertoken);
if (user==NULL) {
AddUser(usertoken);
- FindUser(usertoken);
+ user = FindUser(usertoken);
+
}
if (writelockowner==NULL) {
@@ -255,12 +256,11 @@
return successful;
}
void CacheObject::ReleaseWriteLock(uint32 usertoken) {
- BAutolock alock(lock);
- if (alock.IsLocked()) {
- if (writelockowner!=NULL) {
- if (writelockowner->Token()==usertoken) {
- writelockowner=NULL;
- }
+
+ if (writelockowner!=NULL) {
+ if (writelockowner->Token()==usertoken) {
+ writelockowner=NULL;
+ writeLock.Unlock();
}
}
Modified: trunk/themis/common/cacheobject.h
===================================================================
--- trunk/themis/common/cacheobject.h 2018-03-12 21:55:53 UTC (rev 738)
+++ trunk/themis/common/cacheobject.h 2019-03-30 22:11:29 UTC (rev 739)
@@ -58,6 +58,7 @@
//! Pointers to the next and previous items in the linked list respectively.
CacheObject *next,*prev;
BLocker lock;
+ BLocker writeLock;
time_t creation_time;
time_t last_access_time;
virtual void UpdateAccessTime();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|