source: trunk/libtransmission/history.h @ 12328

Last change on this file since 12328 was 12328, checked in by jordan, 11 years ago

(trunk libT) more heap pruning: avoid four unnecessary malloc() + free() calls per tr_peer.

This commit also changes tr_recentHistory from being a general-purpose tool to being a little more hardcoded for the only purpose it's used, in tr_peerMgr. If its files (history.[ch]) don't find any other "customers" in libtransmission, eventually it should be demoted to being a private helper class inside of peer-mgr.c and have the history.[ch] files removed from the build.

  • Property svn:keywords set to Date Rev Author Id
File size: 1.6 KB
Line 
1/*
2 * This file Copyright (C) Mnemosyne LLC
3 *
4 * This file is licensed by the GPL version 2. Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id: history.h 12328 2011-04-06 23:27:11Z jordan $
11 */
12
13#ifndef __TRANSMISSION__
14 #error only libtransmission should #include this header.
15#endif
16
17#ifndef TR_RECENT_HISTORY_H
18#define TR_RECENT_HISTORY_H
19
20/**
21 * A generic short-term memory object that remembers how many times
22 * something happened over the last N seconds.
23 *
24 * For example, it could count how many are bytes transferred
25 * to estimate the speed over the last N seconds.
26 */
27
28enum
29{
30    TR_RECENT_HISTORY_PERIOD_SEC = 60
31};
32
33
34typedef struct tr_recentHistory
35{
36    /* these are PRIVATE IMPLEMENTATION details included for composition only.
37     * Don't access these directly! */
38
39    int newest;
40
41    struct {
42        unsigned int n;
43        time_t date;
44    } slices[TR_RECENT_HISTORY_PERIOD_SEC];
45}
46tr_recentHistory;
47
48/**
49 * @brief add a counter to the recent history object.
50 * @param when the current time in sec, such as from tr_time()
51 * @param n how many items to add to the history's counter
52 */
53void tr_historyAdd( tr_recentHistory *, time_t when, unsigned int n );
54
55/**
56 * @brief count how many events have occurred in the last N seconds.
57 * @param when the current time in sec, such as from tr_time()
58 * @param seconds how many seconds to count back through.
59 */
60unsigned int tr_historyGet( const tr_recentHistory *, time_t when, unsigned int seconds );
61
62#endif
Note: See TracBrowser for help on using the repository browser.