reorder some structs to reduce padding

This commit is contained in:
Arvid Norberg 2013-11-26 02:00:02 +00:00
parent 311ef5d3a4
commit 629baa3622
7 changed files with 63 additions and 66 deletions

View File

@ -784,6 +784,11 @@ namespace libtorrent
// we might need more than one listen socket // we might need more than one listen socket
std::list<listen_socket_t> m_listen_sockets; std::list<listen_socket_t> m_listen_sockets;
#if TORRENT_USE_I2P
i2p_connection m_i2p_conn;
boost::shared_ptr<socket_type> m_i2p_listen_socket;
#endif
#ifdef TORRENT_USE_OPENSSL #ifdef TORRENT_USE_OPENSSL
void ssl_handshake(error_code const& ec, boost::shared_ptr<socket_type> s); void ssl_handshake(error_code const& ec, boost::shared_ptr<socket_type> s);
#endif #endif
@ -795,11 +800,6 @@ namespace libtorrent
void open_new_incoming_socks_connection(); void open_new_incoming_socks_connection();
#if TORRENT_USE_I2P
i2p_connection m_i2p_conn;
boost::shared_ptr<socket_type> m_i2p_listen_socket;
#endif
void setup_listener(listen_socket_t* s, tcp::endpoint ep, int& retries void setup_listener(listen_socket_t* s, tcp::endpoint ep, int& retries
, bool v6_only, int flags, error_code& ec); , bool v6_only, int flags, error_code& ec);
@ -809,13 +809,6 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
entry m_dht_state; entry m_dht_state;
#endif #endif
// set to true when the session object
// is being destructed and the thread
// should exit
bool m_abort;
// is true if the session is paused
bool m_paused;
// the number of unchoked peers as set by the auto-unchoker // the number of unchoked peers as set by the auto-unchoker
// this should always be >= m_max_uploads // this should always be >= m_max_uploads
@ -867,12 +860,6 @@ namespace libtorrent
int m_peak_up_rate; int m_peak_up_rate;
int m_peak_down_rate; int m_peak_down_rate;
// is false by default and set to true when
// the first incoming connection is established
// this is used to know if the client is behind
// NAT or not.
bool m_incoming_connection;
void on_disk_queue(); void on_disk_queue();
void on_tick(error_code const& e); void on_tick(error_code const& e);
@ -1206,6 +1193,19 @@ namespace libtorrent
// no longer needs to execute the auto-management. // no longer needs to execute the auto-management.
bool m_need_auto_manage; bool m_need_auto_manage;
// set to true when the session object
// is being destructed and the thread
// should exit
bool m_abort;
// is true if the session is paused
bool m_paused;
// is false by default and set to true when
// the first incoming connection is established
// this is used to know if the client is behind
// NAT or not.
bool m_incoming_connection;
// redundant bytes per category // redundant bytes per category
size_type m_redundant_bytes[7]; size_type m_redundant_bytes[7];

View File

@ -98,7 +98,12 @@ private:
struct entry struct entry
{ {
entry(): connecting(false), ticket(0), expires(max_time()), priority(0) {} entry()
: expires(max_time())
, ticket(0)
, connecting(false)
, priority(0)
{}
// called when the connection is initiated // called when the connection is initiated
// this is when the timeout countdown starts // this is when the timeout countdown starts
boost::function<void(int)> on_connect; boost::function<void(int)> on_connect;
@ -109,11 +114,11 @@ private:
// 2. on_connect, on_timeout // 2. on_connect, on_timeout
// 3. on_timeout // 3. on_timeout
boost::function<void()> on_timeout; boost::function<void()> on_timeout;
bool connecting;
int ticket;
ptime expires; ptime expires;
time_duration timeout; time_duration timeout;
int priority; boost::uint32_t ticket;
bool connecting;
boost::uint8_t priority;
}; };
std::list<entry> m_queue; std::list<entry> m_queue;

View File

@ -89,13 +89,13 @@ namespace libtorrent
struct disk_io_job struct disk_io_job
{ {
disk_io_job() disk_io_job()
: action(read) : buffer(0)
, buffer(0)
, buffer_size(0) , buffer_size(0)
, piece(0) , piece(0)
, offset(0) , offset(0)
, max_cache_line(0) , max_cache_line(0)
, cache_min_time(0) , cache_min_time(0)
, action(read)
{} {}
enum action_t enum action_t
@ -121,14 +121,23 @@ namespace libtorrent
#endif #endif
}; };
action_t action;
char* buffer; char* buffer;
int buffer_size;
// this is called when operation completes
boost::function<void(int, disk_io_job const&)> callback;
boost::intrusive_ptr<piece_manager> storage; boost::intrusive_ptr<piece_manager> storage;
// arguments used for read and write
// piece is used as flags for move_storage boost::shared_ptr<entry> resume_data;
int piece, offset;
// the error code from the file operation
error_code error;
// the time when this job was issued. This is used to
// keep track of disk I/O congestion
ptime start_time;
// used for move_storage and rename_file. On errors, this is set // used for move_storage and rename_file. On errors, this is set
// to the error message // to the error message
std::string str; std::string str;
@ -137,6 +146,12 @@ namespace libtorrent
// file the disk operation failed on // file the disk operation failed on
std::string error_file; std::string error_file;
int buffer_size;
// arguments used for read and write
// piece is used as flags for move_storage
int piece, offset;
// if this is > 0, it specifies the max number of blocks to read // if this is > 0, it specifies the max number of blocks to read
// ahead in the read cache for this access. This is only valid // ahead in the read cache for this access. This is only valid
// for 'read' actions // for 'read' actions
@ -146,17 +161,7 @@ namespace libtorrent
// line caused by this operation stays in the cache // line caused by this operation stays in the cache
int cache_min_time; int cache_min_time;
boost::shared_ptr<entry> resume_data; action_t action:5;
// the error code from the file operation
error_code error;
// this is called when operation completes
boost::function<void(int, disk_io_job const&)> callback;
// the time when this job was issued. This is used to
// keep track of disk I/O congestion
ptime start_time;
}; };
// returns true if the fundamental operation // returns true if the fundamental operation

View File

@ -154,24 +154,6 @@ namespace libtorrent
void check_invariant() const; void check_invariant() const;
#endif #endif
// intended struct layout (on 32 bit architectures)
// offset size alignment field
// 0 8 4 prev_amount_upload, prev_amount_download
// 8 4 4 connection
// 12 2 2 last_optimistically_unchoked
// 14 2 2 last_connected
// 16 16 1 addr
// 32 2 2 port
// 34 2 2 upload_rate_limit
// 36 2 2 download_rate_limit
// 38 1 1 hashfails
// 39 1 1 failcount, connectable, optimistically_unchoked, seed
// 40 1 1 fast_reconnects, trust_points
// 41 1 1 source, pe_support, is_v6_addr
// 42 1 1 on_parole, banned, added_to_dht, supports_utp,
// supports_holepunch, web_seed
// 43 1 1 <padding>
// 44
struct TORRENT_EXTRA_EXPORT peer struct TORRENT_EXTRA_EXPORT peer
{ {
peer(boost::uint16_t port, bool connectable, int src); peer(boost::uint16_t port, bool connectable, int src);
@ -206,11 +188,6 @@ namespace libtorrent
// will refer to a valid peer_connection // will refer to a valid peer_connection
peer_connection* connection; peer_connection* connection;
// as computed by hashing our IP with the remote
// IP of this peer
// calculated lazily
mutable boost::uint32_t peer_rank;
#ifndef TORRENT_DISABLE_GEO_IP #ifndef TORRENT_DISABLE_GEO_IP
#ifdef TORRENT_DEBUG #ifdef TORRENT_DEBUG
// only used in debug mode to assert that // only used in debug mode to assert that
@ -221,6 +198,11 @@ namespace libtorrent
std::pair<const int, int>* inet_as; std::pair<const int, int>* inet_as;
#endif #endif
// as computed by hashing our IP with the remote
// IP of this peer
// calculated lazily
mutable boost::uint32_t peer_rank;
// the time when this peer was optimistically unchoked // the time when this peer was optimistically unchoked
// the last time. in seconds since session was created // the last time. in seconds since session was created
// 16 bits is enough to last for 18.2 hours // 16 bits is enough to last for 18.2 hours

View File

@ -114,6 +114,8 @@ namespace libtorrent
int m_5_sec_average; int m_5_sec_average;
int m_30_sec_average; int m_30_sec_average;
// TODO: this is 4 bytes of padding!
// total counters // total counters
size_type m_total_counter; size_type m_total_counter;
}; };

View File

@ -98,6 +98,9 @@ namespace libtorrent
e->timeout = timeout; e->timeout = timeout;
++m_next_ticket; ++m_next_ticket;
if (m_next_ticket >= (1 << 29))
m_next_ticket = 0;
if (m_num_connecting < m_half_open_limit if (m_num_connecting < m_half_open_limit
|| m_half_open_limit == 0) || m_half_open_limit == 0)
m_timer.get_io_service().post(boost::bind( m_timer.get_io_service().post(boost::bind(

View File

@ -637,8 +637,6 @@ namespace aux {
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
, m_i2p_conn(m_io_service) , m_i2p_conn(m_io_service)
#endif #endif
, m_abort(false)
, m_paused(false)
, m_allowed_upload_slots(8) , m_allowed_upload_slots(8)
, m_num_unchoked(0) , m_num_unchoked(0)
, m_unchoke_time_scaler(0) , m_unchoke_time_scaler(0)
@ -650,7 +648,6 @@ namespace aux {
, m_cache_rotation_timer(0) , m_cache_rotation_timer(0)
, m_peak_up_rate(0) , m_peak_up_rate(0)
, m_peak_down_rate(0) , m_peak_down_rate(0)
, m_incoming_connection(false)
, m_created(time_now_hires()) , m_created(time_now_hires())
, m_last_tick(m_created) , m_last_tick(m_created)
, m_last_second_tick(m_created - milliseconds(900)) , m_last_second_tick(m_created - milliseconds(900))
@ -689,6 +686,9 @@ namespace aux {
, m_total_redundant_bytes(0) , m_total_redundant_bytes(0)
, m_pending_auto_manage(false) , m_pending_auto_manage(false)
, m_need_auto_manage(false) , m_need_auto_manage(false)
, m_abort(false)
, m_paused(false)
, m_incoming_connection(false)
#if (defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS) && defined BOOST_HAS_PTHREADS #if (defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS) && defined BOOST_HAS_PTHREADS
, m_network_thread(0) , m_network_thread(0)
#endif #endif