summaryrefslogtreecommitdiff
path: root/ot_mutex.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2009-01-02 08:57:49 +0000
committerDirk Engling <erdgeist@erdgeist.org>2009-01-02 08:57:49 +0000
commit49ec59cbbe332f3c7cb5237799b1d77bcda92c0e (patch)
tree84bc6d4c3c7d8fd2443470867236308a35bf6788 /ot_mutex.c
parent621c8462bebc7df652202c0eb9f28f0b5d9946d9 (diff)
downloadopentracker-49ec59cbbe332f3c7cb5237799b1d77bcda92c0e.tar.gz
opentracker-49ec59cbbe332f3c7cb5237799b1d77bcda92c0e.zip
* 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.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/ot_mutex.c b/ot_mutex.c
index 4bdd689..a876b1a 100644
--- a/ot_mutex.c
+++ b/ot_mutex.c
@@ -24,6 +24,7 @@
/* Our global all torrents list */
static ot_vector all_torrents[OT_BUCKET_COUNT];
+static size_t g_torrent_count;
/* Bucket Magic */
static int bucket_locklist[ OT_MAX_THREADS ];
@@ -87,15 +88,24 @@ ot_vector *mutex_bucket_lock_by_hash( ot_hash *hash ) {
return all_torrents + bucket;
}
-void mutex_bucket_unlock( int bucket ) {
+void mutex_bucket_unlock( int bucket, int delta_torrentcount ) {
pthread_mutex_lock( &bucket_mutex );
bucket_remove( bucket );
+ g_torrent_count += delta_torrentcount;
pthread_cond_broadcast( &bucket_being_unlocked );
pthread_mutex_unlock( &bucket_mutex );
}
-void mutex_bucket_unlock_by_hash( ot_hash *hash ) {
- mutex_bucket_unlock( uint32_read_big( (char*)*hash ) >> OT_BUCKET_COUNT_SHIFT );
+void mutex_bucket_unlock_by_hash( ot_hash *hash, int delta_torrentcount ) {
+ mutex_bucket_unlock( uint32_read_big( (char*)*hash ) >> OT_BUCKET_COUNT_SHIFT, delta_torrentcount );
+}
+
+size_t mutex_get_torrent_count( ) {
+ size_t torrent_count;
+ pthread_mutex_lock( &bucket_mutex );
+ torrent_count = g_torrent_count;
+ pthread_mutex_unlock( &bucket_mutex );
+ return torrent_count;
}
/* TaskQueue Magic */
@@ -316,4 +326,4 @@ void mutex_deinit( ) {
byte_zero( all_torrents, sizeof( all_torrents ) );
}
-const char *g_version_mutex_c = "$Source: /home/cvsroot/opentracker/ot_mutex.c,v $: $Revision: 1.15 $\n";
+const char *g_version_mutex_c = "$Source: /home/cvsroot/opentracker/ot_mutex.c,v $: $Revision: 1.16 $\n";