summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-08-09 23:53:39 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-08-16 21:01:38 +0000
commit54066f338f185f2fbd6694d9a4877f42cbfa21c8 (patch)
treee056e50af1009bf373c040812e46cd1de8de9979 /toxcore
parent31ea1aa06e59d24d5196b17be9a7105d85c25080 (diff)
Reduce the number of times `unix_time_update` is called.
Reduced by, e.g.: * `file_transfer_test`: 33% of the `clock_gettime` calls. * `tox_many_test`: 53% of the `clock_gettime` calls. Other tests will see similar improvements. Real world applications will be closer to 40-50% improvement, since tox_many_test has 100 nodes, while file_transfer_test has 2 nodes.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/DHT.c9
-rw-r--r--toxcore/Messenger.c2
-rw-r--r--toxcore/TCP_client.c2
-rw-r--r--toxcore/TCP_server.c2
-rw-r--r--toxcore/net_crypto.c3
-rw-r--r--toxcore/network.c2
-rw-r--r--toxcore/tox.c5
7 files changed, 5 insertions, 20 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 37dd9385..94928b75 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -2690,9 +2690,6 @@ static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *pack
2690 2690
2691DHT *new_dht(const Logger *log, Networking_Core *net, bool holepunching_enabled) 2691DHT *new_dht(const Logger *log, Networking_Core *net, bool holepunching_enabled)
2692{ 2692{
2693 /* init time */
2694 unix_time_update();
2695
2696 if (net == nullptr) { 2693 if (net == nullptr) {
2697 return nullptr; 2694 return nullptr;
2698 } 2695 }
@@ -2741,8 +2738,6 @@ DHT *new_dht(const Logger *log, Networking_Core *net, bool holepunching_enabled)
2741 2738
2742void do_dht(DHT *dht) 2739void do_dht(DHT *dht)
2743{ 2740{
2744 unix_time_update();
2745
2746 if (dht->last_run == unix_time()) { 2741 if (dht->last_run == unix_time()) {
2747 return; 2742 return;
2748 } 2743 }
@@ -2963,8 +2958,6 @@ int dht_load(DHT *dht, const uint8_t *data, uint32_t length)
2963 */ 2958 */
2964bool dht_isconnected(const DHT *dht) 2959bool dht_isconnected(const DHT *dht)
2965{ 2960{
2966 unix_time_update();
2967
2968 for (uint32_t i = 0; i < LCLIENT_LIST; ++i) { 2961 for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
2969 const Client_data *const client = &dht->close_clientlist[i]; 2962 const Client_data *const client = &dht->close_clientlist[i];
2970 2963
@@ -2982,8 +2975,6 @@ bool dht_isconnected(const DHT *dht)
2982 */ 2975 */
2983bool dht_non_lan_connected(const DHT *dht) 2976bool dht_non_lan_connected(const DHT *dht)
2984{ 2977{
2985 unix_time_update();
2986
2987 for (uint32_t i = 0; i < LCLIENT_LIST; ++i) { 2978 for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
2988 const Client_data *const client = &dht->close_clientlist[i]; 2979 const Client_data *const client = &dht->close_clientlist[i];
2989 2980
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index acf9f806..ab341e61 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -2603,8 +2603,6 @@ void do_messenger(Messenger *m, void *userdata)
2603 } 2603 }
2604 } 2604 }
2605 2605
2606 unix_time_update();
2607
2608 if (!m->options.udp_disabled) { 2606 if (!m->options.udp_disabled) {
2609 networking_poll(m->net, userdata); 2607 networking_poll(m->net, userdata);
2610 do_dht(m->dht); 2608 do_dht(m->dht);
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c
index 381d9b80..d6a27c95 100644
--- a/toxcore/TCP_client.c
+++ b/toxcore/TCP_client.c
@@ -985,8 +985,6 @@ static int do_confirmed_TCP(TCP_Client_Connection *conn, void *userdata)
985 */ 985 */
986void do_TCP_connection(TCP_Client_Connection *tcp_connection, void *userdata) 986void do_TCP_connection(TCP_Client_Connection *tcp_connection, void *userdata)
987{ 987{
988 unix_time_update();
989
990 if (tcp_connection->status == TCP_CLIENT_DISCONNECTED) { 988 if (tcp_connection->status == TCP_CLIENT_DISCONNECTED) {
991 return; 989 return;
992 } 990 }
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index cc59d088..207a5107 100644
--- a/toxcore/TCP_server.c
+++ b/toxcore/TCP_server.c
@@ -1424,8 +1424,6 @@ static void do_TCP_epoll(TCP_Server *tcp_server)
1424 1424
1425void do_TCP_server(TCP_Server *tcp_server) 1425void do_TCP_server(TCP_Server *tcp_server)
1426{ 1426{
1427 unix_time_update();
1428
1429#ifdef TCP_SERVER_USE_EPOLL 1427#ifdef TCP_SERVER_USE_EPOLL
1430 do_TCP_epoll(tcp_server); 1428 do_TCP_epoll(tcp_server);
1431 1429
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 8f5fd507..bd214b91 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -2925,8 +2925,6 @@ void load_secret_key(Net_Crypto *c, const uint8_t *sk)
2925 */ 2925 */
2926Net_Crypto *new_net_crypto(const Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info) 2926Net_Crypto *new_net_crypto(const Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info)
2927{ 2927{
2928 unix_time_update();
2929
2930 if (dht == nullptr) { 2928 if (dht == nullptr) {
2931 return nullptr; 2929 return nullptr;
2932 } 2930 }
@@ -3016,7 +3014,6 @@ uint32_t crypto_run_interval(const Net_Crypto *c)
3016/* Main loop. */ 3014/* Main loop. */
3017void do_net_crypto(Net_Crypto *c, void *userdata) 3015void do_net_crypto(Net_Crypto *c, void *userdata)
3018{ 3016{
3019 unix_time_update();
3020 kill_timedout(c, userdata); 3017 kill_timedout(c, userdata);
3021 do_tcp(c, userdata); 3018 do_tcp(c, userdata);
3022 send_crypto_packets(c); 3019 send_crypto_packets(c);
diff --git a/toxcore/network.c b/toxcore/network.c
index 68ca43e5..08bec13a 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -641,8 +641,6 @@ void networking_poll(Networking_Core *net, void *userdata)
641 return; 641 return;
642 } 642 }
643 643
644 unix_time_update();
645
646 IP_Port ip_port; 644 IP_Port ip_port;
647 uint8_t data[MAX_UDP_PACKET_SIZE]; 645 uint8_t data[MAX_UDP_PACKET_SIZE];
648 uint32_t length; 646 uint32_t length;
diff --git a/toxcore/tox.c b/toxcore/tox.c
index cd1b71f0..879b5c09 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -38,6 +38,7 @@
38#include "Messenger.h" 38#include "Messenger.h"
39#include "group.h" 39#include "group.h"
40#include "logger.h" 40#include "logger.h"
41#include "mono_time.h"
41 42
42#include "../toxencryptsave/defines.h" 43#include "../toxencryptsave/defines.h"
43 44
@@ -335,6 +336,8 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
335 return nullptr; 336 return nullptr;
336 } 337 }
337 338
339 unix_time_update();
340
338 Messenger_Options m_options = {0}; 341 Messenger_Options m_options = {0};
339 342
340 bool load_savedata_sk = false, load_savedata_tox = false; 343 bool load_savedata_sk = false, load_savedata_tox = false;
@@ -653,6 +656,8 @@ uint32_t tox_iteration_interval(const Tox *tox)
653 656
654void tox_iterate(Tox *tox, void *user_data) 657void tox_iterate(Tox *tox, void *user_data)
655{ 658{
659 unix_time_update();
660
656 Messenger *m = tox->m; 661 Messenger *m = tox->m;
657 struct Tox_Userdata tox_data = { tox, user_data }; 662 struct Tox_Userdata tox_data = { tox, user_data };
658 do_messenger(m, &tox_data); 663 do_messenger(m, &tox_data);