From f2e8bf237676c6a5777c9e3b98a827cb7c5922c3 Mon Sep 17 00:00:00 2001 From: ubuntu201711081 <201711081@jbnu.ac.kr> Date: Mon, 14 Dec 2020 10:19:49 +0000 Subject: [PATCH] add comment --- display_bar.h | 17 +++++++++-------- server.c | 16 +++++++++------- timerhelper.h | 4 ++++ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/display_bar.h b/display_bar.h index 7bdc170..46b1d10 100644 --- a/display_bar.h +++ b/display_bar.h @@ -1,29 +1,30 @@ #include #include #include +#include #ifndef _DISPLAY_BAR_H_ #define _DISPLAY_BAR_H_ +//declare for raw operation typedef unsigned raw_progress_bar_t; void lock_scrolled(); - 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(); - void RawDisplayProgressBar(raw_progress_bar_t bar,size_t offset,size_t total,const char * filename); +//you should call before using progrees bar. +void ready_progress_bar(); +//quit progress bar system. +void quit_progress_bar(); +//same as isatty bool isatty_file(FILE * file); +// void myd_perror(const char * msg); +int myd_vfprintf(int line,FILE * f,const char * msg,va_list arg); typedef struct { raw_progress_bar_t bar; diff --git a/server.c b/server.c index 40915c4..d65cf02 100644 --- a/server.c +++ b/server.c @@ -301,9 +301,9 @@ int parse_args(int argc,const char * argv[] , in_port_t * port){ typedef struct SharedState{ //empty if less than 0 queue_struct(int,WORK_QUEUE_SIZE) socks; -#ifdef USE_TRACE + #ifdef USE_TRACE queue_struct(struct timespec,WORK_QUEUE_SIZE) trace_timer; -#endif + #endif pthread_mutex_t sock_mutex; pthread_cond_t ready; //int progress[MAX_THREAD_NUMBER]; @@ -311,14 +311,14 @@ typedef struct SharedState{ void init_shared_state(shared_state_t * state) { queue_init(&state->socks); -#ifdef USE_TRACE + #ifdef USE_TRACE queue_init(&state->trace_timer); -#endif + #endif pthread_mutex_init(&state->sock_mutex,NULL); pthread_cond_init(&state->ready,NULL); } #endif -// +//argument for thread worker typedef struct WorkerArgument { int id; @@ -365,10 +365,11 @@ void * worker_proc(void * data){ #endif for(;;){ pthread_mutex_lock(&globalState.sock_mutex); + //wait until request come. while (queue_isempty(&globalState.socks)){ pthread_cond_wait(&globalState.ready,&globalState.sock_mutex); } - csock = dequeue(&globalState.socks); + csock = dequeue(&globalState.socks); //dequeue socket descriptor for request. #ifdef USE_TRACE ts_top_begin = dequeue(&globalState.trace_timer); #endif @@ -377,6 +378,7 @@ void * worker_proc(void * data){ clock_gettime(Top_Trace_Timer_ID,&ts_top_end); clock_gettime(Bottom_Trace_Timer_ID,&ts_bottom_begin); #endif + //process request. if((fd = read_request(csock,args->buf,args->bufsize)) > 0){ send_response(csock,fd,args->buf,args->bufsize); close(fd); @@ -454,7 +456,7 @@ int main(int argc, const char *argv[]){ if(use_gui) ready_progress_bar(); #ifdef USE_TRACE - report_resolution(); + report_resolution(); #endif sock = socket(AF_INET,SOCK_STREAM,0); atexit(safe_exit); diff --git a/timerhelper.h b/timerhelper.h index ae90e96..fc4ae26 100644 --- a/timerhelper.h +++ b/timerhelper.h @@ -2,6 +2,10 @@ #define _TIMERHELPER_H_ #include +#ifndef __always_inline +#define __always_inline +#endif + __always_inline struct timespec timespec_sub(struct timespec a,struct timespec b){ struct timespec ret; ret.tv_sec = a.tv_sec - b.tv_sec;