mirror of
https://github.com/upa/mscp.git
synced 2026-05-21 21:07:31 +08:00
set nr_threads to # of chunks if # of chunks is small
This commit is contained in:
15
src/main.c
15
src/main.c
@@ -55,7 +55,7 @@ struct mscp_thread {
|
|||||||
void *mscp_copy_thread(void *arg);
|
void *mscp_copy_thread(void *arg);
|
||||||
void *mscp_monitor_thread(void *arg);
|
void *mscp_monitor_thread(void *arg);
|
||||||
|
|
||||||
static pthread_t mtid;
|
pthread_t mtid;
|
||||||
struct mscp_thread *threads;
|
struct mscp_thread *threads;
|
||||||
int nr_threads;
|
int nr_threads;
|
||||||
|
|
||||||
@@ -69,6 +69,14 @@ void stop_copy_threads(int sig)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int list_count(struct list_head *head)
|
||||||
|
{
|
||||||
|
int n = 0;
|
||||||
|
struct list_head *p;
|
||||||
|
|
||||||
|
list_for_each(p, head) n++;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
void usage(bool print_help) {
|
void usage(bool print_help) {
|
||||||
printf("mscp v" VERSION ": copy files over multiple ssh connections\n"
|
printf("mscp v" VERSION ": copy files over multiple ssh connections\n"
|
||||||
@@ -318,6 +326,11 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* prepare thread instances */
|
/* prepare thread instances */
|
||||||
|
if ((n = list_count(&m.chunk_list)) < nr_threads) {
|
||||||
|
pprint3("we have only %d chunk(s). set nr_conns to %d\n", n, n);
|
||||||
|
nr_threads = n;
|
||||||
|
}
|
||||||
|
|
||||||
threads = calloc(nr_threads, sizeof(struct mscp_thread));
|
threads = calloc(nr_threads, sizeof(struct mscp_thread));
|
||||||
memset(threads, 0, nr_threads * sizeof(struct mscp_thread));
|
memset(threads, 0, nr_threads * sizeof(struct mscp_thread));
|
||||||
for (n = 0; n < nr_threads; n++) {
|
for (n = 0; n < nr_threads; n++) {
|
||||||
|
|||||||
@@ -3,11 +3,6 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
static int pprint_level = 1;
|
static int pprint_level = 1;
|
||||||
/* level 1: print progress bar only.
|
|
||||||
* level 2: print copy start/done messages.
|
|
||||||
* level 3: print ssh connection establishment/disconnection.
|
|
||||||
* level 4: print chunk information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static pthread_mutex_t pprint_lock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t pprint_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,11 @@
|
|||||||
|
|
||||||
/* progress print functions */
|
/* progress print functions */
|
||||||
|
|
||||||
|
/* level 1: print progress bar only.
|
||||||
|
* level 2: print copy start/done messages.
|
||||||
|
* level 3: print ssh connection establishment/disconnection.
|
||||||
|
* level 4: print chunk information.
|
||||||
|
*/
|
||||||
void pprint_set_level(int level);
|
void pprint_set_level(int level);
|
||||||
void pprint(int level, const char *fmt, ...);
|
void pprint(int level, const char *fmt, ...);
|
||||||
|
|
||||||
@@ -11,4 +16,5 @@ void pprint(int level, const char *fmt, ...);
|
|||||||
#define pprint3(fmt, ...) pprint(3, "\r\033[K" fmt, ##__VA_ARGS__)
|
#define pprint3(fmt, ...) pprint(3, "\r\033[K" fmt, ##__VA_ARGS__)
|
||||||
#define pprint4(fmt, ...) pprint(4, "\r\033[K" fmt, ##__VA_ARGS__)
|
#define pprint4(fmt, ...) pprint(4, "\r\033[K" fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
#endif /* _PPRRINT_H_ */
|
#endif /* _PPRRINT_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user