diff options
author | Yorhel <git@yorhel.nl> | 2021-03-27 13:41:06 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-03-27 13:41:11 +0100 |
commit | f074e0834f82cbcf5f1d63328892458f655a99da (patch) | |
tree | 70fadb63d11d2fd63a25ee970601997418b6ee6a | |
parent | d1dee81bf15ffb49f9c2342e8688796fb0b3fa06 (diff) |
Bump minimum glib version to 2.32 and get rid of deprecation warnings
I'm sure enough time has passed by now.
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/db.c | 27 | ||||
-rw-r--r-- | src/dl.c | 8 | ||||
-rw-r--r-- | src/dlfile.c | 18 | ||||
-rw-r--r-- | src/fl_local.c | 24 | ||||
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/net.c | 36 | ||||
-rw-r--r-- | src/util.c | 32 |
8 files changed, 70 insertions, 78 deletions
diff --git a/configure.ac b/configure.ac index 092b517..c42ad66 100644 --- a/configure.ac +++ b/configure.ac @@ -121,7 +121,7 @@ PKG_CHECK_EXISTS([sqlite3],[ ) # Check for modules -PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.24 gthread-2.0]) +PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.32 gthread-2.0]) PKG_CHECK_MODULES([GNUTLS], [gnutls >= 3.0]) AC_ARG_WITH([geoip], [AS_HELP_STRING([--with-geoip], [support for IP-to-country lookups @<:@default=no@:>@])], @@ -292,7 +292,7 @@ static int db_queue_process_begin(sqlite3 *db) { static void db_queue_process(sqlite3 *db) { - GTimeVal trans_end = {}; // tv_sec = 0 if no transaction is active + gint64 trans_end = 0; // 0 if no transaction is active gboolean donext = FALSE; gboolean errtrans = FALSE; @@ -302,7 +302,7 @@ static void db_queue_process(sqlite3 *db) { while(1) { char *q = donext ? g_async_queue_try_pop(db_queue) : - trans_end.tv_sec ? g_async_queue_timed_pop(db_queue, &trans_end) : + trans_end ? g_async_queue_timeout_pop(db_queue, trans_end - g_get_monotonic_time()) : g_async_queue_pop(db_queue); int flags = q ? darray_get_int32(q) : 0; @@ -311,9 +311,9 @@ static void db_queue_process(sqlite3 *db) { // Commit state if we need to if(!q || flags & DBF_SINGLE || flags & DBF_END) { g_warn_if_fail(!donext); - if(trans_end.tv_sec) + if(trans_end) db_queue_process_commit(db); - trans_end.tv_sec = 0; + trans_end = 0; donext = errtrans = FALSE; } @@ -343,7 +343,7 @@ static void db_queue_process(sqlite3 *db) { donext = flags & DBF_NEXT ? TRUE : FALSE; if(!donext) { errtrans = FALSE; - trans_end.tv_sec = 0; + trans_end = 0; } g_free(q); continue; @@ -351,15 +351,15 @@ static void db_queue_process(sqlite3 *db) { // handle LAST queries if(flags & DBF_LAST) { - r = db_queue_process_one(db, q, nocache, trans_end.tv_sec?TRUE:FALSE, &res, &lastid); + r = db_queue_process_one(db, q, nocache, trans_end?TRUE:FALSE, &res, &lastid); // Commit first, then send back the final result - if(trans_end.tv_sec) { + if(trans_end) { if(r == SQLITE_DONE) r = db_queue_process_commit(db); if(r != SQLITE_DONE) db_queue_process_rollback(db); } - trans_end.tv_sec = 0; + trans_end = 0; donext = FALSE; db_queue_item_final(res, r, lastid); g_free(q); @@ -367,15 +367,14 @@ static void db_queue_process(sqlite3 *db) { } // start a new transaction for normal/NEXT queries - if(!trans_end.tv_sec) { - g_get_current_time(&trans_end); - g_time_val_add(&trans_end, DB_FLUSH_TIMEOUT); + if(!trans_end) { + trans_end = g_get_monotonic_time() + DB_FLUSH_TIMEOUT; r = db_queue_process_begin(db); if(r != SQLITE_DONE) { if(flags & DBF_NEXT) donext = errtrans = TRUE; else - trans_end.tv_sec = 0; + trans_end = 0; db_queue_item_error(q); g_free(q); continue; @@ -393,7 +392,7 @@ static void db_queue_process(sqlite3 *db) { if(flags & DBF_NEXT) errtrans = TRUE; else - trans_end.tv_sec = 0; + trans_end = 0; } } } @@ -1611,7 +1610,7 @@ void db_init() { // start database thread db_queue = g_async_queue_new(); - db_thread = g_thread_create(db_thread_func, g_build_filename(db_dir, "db.sqlite3", NULL), TRUE, NULL); + db_thread = g_thread_new("database thread", db_thread_func, g_build_filename(db_dir, "db.sqlite3", NULL)); db_init_schema(); } @@ -128,7 +128,7 @@ struct dl_t { * downloading thread is active and thus do not need synchronisation. These * include dl_t.{size,islist,hash,hash_block,incfd} and possibly more. * TODO: dl.have isn't always protected yet! */ - GStaticMutex lock; + GMutex lock; }; #endif @@ -537,7 +537,7 @@ void dl_queue_addlist(hub_user_t *u, const char *sel, ui_tab_t *parent, gboolean g_return_if_fail(u && u->hasinfo); dl_t *dl = g_slice_new0(dl_t); dl->islist = TRUE; - g_static_mutex_init(&dl->lock); + g_mutex_init(&dl->lock); if(sel) dl->flsel = g_strdup(sel); dl->flpar = parent; @@ -576,7 +576,7 @@ static gboolean dl_queue_addfile(guint64 uid, char *hash, guint64 size, char *fn if(g_hash_table_lookup(dl_queue, hash)) return FALSE; dl_t *dl = g_slice_new0(dl_t); - g_static_mutex_init(&dl->lock); + g_mutex_init(&dl->lock); memcpy(dl->hash, hash, 24); dl->size = size; // Figure out dl->dest @@ -924,7 +924,7 @@ void dl_load_dl(const char *tth, guint64 size, const char *dest, signed char pri g_return_if_fail(dest); dl_t *dl = g_slice_new0(dl_t); - g_static_mutex_init(&dl->lock); + g_mutex_init(&dl->lock); memcpy(dl->hash, tth, 24); dl->size = size; dl->prio = prio; diff --git a/src/dlfile.c b/src/dlfile.c index cea89e8..512c773 100644 --- a/src/dlfile.c +++ b/src/dlfile.c @@ -119,7 +119,7 @@ static gboolean dlfile_save_bitmap(dl_t *dl, int fd) { static gboolean dlfile_save_bitmap_timeout(gpointer dat) { dl_t *dl = dat; - g_static_mutex_lock(&dl->lock); + g_mutex_lock(&dl->lock); dl->bitmap_src = 0; if(dl->incfd > 0 && !dlfile_save_bitmap(dl, dl->incfd)) { g_warning("Error writing bitmap for `%s': %s.", dl->dest, g_strerror(errno)); @@ -129,7 +129,7 @@ static gboolean dlfile_save_bitmap_timeout(gpointer dat) { close(dl->incfd); dl->incfd = 0; } - g_static_mutex_unlock(&dl->lock); + g_mutex_unlock(&dl->lock); return FALSE; } @@ -483,7 +483,7 @@ dlfile_thread_t *dlfile_getchunk(dl_t *dl, guint64 uid, guint64 speed) { dlfile_thread_t *tsec = NULL; GSList *l; - g_static_mutex_lock(&dl->lock); + g_mutex_lock(&dl->lock); dlfile_threaddump(dl, 1); for(l=dl->threads; l; l=l->next) { dlfile_thread_t *ti = l->data; @@ -531,7 +531,7 @@ dlfile_thread_t *dlfile_getchunk(dl_t *dl, guint64 uid, guint64 speed) { dl->allbusy = !l; dlfile_threaddump(dl, 2); - g_static_mutex_unlock(&dl->lock); + g_mutex_unlock(&dl->lock); g_debug("Allocating: allbusy = %d, chunk = %u, allocated = %u, avail = %u, chunksinblock = %u, chunksinfile = %u", dl->allbusy, t->chunk, t->allocated, t->avail, (guint32)dl->hash_block/DLFILE_CHUNKSIZE, dlfile_chunks(dl->size)); return t; @@ -543,7 +543,7 @@ static gboolean dlfile_recv_check(dlfile_thread_t *t, char *leaf) { if(t->dl->size < t->dl->hash_block ? memcmp(leaf, t->dl->hash, 24) == 0 : db_dl_checkhash(t->dl->hash, num, leaf)) return TRUE; - g_static_mutex_lock(&t->dl->lock); + g_mutex_lock(&t->dl->lock); /* Hash failure, remove the failed block from the bitmap and dl->have, and * reset this thread so that the block can be re-downloaded. */ @@ -560,7 +560,7 @@ static gboolean dlfile_recv_check(dlfile_thread_t *t, char *leaf) { bita_set(t->dl->bitmap, i); dlfile_save_bitmap_defer(t->dl); - g_static_mutex_unlock(&t->dl->lock); + g_mutex_unlock(&t->dl->lock); t->uerr = DLE_HASH; t->uerr_msg = g_strdup_printf("Hash for block %u (chunk %u-%u) does not match.", num, startchunk, startchunk+chunksinblock); @@ -609,11 +609,11 @@ gboolean dlfile_recv(void *vt, const char *buf, int len) { buf += inchunk; len -= inchunk; - g_static_mutex_lock(&t->dl->lock); + g_mutex_lock(&t->dl->lock); t->dl->have += inchunk; if(!islast && t->len < DLFILE_CHUNKSIZE) { - g_static_mutex_unlock(&t->dl->lock); + g_mutex_unlock(&t->dl->lock); continue; } @@ -625,7 +625,7 @@ gboolean dlfile_recv(void *vt, const char *buf, int len) { t->allocated--; t->avail--; t->len = 0; - g_static_mutex_unlock(&t->dl->lock); + g_mutex_unlock(&t->dl->lock); if(!t->dl->islist && (islast || t->chunk % (t->dl->hash_block / DLFILE_CHUNKSIZE) == 0)) { char leaf[24]; diff --git a/src/fl_local.c b/src/fl_local.c index c0b8cff..1ee9b84 100644 --- a/src/fl_local.c +++ b/src/fl_local.c @@ -46,8 +46,8 @@ guint64 fl_hash_queue_size = 0; static fl_list_t *fl_hash_cur = NULL; // most recent file initiated for hashing ratecalc_t fl_hash_rate; static guint64 fl_hash_reset = 0; // increased when fl_hash_cur is removed from the queue (to stop current hash operation) -static GMutex *fl_hash_resetlock; -static GCond *fl_hash_resetcond; +static GMutex fl_hash_resetlock; +static GCond fl_hash_resetcond; #define TTH_BUFSIZE (512*1024) @@ -476,10 +476,10 @@ typedef struct fl_hash_t { fl_hash_queue_size -= fl->size;\ g_hash_table_remove(fl_hash_queue, fl);\ if((fl) == fl_hash_cur) {\ - g_mutex_lock(fl_hash_resetlock);\ + g_mutex_lock(&fl_hash_resetlock);\ fl_hash_reset++;\ - g_cond_signal(fl_hash_resetcond);\ - g_mutex_unlock(fl_hash_resetlock);\ + g_cond_signal(&fl_hash_resetcond);\ + g_mutex_unlock(&fl_hash_resetlock);\ }\ }\ } while(0) @@ -503,14 +503,10 @@ static void fl_hash_queue_delrec(fl_list_t *f) { // Returns the allowed burst, or 0 on cancellation. static int fl_hash_burst(guint64 lastreset) { int b = 0; - g_mutex_lock(fl_hash_resetlock); - while(fl_hash_reset == lastreset && (b = ratecalc_burst(&fl_hash_rate)) <= 0) { - GTimeVal end; - g_get_current_time(&end); - g_time_val_add(&end, 100*1000); // Wake up every 100ms. - g_cond_timed_wait(fl_hash_resetcond, fl_hash_resetlock, &end); - } - g_mutex_unlock(fl_hash_resetlock); + g_mutex_lock(&fl_hash_resetlock); + while(fl_hash_reset == lastreset && (b = ratecalc_burst(&fl_hash_rate)) <= 0) + g_cond_wait_until(&fl_hash_resetcond, &fl_hash_resetlock, g_get_monotonic_time()* + 100*G_TIME_SPAN_MILLISECOND); + g_mutex_unlock(&fl_hash_resetlock); return b; } @@ -1001,8 +997,6 @@ void fl_init() { fl_refresh_queue = g_queue_new(); fl_scan_pool = g_thread_pool_new(fl_scan_thread, NULL, 1, FALSE, NULL); fl_hash_pool = g_thread_pool_new(fl_hash_thread, NULL, 1, FALSE, NULL); - fl_hash_resetlock = g_mutex_new(); - fl_hash_resetcond = g_cond_new(); fl_hash_queue = g_hash_table_new(g_direct_hash, g_direct_equal); // Even though the keys are the tth roots, we can just use g_int_hash. The // first four bytes provide enough unique data anyway. @@ -401,7 +401,6 @@ int main(int argc, char **argv) { // init stuff gnutls_global_init(); - g_thread_init(NULL); // Create main loop main_loop = g_main_loop_new(NULL, FALSE); @@ -240,7 +240,7 @@ static int low_send(net_t *n, const char *buf, int len, const char **err) { static void asy_setuppoll(net_t *n); struct synfer_t { - GStaticMutex lock; // protects n->left, any data used within the low_* functions and, in the case of a disconnect, net->sock and net->tls. + GMutex lock; // protects n->left, any data used within the low_* functions and, in the case of a disconnect, net->sock and net->tls. net_t *net; guint64 left; // The transfer thread itself does not need the lock to read this value, only to write. (It is the only writer) int fd; // for uploads @@ -264,7 +264,7 @@ static void syn_new(net_t *n, gboolean upl, guint64 len) { n->syn->net = n; n->syn->upl = upl; - g_static_mutex_init(&n->syn->lock); + g_mutex_init(&n->syn->lock); if(pipe(n->syn->can) < 0) { g_critical("pipe() failed: %s", g_strerror(errno)); g_return_if_reached(); @@ -333,13 +333,13 @@ static gboolean syn_done(gpointer dat) { // success, 0 if the operation has been cancelled. static int syn_wait(synfer_t *s, int sock, gboolean write) { // Lock to get the socket fd - g_static_mutex_lock(&s->lock); + g_mutex_lock(&s->lock); GPollFD fds[2] = {}; fds[0].fd = s->can[0]; fds[0].events = G_IO_IN; fds[1].fd = sock; fds[1].events = write ? G_IO_OUT : G_IO_IN; - g_static_mutex_unlock(&s->lock); + g_mutex_unlock(&s->lock); // Poll for burst int b = 0; @@ -405,10 +405,10 @@ static void syn_upload_sendfile(synfer_t *s, int sock, fadv_t *adv) { // ratecalc thing and update timeout_last. ratecalc_add(&net_out, r); ratecalc_add(&s->net->rate_out, r); - g_static_mutex_lock(&s->lock); + g_mutex_lock(&s->lock); time(&s->net->timeout_last); s->left -= r; - g_static_mutex_unlock(&s->lock); + g_mutex_unlock(&s->lock); continue; } else if(errno == EAGAIN || errno == EINTR) { continue; @@ -452,7 +452,7 @@ static void syn_upload_buf(synfer_t *s, int sock, fadv_t *adv) { if(b <= 0) goto done; - g_static_mutex_lock(&s->lock); + g_mutex_lock(&s->lock); const char *err = NULL; int wr = s->cancel || !s->net->sock ? 0 : low_send(s->net, p, MIN(rd, b), &err); // successful write @@ -461,7 +461,7 @@ static void syn_upload_buf(synfer_t *s, int sock, fadv_t *adv) { s->left -= wr; rd -= wr; } - g_static_mutex_unlock(&s->lock); + g_mutex_unlock(&s->lock); if(!wr) // cancelled goto done; @@ -487,12 +487,12 @@ static void syn_download(synfer_t *s, int sock) { if(b <= 0) break; - g_static_mutex_lock(&s->lock); + g_mutex_lock(&s->lock); const char *err = NULL; int r = s->cancel || !s->net->sock ? 0 : low_recv(s->net, buf, MIN(NET_TRANS_BUF, s->left), &err); if(r > 0) s->left -= r; - g_static_mutex_unlock(&s->lock); + g_mutex_unlock(&s->lock); if(!r) break; @@ -518,10 +518,10 @@ static void syn_thread(gpointer dat, gpointer udat) { // Make a copy of sock to make sure it doesn't disappear on us. // (Still need to obtain the lock to make use of it). - g_static_mutex_lock(&s->lock); + g_mutex_lock(&s->lock); int sock = s->net->sock; gboolean tls = !!s->net->tls; - g_static_mutex_unlock(&s->lock); + g_mutex_unlock(&s->lock); if(sock && !s->cancel && s->upl) { fadv_t adv; @@ -560,9 +560,9 @@ static void syn_start(net_t *n) { guint64 net_left(net_t *n) { if(!n->syn) return 0; - g_static_mutex_lock(&n->syn->lock); + g_mutex_lock(&n->syn->lock); guint64 r = n->syn->left; - g_static_mutex_unlock(&n->syn->lock); + g_mutex_unlock(&n->syn->lock); return r; } @@ -1238,10 +1238,10 @@ static void dnscon_thread(gpointer dat, gpointer udat) { time_t net_last_activity(net_t *n) { if(n->syn) - g_static_mutex_lock(&n->syn->lock); + g_mutex_lock(&n->syn->lock); time_t last = n->timeout_last; if(n->syn) - g_static_mutex_unlock(&n->syn->lock); + g_mutex_unlock(&n->syn->lock); return last; } @@ -1370,7 +1370,7 @@ void net_disconnect(net_t *n) { // If we're in the SYN state, then the socket and tls session are in control // of the file transfer thread. Hence the need for the conditional locks. if(s) - g_static_mutex_lock(&s->lock); + g_mutex_lock(&s->lock); if(n->tls) { gnutls_deinit(n->tls); n->tls = NULL; @@ -1381,7 +1381,7 @@ void net_disconnect(net_t *n) { } time(&n->timeout_last); if(s) - g_static_mutex_unlock(&s->lock); + g_mutex_unlock(&s->lock); if(n->rbuf) { g_string_free(n->rbuf, TRUE); @@ -758,7 +758,7 @@ char *darray_get_dat(char *v, int *l) { #define RCC_MAX RCC_DOWN struct ratecalc_t { - GStaticMutex lock; // protects total, last, rate and burst + GMutex lock; // protects total, last, rate and burst gint64 total; gint64 last; int burst; @@ -767,13 +767,13 @@ struct ratecalc_t { }; #define ratecalc_reset(rc) do {\ - g_static_mutex_lock(&((rc)->lock));\ + g_mutex_lock(&((rc)->lock));\ (rc)->total = (rc)->last = (rc)->rate = (rc)->burst = 0;\ - g_static_mutex_unlock(&((rc)->lock));\ + g_mutex_unlock(&((rc)->lock));\ } while(0) #define ratecalc_init(rc) do {\ - g_static_mutex_init(&((rc)->lock));\ + g_mutex_init(&((rc)->lock));\ ratecalc_unregister(rc);\ ratecalc_reset(rc);\ } while(0) @@ -797,33 +797,33 @@ GSList *ratecalc_list = NULL; void ratecalc_add(ratecalc_t *rc, int b) { - g_static_mutex_lock(&rc->lock); + g_mutex_lock(&rc->lock); rc->total += b; rc->burst -= b; - g_static_mutex_unlock(&rc->lock); + g_mutex_unlock(&rc->lock); } int ratecalc_rate(ratecalc_t *rc) { - g_static_mutex_lock(&rc->lock); + g_mutex_lock(&rc->lock); int r = rc->rate; - g_static_mutex_unlock(&rc->lock); + g_mutex_unlock(&rc->lock); return r; } int ratecalc_burst(ratecalc_t *rc) { - g_static_mutex_lock(&rc->lock); + g_mutex_lock(&rc->lock); int r = rc->burst; - g_static_mutex_unlock(&rc->lock); + g_mutex_unlock(&rc->lock); return r; } gint64 ratecalc_total(ratecalc_t *rc) { - g_static_mutex_lock(&rc->lock); + g_mutex_lock(&rc->lock); gint64 r = rc->total; - g_static_mutex_unlock(&rc->lock); + g_mutex_unlock(&rc->lock); return r; } @@ -848,7 +848,7 @@ void ratecalc_calc() { // Pass one: calculate rc->rate, substract negative burst values from left[] and calculate nums[]. for(n=ratecalc_list; n; n=n->next) { ratecalc_t *rc = n->data; - g_static_mutex_lock(&rc->lock); + g_mutex_lock(&rc->lock); gint64 diff = rc->total - rc->last; rc->rate = diff + ((rc->rate - diff) / 2); rc->last = rc->total; @@ -861,7 +861,7 @@ void ratecalc_calc() { nums[rc->reg]++; else rc->burst = maxburst[rc->reg]; - g_static_mutex_unlock(&rc->lock); + g_mutex_unlock(&rc->lock); } //g_debug("Num: %d - %d - %d", nums[2], nums[3], nums[4]); @@ -885,12 +885,12 @@ void ratecalc_calc() { for(n=ratecalc_list; n; n=n->next) { ratecalc_t *rc = n->data; if(bwp[rc->reg] > 0) { - g_static_mutex_lock(&rc->lock); + g_mutex_lock(&rc->lock); int alloc = MIN(maxburst[rc->reg]-rc->burst, bwp[rc->reg]); //g_debug("Allocing class %d(num=%d), %d new bytes to %d", rc->reg, nums[rc->reg], alloc, rc->burst); rc->burst += alloc; left[rc->reg] -= alloc; - g_static_mutex_unlock(&rc->lock); + g_mutex_unlock(&rc->lock); if(alloc > 0 && alloc < bwp[rc->reg]) nums[rc->reg]--; } |