diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-24 00:15:34 +0200 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-24 00:15:34 +0200 |
| commit | 6d97e999f1e7b4476faf749abbb5e925d09208c6 (patch) | |
| tree | f22c04816949de04fc6b971c0a50f98f1cefd1ba /ot_mutex.c | |
| parent | 4ece9d359fd6668bfbc9c4260463f5b5913ae8fc (diff) | |
Replace endianess helpers and remove unused system and libowfat included
* Replace libowfat big endian packers with htonl/ntohl
* Turn bucket derivation in ot_mutex.c into its own helper
* remove unused includes
Diffstat (limited to 'ot_mutex.c')
| -rw-r--r-- | ot_mutex.c | 15 |
1 files changed, 11 insertions, 4 deletions
| @@ -4,16 +4,15 @@ | |||
| 4 | $id$ */ | 4 | $id$ */ |
| 5 | 5 | ||
| 6 | /* System */ | 6 | /* System */ |
| 7 | #include <arpa/inet.h> | ||
| 7 | #include <pthread.h> | 8 | #include <pthread.h> |
| 8 | #include <stdio.h> | 9 | #include <stdio.h> |
| 9 | #include <stdlib.h> | 10 | #include <stdlib.h> |
| 10 | #include <string.h> | 11 | #include <string.h> |
| 11 | #include <sys/mman.h> | ||
| 12 | #include <sys/uio.h> | 12 | #include <sys/uio.h> |
| 13 | 13 | ||
| 14 | /* Libowfat */ | 14 | /* Libowfat */ |
| 15 | #include "io.h" | 15 | #include "io.h" |
| 16 | #include "uint32.h" | ||
| 17 | 16 | ||
| 18 | /* Opentracker */ | 17 | /* Opentracker */ |
| 19 | #include "ot_iovec.h" | 18 | #include "ot_iovec.h" |
| @@ -37,7 +36,15 @@ ot_vector *mutex_bucket_lock(int bucket) { | |||
| 37 | return all_torrents + bucket; | 36 | return all_torrents + bucket; |
| 38 | } | 37 | } |
| 39 | 38 | ||
| 40 | ot_vector *mutex_bucket_lock_by_hash(ot_hash const hash) { return mutex_bucket_lock(uint32_read_big((const char *)hash) >> OT_BUCKET_COUNT_SHIFT); } | 39 | /* Torrents are spread over buckets by the first four bytes of their info_hash, |
| 40 | which may sit at any alignment, hence the memcpy */ | ||
| 41 | static int bucket_from_hash(ot_hash const hash) { | ||
| 42 | uint32_t bucket; | ||
| 43 | memcpy(&bucket, hash, sizeof(bucket)); | ||
| 44 | return ntohl(bucket) >> OT_BUCKET_COUNT_SHIFT; | ||
| 45 | } | ||
| 46 | |||
| 47 | ot_vector *mutex_bucket_lock_by_hash(ot_hash const hash) { return mutex_bucket_lock(bucket_from_hash(hash)); } | ||
| 41 | 48 | ||
| 42 | void mutex_bucket_unlock(int bucket, int delta_torrentcount) { | 49 | void mutex_bucket_unlock(int bucket, int delta_torrentcount) { |
| 43 | pthread_mutex_unlock(bucket_mutex + bucket); | 50 | pthread_mutex_unlock(bucket_mutex + bucket); |
| @@ -45,7 +52,7 @@ void mutex_bucket_unlock(int bucket, int delta_torrentcount) { | |||
| 45 | } | 52 | } |
| 46 | 53 | ||
| 47 | void mutex_bucket_unlock_by_hash(ot_hash const hash, int delta_torrentcount) { | 54 | void mutex_bucket_unlock_by_hash(ot_hash const hash, int delta_torrentcount) { |
| 48 | mutex_bucket_unlock(uint32_read_big((char *)hash) >> OT_BUCKET_COUNT_SHIFT, delta_torrentcount); | 55 | mutex_bucket_unlock(bucket_from_hash(hash), delta_torrentcount); |
| 49 | } | 56 | } |
| 50 | 57 | ||
| 51 | size_t mutex_get_torrent_count(void) { return g_torrent_count; } | 58 | size_t mutex_get_torrent_count(void) { return g_torrent_count; } |
