+ovsdb_session_destroy(struct ovsdb_session *session)
+{
+ ovs_assert(hmap_is_empty(&session->waiters));
+ hmap_destroy(&session->waiters);
+}
+
+/* Searches 'session' for an ovsdb_lock_waiter named 'lock_name' and returns
+ * it if it finds one, otherwise NULL. */
+struct ovsdb_lock_waiter *
+ovsdb_session_get_lock_waiter(const struct ovsdb_session *session,
+ const char *lock_name)
+{
+ struct ovsdb_lock_waiter *waiter;
+
+ HMAP_FOR_EACH_WITH_HASH (waiter, session_node, hash_string(lock_name, 0),
+ &session->waiters) {
+ if (!strcmp(lock_name, waiter->lock_name)) {
+ return waiter;
+ }
+ }
+ return NULL;
+}
+
+/* Returns the waiter that owns 'lock'.
+ *
+ * A lock always has an owner, so this function will never return NULL. */
+struct ovsdb_lock_waiter *
+ovsdb_lock_get_owner(const struct ovsdb_lock *lock)
+{
+ return CONTAINER_OF(list_front(&lock->waiters),
+ struct ovsdb_lock_waiter, lock_node);
+}
+
+/* Removes 'waiter' from its lock's list. This means that, if 'waiter' was
+ * formerly the owner of its lock, then it no longer owns it.
+ *
+ * Returns the session that now owns 'waiter'. This is NULL if 'waiter' was
+ * the lock's owner and no other sessions were waiting for the lock. In this
+ * case, the lock has been destroyed, so the caller must be sure not to refer
+ * to it again. A nonnull return value reflects a change in the lock's
+ * ownership if and only if 'waiter' formerly owned the lock. */
+struct ovsdb_session *
+ovsdb_lock_waiter_remove(struct ovsdb_lock_waiter *waiter)
+{
+ struct ovsdb_lock *lock = waiter->lock;
+
+ list_remove(&waiter->lock_node);
+ waiter->lock = NULL;
+
+ if (list_is_empty(&lock->waiters)) {
+ hmap_remove(&lock->server->locks, &lock->hmap_node);
+ free(lock->name);
+ free(lock);
+ return NULL;
+ }
+
+ return ovsdb_lock_get_owner(lock)->session;
+}
+
+/* Destroys 'waiter', which must have already been removed from its lock's
+ * waiting list with ovsdb_lock_waiter_remove().
+ *
+ * Removing and destroying locks are decoupled because a lock initially created
+ * by the "steal" request, that is later stolen by another client, remains in
+ * the database session until the database client sends an "unlock" request. */
+void
+ovsdb_lock_waiter_destroy(struct ovsdb_lock_waiter *waiter)
+{
+ ovs_assert(!waiter->lock);
+ hmap_remove(&waiter->session->waiters, &waiter->session_node);
+ free(waiter->lock_name);
+ free(waiter);
+}
+
+/* Returns true if 'waiter' owns its associated lock. */
+bool
+ovsdb_lock_waiter_is_owner(const struct ovsdb_lock_waiter *waiter)