fix progress bar deadlock
This commit is contained in:
parent
bd92bc47f2
commit
b3ddb92786
3
client.c
3
client.c
@ -419,6 +419,7 @@ int main(int argc, const char *argv[]){
|
||||
|
||||
init_bench_data();
|
||||
if(parse_arg(argc,argv) < 0) return EXIT_FAILURE;
|
||||
ready_progress_bar();
|
||||
|
||||
err = getsockaddrbyname(AF_INET,SOCK_STREAM,0,cmd_args.server_name,(struct sockaddr *)&addr);
|
||||
if (err != 0){
|
||||
@ -480,6 +481,6 @@ int main(int argc, const char *argv[]){
|
||||
fprintf(stdout,"operation: %lf us/op\n",avg / 1000.0);
|
||||
fprintf(stdout,"resolution: %ld sec %ld ns\n",bench.resolution.tv_sec,bench.resolution.tv_nsec);
|
||||
}
|
||||
|
||||
quit_progress_bar();
|
||||
return retval;
|
||||
}
|
@ -6,6 +6,9 @@
|
||||
#include<unistd.h>
|
||||
#include<termio.h>
|
||||
#include<pthread.h>
|
||||
#include<stdlib.h>
|
||||
#include<unistd.h>
|
||||
#include<fcntl.h>
|
||||
|
||||
#include "display_bar.h"
|
||||
#include "timerhelper.h"
|
||||
@ -25,15 +28,34 @@ enum{
|
||||
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static raw_progress_bar_t scrolled = 1;
|
||||
static int tty_fd = STDIN_FILENO;
|
||||
#ifdef DEBUG
|
||||
static int deadlock = 0;
|
||||
#endif
|
||||
|
||||
void ready_progress_bar(){
|
||||
fflush(stdout);
|
||||
if(!isatty(STDIN_FILENO)){
|
||||
char * buf = ctermid(NULL);
|
||||
tty_fd = open(buf,O_RDONLY);
|
||||
}
|
||||
}
|
||||
|
||||
void lock_scrolled(){
|
||||
#ifdef DEBUG
|
||||
deadlock++;
|
||||
if (deadlock > 1)
|
||||
{
|
||||
fprintf(stderr,"deadlock occur\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
pthread_mutex_lock(&mutex);
|
||||
}
|
||||
void unlock_scrolled(){
|
||||
#ifdef DEBUG
|
||||
deadlock--;
|
||||
#endif
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
@ -75,7 +97,10 @@ void RawDisplayProgressBar(raw_progress_bar_t bar,size_t offset,size_t total,con
|
||||
}//optimization.
|
||||
//if ioctl failed? what should i do...
|
||||
ioctl(STDIN_FILENO,TIOCGWINSZ,(char *)&wnd_size);
|
||||
if (wnd_size.ws_row < pos) return;
|
||||
if (wnd_size.ws_row < pos){
|
||||
unlock_scrolled();
|
||||
return;
|
||||
}
|
||||
fprintf(stdout,"\x1b[%dA[%s]: %.2f%% %s bytes: %ld/%ld \x1b[%dB\r",pos,buf,cur_progress,filename,total,offset,pos);
|
||||
fflush(stdout);
|
||||
unlock_scrolled();
|
||||
@ -116,3 +141,9 @@ void DisplayProgressBar(progress_bar_t * bar,size_t offset,size_t total,const ch
|
||||
bar->last_update = ts;
|
||||
RawDisplayProgressBar(bar->bar,offset,total,filename);
|
||||
}
|
||||
|
||||
void quit_progress_bar(){
|
||||
if(tty_fd != STDIN_FILENO){
|
||||
close(tty_fd);
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@ void unlock_scrolled();
|
||||
|
||||
void ready_progress_bar();
|
||||
|
||||
void quit_progress_bar();
|
||||
|
||||
void add_scrolled_unlocked(unsigned int i);
|
||||
|
||||
raw_progress_bar_t create_raw_progress_bar();
|
||||
|
1000
testdata/dlist.txt
vendored
Normal file
1000
testdata/dlist.txt
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user