Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
5a5b9f8d
Commit
5a5b9f8d
authored
Mar 29, 2011
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tdb2: implement tdb_chainlock_read/tdb_chainunlock_read.
parent
63e80faf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
1 deletion
+49
-1
ccan/tdb2/hash.c
ccan/tdb2/hash.c
+21
-0
ccan/tdb2/tdb2.h
ccan/tdb2/tdb2.h
+28
-1
No files found.
ccan/tdb2/hash.c
View file @
5a5b9f8d
...
...
@@ -875,3 +875,24 @@ void tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key)
tdb_trace_1rec
(
tdb
,
"tdb_chainunlock"
,
key
);
tdb_unlock_hashes
(
tdb
,
lockstart
,
locksize
,
F_WRLCK
);
}
enum
TDB_ERROR
tdb_chainlock_read
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
)
{
return
tdb
->
last_error
=
chainlock
(
tdb
,
&
key
,
F_RDLCK
,
TDB_LOCK_WAIT
,
"tdb_chainlock_read"
);
}
void
tdb_chainunlock_read
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
)
{
uint64_t
h
=
tdb_hash
(
tdb
,
key
.
dptr
,
key
.
dsize
);
tdb_off_t
lockstart
,
locksize
;
unsigned
int
group
,
gbits
;
gbits
=
TDB_TOPLEVEL_HASH_BITS
-
TDB_HASH_GROUP_BITS
;
group
=
bits_from
(
h
,
64
-
gbits
,
gbits
);
lockstart
=
hlock_range
(
group
,
&
locksize
);
tdb_trace_1rec
(
tdb
,
"tdb_chainunlock_read"
,
key
);
tdb_unlock_hashes
(
tdb
,
lockstart
,
locksize
,
F_RDLCK
);
}
ccan/tdb2/tdb2.h
View file @
5a5b9f8d
...
...
@@ -395,7 +395,7 @@ enum TDB_ERROR tdb_nextkey(struct tdb_context *tdb, struct tdb_data *key);
* @tdb: the tdb context returned from tdb_open()
* @key: the key to lock.
*
* This prevents any
changes from
occurring to a group of keys including @key,
* This prevents any
access
occurring to a group of keys including @key,
* even if @key does not exist. This allows primitive atomic updates of
* records without using transactions.
*
...
...
@@ -417,6 +417,33 @@ enum TDB_ERROR tdb_chainlock(struct tdb_context *tdb, TDB_DATA key);
*/
void
tdb_chainunlock
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
);
/**
* tdb_chainlock_read - lock a record in the TDB, for reading
* @tdb: the tdb context returned from tdb_open()
* @key: the key to lock.
*
* This prevents any changes from occurring to a group of keys including @key,
* even if @key does not exist. This allows primitive atomic updates of
* records without using transactions.
*
* You cannot begin a transaction while holding a tdb_chainlock_read(), nor can
* you do any operations on any other keys in the database. This also means
* that you cannot hold more than one tdb_chainlock()/read() at a time.
*
* See Also:
* tdb_chainlock()
*/
enum
TDB_ERROR
tdb_chainlock_read
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
);
/**
* tdb_chainunlock_read - unlock a record in the TDB for reading
* @tdb: the tdb context returned from tdb_open()
* @key: the key to unlock.
*
* The key must have previously been locked by tdb_chainlock_read().
*/
void
tdb_chainunlock_read
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
);
/**
* tdb_lockall - lock the entire TDB
* @tdb: the tdb context returned from tdb_open()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment