summaryrefslogtreecommitdiff
path: root/ot_mutex.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_mutex.c')
-rw-r--r--ot_mutex.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/ot_mutex.c b/ot_mutex.c
index a28144b..8094e99 100644
--- a/ot_mutex.c
+++ b/ot_mutex.c
@@ -24,6 +24,7 @@
24 24
25/* Our global all torrents list */ 25/* Our global all torrents list */
26static ot_vector all_torrents[OT_BUCKET_COUNT]; 26static ot_vector all_torrents[OT_BUCKET_COUNT];
27static size_t g_torrent_count;
27 28
28/* Bucket Magic */ 29/* Bucket Magic */
29static int bucket_locklist[ OT_MAX_THREADS ]; 30static int bucket_locklist[ OT_MAX_THREADS ];
@@ -87,15 +88,24 @@ ot_vector *mutex_bucket_lock_by_hash( ot_hash *hash ) {
87 return all_torrents + bucket; 88 return all_torrents + bucket;
88} 89}
89 90
90void mutex_bucket_unlock( int bucket ) { 91void mutex_bucket_unlock( int bucket, int delta_torrentcount ) {
91 pthread_mutex_lock( &bucket_mutex ); 92 pthread_mutex_lock( &bucket_mutex );
92 bucket_remove( bucket ); 93 bucket_remove( bucket );
94 g_torrent_count += delta_torrentcount;
93 pthread_cond_broadcast( &bucket_being_unlocked ); 95 pthread_cond_broadcast( &bucket_being_unlocked );
94 pthread_mutex_unlock( &bucket_mutex ); 96 pthread_mutex_unlock( &bucket_mutex );
95} 97}
96 98
97void mutex_bucket_unlock_by_hash( ot_hash *hash ) { 99void mutex_bucket_unlock_by_hash( ot_hash *hash, int delta_torrentcount ) {
98 mutex_bucket_unlock( uint32_read_big( (char*)*hash ) >> OT_BUCKET_COUNT_SHIFT ); 100 mutex_bucket_unlock( uint32_read_big( (char*)*hash ) >> OT_BUCKET_COUNT_SHIFT, delta_torrentcount );
101}
102
103size_t mutex_get_torrent_count( ) {
104 size_t torrent_count;
105 pthread_mutex_lock( &bucket_mutex );
106 torrent_count = g_torrent_count;
107 pthread_mutex_unlock( &bucket_mutex );
108 return torrent_count;
99} 109}
100 110
101/* TaskQueue Magic */ 111/* TaskQueue Magic */