add comment
This commit is contained in:
parent
d177b33177
commit
f2e8bf2376
@ -1,29 +1,30 @@
|
||||
#include<stdio.h>
|
||||
#include<time.h>
|
||||
#include<stdbool.h>
|
||||
#include<stddef.h>
|
||||
|
||||
#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;
|
||||
|
16
server.c
16
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);
|
||||
|
@ -2,6 +2,10 @@
|
||||
#define _TIMERHELPER_H_
|
||||
#include <sys/time.h>
|
||||
|
||||
#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;
|
||||
|
Loading…
Reference in New Issue
Block a user