void* tribuf_get_read_nolock(tribuf *tb) { tb_lock(&tb->lock); int r = do_get_read_nolock((frms)tb->active); tb_unlock(&tb->lock); return tb->data[r]; }
int tribuf_check_fresh(tribuf *tb) { tb_lock(&tb->lock); int res = ((frms)tb->active).idf; tb_unlock(&tb->lock); return res; }
void tribuf_finish_write(tribuf *tb) { user_debug_unlock(tb, write); tb_lock(&tb->lock); tb->active = do_finish_write((frms)tb->active).v; tb_unlock(&tb->lock); }
void mysql::flush_torrents() { std::lock_guard<std::mutex> tb_lock(torrent_buffer_lock); if (readonly) { update_torrent_buffer.clear(); return; } std::string sql; std::lock_guard<std::mutex> tq_lock(torrent_queue_lock); size_t qsize = torrent_queue.size(); if (verbose_flush || qsize > 0) { std::cout << "Torrent flush queue size: " << qsize << ", next query length: " << torrent_queue.front().size() << std::endl; } if (update_torrent_buffer == "") { return; } sql = "INSERT INTO bb_bt_tracker_snap (topic_id,seeders,leechers,complete) VALUES " + update_torrent_buffer + " ON DUPLICATE KEY UPDATE seeders=VALUES(seeders), leechers=VALUES(leechers), " + "complete=complete+VALUES(complete)" ; torrent_queue.push(sql); update_torrent_buffer.clear(); sql.clear(); sql = "DELETE FROM bb_bt_torrents WHERE info_hash = ''"; torrent_queue.push(sql); if (!t_active) { std::thread thread(&mysql::do_flush_torrents, this); thread.detach(); } }
void mysql::record_torrent(const std::string &record) { std::lock_guard<std::mutex> tb_lock(torrent_buffer_lock); if (update_torrent_buffer != "") { update_torrent_buffer += ","; } update_torrent_buffer += record; }
void* tribuf_get_write(tribuf *tb) { tb_lock(&tb->lock); int r = ((frms)tb->active).aw; tb_unlock(&tb->lock); user_debug_lock(tb, write); return tb->data[r]; }
void* tribuf_get_read(tribuf *tb) { tb_lock(&tb->lock); frms f = do_get_read((frms)tb->active); tb->active = f.v; tb_unlock(&tb->lock); user_debug_lock(tb, read); return tb->data[f.ar]; }