diff options
author | Dan Nicholson <dbn@endlessos.org> | 2021-04-16 09:55:40 -0600 |
---|---|---|
committer | Dan Nicholson <dbn@endlessos.org> | 2021-06-05 09:15:32 -0600 |
commit | ccef9784d76c032b00ce5524fbfba39fa732b2fd (patch) | |
tree | d1d506170a8ec345960acaada2817deee8d582fe /src/libostree/ostree-repo-private.h | |
parent | eb09207e1abd7499bd92866cce1de6148d659a4a (diff) | |
download | ostree-ccef9784d76c032b00ce5524fbfba39fa732b2fd.tar.gz |
repo: Make locking per-OstreeRepo
Previously each thread maintained its own lock file descriptor
regardless of whether the thread was using the same `OstreeRepo` as
another thread. This was very safe but it made certain multithreaded
procedures difficult. For example, if a main thread took an exclusive
lock and then spawned worker threads, it would deadlock if one of the
worker threads tried to acquire the lock.
This moves the file descriptor from thread local storage to the
`OstreeRepo` structure so that threads using the same `OstreeRepo` can
share the lock. A mutex guards against threads altering the lock state
concurrently.
Fixes: #2344
Diffstat (limited to 'src/libostree/ostree-repo-private.h')
-rw-r--r-- | src/libostree/ostree-repo-private.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h index 20af1b38..0cd9d8bb 100644 --- a/src/libostree/ostree-repo-private.h +++ b/src/libostree/ostree-repo-private.h @@ -104,6 +104,13 @@ typedef struct { fsblkcnt_t max_blocks; } OstreeRepoTxn; +typedef struct { + GMutex mutex; /* All other members should only be accessed with this held */ + int fd; /* The open file or flock file descriptor */ + guint shared; /* Number of shared locks curently held */ + guint exclusive; /* Number of exclusive locks currently held */ +} OstreeRepoLock; + typedef enum { _OSTREE_FEATURE_NO, _OSTREE_FEATURE_MAYBE, @@ -159,6 +166,8 @@ struct OstreeRepo { GWeakRef sysroot; /* Weak to avoid a circular ref; see also `is_system` */ char *remotes_config_dir; + OstreeRepoLock lock; + GMutex txn_lock; OstreeRepoTxn txn; gboolean txn_locked; |