File tree 6 files changed +44
-43
lines changed
packages/torrent-repository
6 files changed +44
-43
lines changed Original file line number Diff line number Diff line change 1
1
use std:: sync:: Arc ;
2
2
3
+ use repository:: rw_lock_std:: RwLockStd ;
4
+ use repository:: rw_lock_tokio:: RwLockTokio ;
3
5
use repository:: skip_map_mutex_std:: CrossbeamSkipList ;
4
6
use torrust_tracker_clock:: clock;
5
7
@@ -10,12 +12,12 @@ pub type EntrySingle = entry::Torrent;
10
12
pub type EntryMutexStd = Arc < std:: sync:: Mutex < entry:: Torrent > > ;
11
13
pub type EntryMutexTokio = Arc < tokio:: sync:: Mutex < entry:: Torrent > > ;
12
14
13
- pub type TorrentsRwLockStd = repository :: RwLockStd < EntrySingle > ;
14
- pub type TorrentsRwLockStdMutexStd = repository :: RwLockStd < EntryMutexStd > ;
15
- pub type TorrentsRwLockStdMutexTokio = repository :: RwLockStd < EntryMutexTokio > ;
16
- pub type TorrentsRwLockTokio = repository :: RwLockTokio < EntrySingle > ;
17
- pub type TorrentsRwLockTokioMutexStd = repository :: RwLockTokio < EntryMutexStd > ;
18
- pub type TorrentsRwLockTokioMutexTokio = repository :: RwLockTokio < EntryMutexTokio > ;
15
+ pub type TorrentsRwLockStd = RwLockStd < EntrySingle > ;
16
+ pub type TorrentsRwLockStdMutexStd = RwLockStd < EntryMutexStd > ;
17
+ pub type TorrentsRwLockStdMutexTokio = RwLockStd < EntryMutexTokio > ;
18
+ pub type TorrentsRwLockTokio = RwLockTokio < EntrySingle > ;
19
+ pub type TorrentsRwLockTokioMutexStd = RwLockTokio < EntryMutexStd > ;
20
+ pub type TorrentsRwLockTokioMutexTokio = RwLockTokio < EntryMutexTokio > ;
19
21
20
22
pub type TorrentsSkipMapMutexStd = CrossbeamSkipList < EntryMutexStd > ;
21
23
Original file line number Diff line number Diff line change @@ -41,37 +41,3 @@ pub trait RepositoryAsync<T>: Debug + Default + Sized + 'static {
41
41
peer : & peer:: Peer ,
42
42
) -> impl std:: future:: Future < Output = ( bool , SwarmMetadata ) > + Send ;
43
43
}
44
-
45
- #[ derive( Default , Debug ) ]
46
- pub struct RwLockStd < T > {
47
- torrents : std:: sync:: RwLock < std:: collections:: BTreeMap < InfoHash , T > > ,
48
- }
49
-
50
- #[ derive( Default , Debug ) ]
51
- pub struct RwLockTokio < T > {
52
- torrents : tokio:: sync:: RwLock < std:: collections:: BTreeMap < InfoHash , T > > ,
53
- }
54
-
55
- impl < T > RwLockStd < T > {
56
- /// # Panics
57
- ///
58
- /// Panics if unable to get a lock.
59
- pub fn write (
60
- & self ,
61
- ) -> std:: sync:: RwLockWriteGuard < ' _ , std:: collections:: BTreeMap < torrust_tracker_primitives:: info_hash:: InfoHash , T > > {
62
- self . torrents . write ( ) . expect ( "it should get lock" )
63
- }
64
- }
65
-
66
- impl < T > RwLockTokio < T > {
67
- pub fn write (
68
- & self ,
69
- ) -> impl std:: future:: Future <
70
- Output = tokio:: sync:: RwLockWriteGuard <
71
- ' _ ,
72
- std:: collections:: BTreeMap < torrust_tracker_primitives:: info_hash:: InfoHash , T > ,
73
- > ,
74
- > {
75
- self . torrents . write ( )
76
- }
77
- }
Original file line number Diff line number Diff line change @@ -11,6 +11,22 @@ use super::Repository;
11
11
use crate :: entry:: Entry ;
12
12
use crate :: { EntrySingle , TorrentsRwLockStd } ;
13
13
14
+ #[ derive( Default , Debug ) ]
15
+ pub struct RwLockStd < T > {
16
+ pub ( crate ) torrents : std:: sync:: RwLock < std:: collections:: BTreeMap < InfoHash , T > > ,
17
+ }
18
+
19
+ impl < T > RwLockStd < T > {
20
+ /// # Panics
21
+ ///
22
+ /// Panics if unable to get a lock.
23
+ pub fn write (
24
+ & self ,
25
+ ) -> std:: sync:: RwLockWriteGuard < ' _ , std:: collections:: BTreeMap < torrust_tracker_primitives:: info_hash:: InfoHash , T > > {
26
+ self . torrents . write ( ) . expect ( "it should get lock" )
27
+ }
28
+ }
29
+
14
30
impl TorrentsRwLockStd {
15
31
fn get_torrents < ' a > ( & ' a self ) -> std:: sync:: RwLockReadGuard < ' a , std:: collections:: BTreeMap < InfoHash , EntrySingle > >
16
32
where
Original file line number Diff line number Diff line change @@ -11,6 +11,24 @@ use super::RepositoryAsync;
11
11
use crate :: entry:: Entry ;
12
12
use crate :: { EntrySingle , TorrentsRwLockTokio } ;
13
13
14
+ #[ derive( Default , Debug ) ]
15
+ pub struct RwLockTokio < T > {
16
+ pub ( crate ) torrents : tokio:: sync:: RwLock < std:: collections:: BTreeMap < InfoHash , T > > ,
17
+ }
18
+
19
+ impl < T > RwLockTokio < T > {
20
+ pub fn write (
21
+ & self ,
22
+ ) -> impl std:: future:: Future <
23
+ Output = tokio:: sync:: RwLockWriteGuard <
24
+ ' _ ,
25
+ std:: collections:: BTreeMap < torrust_tracker_primitives:: info_hash:: InfoHash , T > ,
26
+ > ,
27
+ > {
28
+ self . torrents . write ( )
29
+ }
30
+ }
31
+
14
32
impl TorrentsRwLockTokio {
15
33
async fn get_torrents < ' a > ( & ' a self ) -> tokio:: sync:: RwLockReadGuard < ' a , std:: collections:: BTreeMap < InfoHash , EntrySingle > >
16
34
where
Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ use torrust_tracker_primitives::info_hash::InfoHash;
8
8
use torrust_tracker_primitives:: pagination:: Pagination ;
9
9
use torrust_tracker_primitives:: { NumberOfBytes , PersistentTorrents } ;
10
10
use torrust_tracker_torrent_repository:: entry:: Entry as _;
11
- use torrust_tracker_torrent_repository:: repository:: { RwLockStd , RwLockTokio } ;
11
+ use torrust_tracker_torrent_repository:: repository:: rw_lock_std:: RwLockStd ;
12
+ use torrust_tracker_torrent_repository:: repository:: rw_lock_tokio:: RwLockTokio ;
12
13
use torrust_tracker_torrent_repository:: EntrySingle ;
13
14
14
15
use crate :: common:: repo:: Repo ;
Original file line number Diff line number Diff line change 25
25
//! - The number of peers that have NOT completed downloading the torrent and are still active, that means they are actively participating in the network.
26
26
//! Peer that don not have a full copy of the torrent data are called "leechers".
27
27
//!
28
-
29
28
use torrust_tracker_torrent_repository:: TorrentsSkipMapMutexStd ;
30
29
31
- //pub type Torrents = TorrentsRwLockStdMutexStd; // Currently Used
32
30
pub type Torrents = TorrentsSkipMapMutexStd ; // Currently Used
You can’t perform that action at this time.
0 commit comments