Revert "Remove gencache_[un]lock_entry"
authorVolker Lendecke <vl@samba.org>
Fri, 11 Jul 2008 15:44:09 +0000 (17:44 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 11 Jul 2008 15:53:25 +0000 (17:53 +0200)
This reverts commit 7a5a575ffe5196caecedc93970a25abfbe6f8059.
(This used to be commit 62e444dd50ae974c2ab9a553cdf7f188a8f2c538)

source3/include/proto.h
source3/lib/gencache.c
source3/libsmb/dsgetdcname.c

index 278a42a9742aa9f6a026498469c5237db7a91421..9958c91dca4dd1fa5e6bce910cece1400585d94f 100644 (file)
@@ -606,6 +606,8 @@ bool gencache_get_data_blob(const char *keystr, DATA_BLOB *blob, bool *expired);
 bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob, time_t timeout);
 void gencache_iterate(void (*fn)(const char* key, const char *value, time_t timeout, void* dptr),
                       void* data, const char* keystr_pattern);
+int gencache_lock_entry( const char *key );
+void gencache_unlock_entry( const char *key );
 
 /* The following definitions come from lib/genrand.c  */
 
index a55b2ab9ba9ce2f544bafac1eb7d3f0ad88bb2b4..1b4342a62bb44af072f317fa96625aa38465e216 100644 (file)
@@ -484,3 +484,28 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time
        
        tdb_search_list_free(first_node);
 }
+
+/********************************************************************
+ lock a key
+********************************************************************/
+
+int gencache_lock_entry( const char *key )
+{
+       if (!gencache_init())
+               return -1;
+       
+       return tdb_lock_bystring(cache, key);
+}
+
+/********************************************************************
+ unlock a key
+********************************************************************/
+
+void gencache_unlock_entry( const char *key )
+{
+       if (!gencache_init())
+               return;
+       
+       tdb_unlock_bystring(cache, key);
+       return;
+}
index afc87030d0881149a7961545d13ca609cb6dc3cb..2a445cbd5a7b40cee5da72216ea8cb2e2955c5ff 100644 (file)
@@ -159,6 +159,7 @@ static NTSTATUS dsgetdcname_cache_store(TALLOC_CTX *mem_ctx,
 {
        time_t expire_time;
        char *key;
+       bool ret = false;
 
        if (!gencache_init()) {
                return NT_STATUS_INTERNAL_DB_ERROR;
@@ -171,8 +172,15 @@ static NTSTATUS dsgetdcname_cache_store(TALLOC_CTX *mem_ctx,
 
        expire_time = time(NULL) + DSGETDCNAME_CACHE_TTL;
 
-       return gencache_set_data_blob(key, blob, expire_time)
-               ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
+       if (gencache_lock_entry(key) != 0) {
+               return NT_STATUS_LOCK_NOT_GRANTED;
+       }
+
+       ret = gencache_set_data_blob(key, blob, expire_time);
+
+       gencache_unlock_entry(key);
+
+       return ret ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
 }
 
 /****************************************************************