summaryrefslogtreecommitdiff
path: root/source3/locking
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-04-13 22:22:54 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:16:22 -0500
commit713eaf1d67d9ef967fb4526113e2a3ba3dd5e229 (patch)
tree04e1b26cd6c6c1fa8c1bd0c1c0a34c6abebd15f9 /source3/locking
parent1f19676903021bed4cc42356230c6c31ff0577c4 (diff)
downloadsamba-713eaf1d67d9ef967fb4526113e2a3ba3dd5e229.tar.gz
samba-713eaf1d67d9ef967fb4526113e2a3ba3dd5e229.tar.bz2
samba-713eaf1d67d9ef967fb4526113e2a3ba3dd5e229.zip
r15083: Using talloc with destructors is nice and all, but in this
case it's in a performace critical path and it *hurts* us. Go back to plain malloc/free with an explicit destructor call. Jeremy. (This used to be commit 1c99aed563c29e1b3d70939878af747a0660bfec)
Diffstat (limited to 'source3/locking')
-rw-r--r--source3/locking/brlock.c14
-rw-r--r--source3/locking/locking.c24
2 files changed, 17 insertions, 21 deletions
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index 60c94c2b98..e6f0dd1c72 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -1304,10 +1304,8 @@ int brl_forall(BRLOCK_FN(fn))
Unlock the record.
********************************************************************/
-static int byte_range_lock_destructor(void *p)
+int byte_range_lock_destructor(struct byte_range_lock *br_lck)
{
- struct byte_range_lock *br_lck =
- talloc_get_type_abort(p, struct byte_range_lock);
TDB_DATA key;
key.dptr = (char *)&br_lck->key;
@@ -1336,6 +1334,7 @@ static int byte_range_lock_destructor(void *p)
tdb_chainunlock(tdb, key);
SAFE_FREE(br_lck->lock_data);
+ SAFE_FREE(br_lck);
return 0;
}
@@ -1344,12 +1343,11 @@ static int byte_range_lock_destructor(void *p)
Leave the record locked.
********************************************************************/
-struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
- files_struct *fsp)
+struct byte_range_lock *brl_get_locks(files_struct *fsp)
{
TDB_DATA key;
TDB_DATA data;
- struct byte_range_lock *br_lck = TALLOC_P(mem_ctx, struct byte_range_lock);
+ struct byte_range_lock *br_lck = SMB_MALLOC_P(struct byte_range_lock);
if (br_lck == NULL) {
return NULL;
@@ -1367,12 +1365,10 @@ struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
if (tdb_chainlock(tdb, key) != 0) {
DEBUG(3, ("Could not lock byte range lock entry\n"));
- TALLOC_FREE(br_lck);
+ SAFE_FREE(br_lck);
return NULL;
}
- talloc_set_destructor(br_lck, byte_range_lock_destructor);
-
data = tdb_fetch(tdb, key);
br_lck->lock_data = (void *)data.dptr;
br_lck->num_locks = data.dsize / sizeof(struct lock_struct);
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 0b3f625d03..2b6023c0c4 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -100,7 +100,7 @@ BOOL is_locked(files_struct *fsp,
DEBUG(10,("is_locked: optimisation - level II oplock on file %s\n", fsp->fsp_name ));
ret = False;
} else {
- struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+ struct byte_range_lock *br_lck = brl_get_locks(fsp);
if (!br_lck) {
return False;
}
@@ -111,10 +111,10 @@ BOOL is_locked(files_struct *fsp,
count,
lock_type,
lock_flav);
- TALLOC_FREE(br_lck);
+ byte_range_lock_destructor(br_lck);
}
} else {
- struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+ struct byte_range_lock *br_lck = brl_get_locks(fsp);
if (!br_lck) {
return False;
}
@@ -125,7 +125,7 @@ BOOL is_locked(files_struct *fsp,
count,
lock_type,
lock_flav);
- TALLOC_FREE(br_lck);
+ byte_range_lock_destructor(br_lck);
}
DEBUG(10,("is_locked: flavour = %s brl start=%.0f len=%.0f %s for fnum %d file %s\n",
@@ -158,7 +158,7 @@ NTSTATUS query_lock(files_struct *fsp,
return NT_STATUS_OK;
}
- br_lck = brl_get_locks(NULL, fsp);
+ br_lck = brl_get_locks(fsp);
if (!br_lck) {
return NT_STATUS_NO_MEMORY;
}
@@ -171,7 +171,7 @@ NTSTATUS query_lock(files_struct *fsp,
plock_type,
lock_flav);
- TALLOC_FREE(br_lck);
+ byte_range_lock_destructor(br_lck);
return status;
}
@@ -204,7 +204,7 @@ NTSTATUS do_lock(files_struct *fsp,
lock_flav_name(lock_flav), lock_type_name(lock_type),
(double)offset, (double)count, fsp->fnum, fsp->fsp_name ));
- br_lck = brl_get_locks(NULL, fsp);
+ br_lck = brl_get_locks(fsp);
if (!br_lck) {
return NT_STATUS_NO_MEMORY;
}
@@ -218,7 +218,7 @@ NTSTATUS do_lock(files_struct *fsp,
lock_flav,
my_lock_ctx);
- TALLOC_FREE(br_lck);
+ byte_range_lock_destructor(br_lck);
return status;
}
@@ -305,7 +305,7 @@ NTSTATUS do_unlock(files_struct *fsp,
DEBUG(10,("do_unlock: unlock start=%.0f len=%.0f requested for fnum %d file %s\n",
(double)offset, (double)count, fsp->fnum, fsp->fsp_name ));
- br_lck = brl_get_locks(NULL, fsp);
+ br_lck = brl_get_locks(fsp);
if (!br_lck) {
return NT_STATUS_NO_MEMORY;
}
@@ -317,7 +317,7 @@ NTSTATUS do_unlock(files_struct *fsp,
count,
lock_flav);
- TALLOC_FREE(br_lck);
+ byte_range_lock_destructor(br_lck);
if (!ok) {
DEBUG(10,("do_unlock: returning ERRlock.\n" ));
@@ -343,10 +343,10 @@ void locking_close_file(files_struct *fsp)
* Just release all the brl locks, no need to release individually.
*/
- br_lck = brl_get_locks(NULL,fsp);
+ br_lck = brl_get_locks(fsp);
if (br_lck) {
brl_close_fnum(br_lck, pid);
- TALLOC_FREE(br_lck);
+ byte_range_lock_destructor(br_lck);
}
if(lp_posix_locking(SNUM(fsp->conn))) {