-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated __sync_* calls to std::atomic.
- Loading branch information
Showing
13 changed files
with
83 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,29 @@ | ||
// libTorrent - BitTorrent library | ||
// Copyright (C) 2005-2011, Jari Sundell | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation; either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
// | ||
// In addition, as a special exception, the copyright holders give | ||
// permission to link the code of portions of this program with the | ||
// OpenSSL library under certain conditions as described in each | ||
// individual source file, and distribute linked combinations | ||
// including the two. | ||
// | ||
// You must obey the GNU General Public License in all respects for | ||
// all of the code used other than OpenSSL. If you modify file(s) | ||
// with this exception, you may extend this exception to your version | ||
// of the file(s), but you are not obligated to do so. If you do not | ||
// wish to do so, delete this exception statement from your version. | ||
// If you delete this exception statement from all source files in the | ||
// program, then also delete it here. | ||
// | ||
// Contact: Jari Sundell <[email protected]> | ||
// | ||
// Skomakerveien 33 | ||
// 3185 Skoppum, NORWAY | ||
|
||
#include "config.h" | ||
|
||
#include "instrumentation.h" | ||
|
||
namespace torrent { | ||
|
||
std::array<int64_t, INSTRUMENTATION_MAX_SIZE> instrumentation_values lt_cacheline_aligned; | ||
std::array<std::atomic_int64_t, INSTRUMENTATION_MAX_SIZE> instrumentation_values; | ||
|
||
inline int64_t | ||
instrumentation_fetch_and_clear(instrumentation_enum type) { | ||
#ifdef LT_INSTRUMENTATION | ||
return __sync_fetch_and_and(&instrumentation_values[type], int64_t()); | ||
return instrumentation_values[type].exchange(0); | ||
#else | ||
return instrumentation_values[type] = 0; | ||
return 0; | ||
#endif | ||
} | ||
|
||
void | ||
instrumentation_tick() { | ||
// Since the values are updated with __sync_add, they can be read | ||
// without any memory barriers. | ||
lt_log_print(LOG_INSTRUMENTATION_MEMORY, | ||
"%" PRIi64 " %" PRIi64 " %" PRIi64 " %" PRIi64 " %" PRIi64, | ||
instrumentation_values[INSTRUMENTATION_MEMORY_CHUNK_USAGE], | ||
instrumentation_values[INSTRUMENTATION_MEMORY_CHUNK_COUNT], | ||
instrumentation_values[INSTRUMENTATION_MEMORY_HASHING_CHUNK_USAGE], | ||
instrumentation_values[INSTRUMENTATION_MEMORY_HASHING_CHUNK_COUNT], | ||
instrumentation_values[INSTRUMENTATION_MEMORY_BITFIELDS]); | ||
instrumentation_values[INSTRUMENTATION_MEMORY_CHUNK_USAGE].load(), | ||
instrumentation_values[INSTRUMENTATION_MEMORY_CHUNK_COUNT].load(), | ||
instrumentation_values[INSTRUMENTATION_MEMORY_HASHING_CHUNK_USAGE].load(), | ||
instrumentation_values[INSTRUMENTATION_MEMORY_HASHING_CHUNK_COUNT].load(), | ||
instrumentation_values[INSTRUMENTATION_MEMORY_BITFIELDS].load()); | ||
|
||
lt_log_print(LOG_INSTRUMENTATION_MINCORE, | ||
"%" PRIi64 " %" PRIi64 " %" PRIi64 " %" PRIi64 " %" PRIi64 | ||
|
@@ -117,24 +79,24 @@ instrumentation_tick() { | |
instrumentation_fetch_and_clear(INSTRUMENTATION_TRANSFER_REQUESTS_QUEUED_ADDED), | ||
instrumentation_fetch_and_clear(INSTRUMENTATION_TRANSFER_REQUESTS_QUEUED_MOVED), | ||
instrumentation_fetch_and_clear(INSTRUMENTATION_TRANSFER_REQUESTS_QUEUED_REMOVED), | ||
instrumentation_values[INSTRUMENTATION_TRANSFER_REQUESTS_QUEUED_TOTAL], | ||
instrumentation_values[INSTRUMENTATION_TRANSFER_REQUESTS_QUEUED_TOTAL].load(), | ||
|
||
instrumentation_fetch_and_clear(INSTRUMENTATION_TRANSFER_REQUESTS_UNORDERED_ADDED), | ||
instrumentation_fetch_and_clear(INSTRUMENTATION_TRANSFER_REQUESTS_UNORDERED_MOVED), | ||
instrumentation_fetch_and_clear(INSTRUMENTATION_TRANSFER_REQUESTS_UNORDERED_REMOVED), | ||
instrumentation_values[INSTRUMENTATION_TRANSFER_REQUESTS_UNORDERED_TOTAL], | ||
instrumentation_values[INSTRUMENTATION_TRANSFER_REQUESTS_UNORDERED_TOTAL].load(), | ||
|
||
instrumentation_fetch_and_clear(INSTRUMENTATION_TRANSFER_REQUESTS_STALLED_ADDED), | ||
instrumentation_fetch_and_clear(INSTRUMENTATION_TRANSFER_REQUESTS_STALLED_MOVED), | ||
instrumentation_fetch_and_clear(INSTRUMENTATION_TRANSFER_REQUESTS_STALLED_REMOVED), | ||
instrumentation_values[INSTRUMENTATION_TRANSFER_REQUESTS_STALLED_TOTAL], | ||
instrumentation_values[INSTRUMENTATION_TRANSFER_REQUESTS_STALLED_TOTAL].load(), | ||
|
||
instrumentation_fetch_and_clear(INSTRUMENTATION_TRANSFER_REQUESTS_CHOKED_ADDED), | ||
instrumentation_fetch_and_clear(INSTRUMENTATION_TRANSFER_REQUESTS_CHOKED_MOVED), | ||
instrumentation_fetch_and_clear(INSTRUMENTATION_TRANSFER_REQUESTS_CHOKED_REMOVED), | ||
instrumentation_values[INSTRUMENTATION_TRANSFER_REQUESTS_CHOKED_TOTAL], | ||
instrumentation_values[INSTRUMENTATION_TRANSFER_REQUESTS_CHOKED_TOTAL].load(), | ||
|
||
instrumentation_values[INSTRUMENTATION_TRANSFER_PEER_INFO_UNACCOUNTED]); | ||
instrumentation_values[INSTRUMENTATION_TRANSFER_PEER_INFO_UNACCOUNTED].load()); | ||
} | ||
|
||
void | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,9 @@ | ||
// libTorrent - BitTorrent library | ||
// Copyright (C) 2005-2011, Jari Sundell | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation; either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
// | ||
// In addition, as a special exception, the copyright holders give | ||
// permission to link the code of portions of this program with the | ||
// OpenSSL library under certain conditions as described in each | ||
// individual source file, and distribute linked combinations | ||
// including the two. | ||
// | ||
// You must obey the GNU General Public License in all respects for | ||
// all of the code used other than OpenSSL. If you modify file(s) | ||
// with this exception, you may extend this exception to your version | ||
// of the file(s), but you are not obligated to do so. If you do not | ||
// wish to do so, delete this exception statement from your version. | ||
// If you delete this exception statement from all source files in the | ||
// program, then also delete it here. | ||
// | ||
// Contact: Jari Sundell <[email protected]> | ||
// | ||
// Skomakerveien 33 | ||
// 3185 Skoppum, NORWAY | ||
|
||
#ifndef LIBTORRENT_UTILS_INSTRUMENTATION_H | ||
#define LIBTORRENT_UTILS_INSTRUMENTATION_H | ||
|
||
#include <algorithm> | ||
#include <array> | ||
#include <atomic> | ||
|
||
#include "torrent/common.h" | ||
#include "torrent/utils/log.h" | ||
|
@@ -106,7 +71,7 @@ enum instrumentation_enum { | |
INSTRUMENTATION_MAX_SIZE | ||
}; | ||
|
||
extern std::array<int64_t, INSTRUMENTATION_MAX_SIZE> instrumentation_values lt_cacheline_aligned; | ||
extern std::array<std::atomic_int64_t, INSTRUMENTATION_MAX_SIZE> instrumentation_values; | ||
|
||
void instrumentation_initialize(); | ||
void instrumentation_update(instrumentation_enum type, int64_t change); | ||
|
@@ -125,7 +90,7 @@ instrumentation_initialize() { | |
inline void | ||
instrumentation_update(instrumentation_enum type, int64_t change) { | ||
#ifdef LT_INSTRUMENTATION | ||
__sync_add_and_fetch(&instrumentation_values[type], change); | ||
instrumentation_values[type] += change; | ||
#endif | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.