summaryrefslogtreecommitdiff
path: root/ot_mutex.c
diff options
context:
space:
mode:
authorerdgeist <>2009-01-02 08:57:53 +0000
committererdgeist <>2009-01-02 08:57:53 +0000
commit2df09905f5540fee096d48a92cb0c42558498a12 (patch)
tree68eab61d29719400972485de395dd0465467aea6 /ot_mutex.c
parent548e2b8338b5ee8d24fa928e833f345bb5cb6f0e (diff)
* opentracker now drops permissions in correct order and really chroots() if ran as root
* lock passing between add_peer_to_torrent and return_peers_for_torrent is now avoided by providing a more general add_peer_to_torrent_and_return_peers function that can be used with NULL parameters to not return any peers (in sync case) * in order to keep a fast overview how many torrents opentracker maintains, every mutex_bucket_unlock operation expects an additional integer parameter that tells ot_mutex.c how many torrents have been added or removed. A function mutex_get_torrent_count has been introduced.
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 */