Linux?????????????????
???????????? ???????[ 2014/10/9 10:51:50 ] ?????????????? Linux
??????????????????????????????????????????????????????????С?
??????????????:
1 #include "head.h"
2 void fd_init(pFD *phead)
3 {
4 *phead= NULL;
5 }
6 void fd_insert(pFD *phead??int rfd??int wfd)
7 {
8 pFD pnew = (pFD )calloc(1??sizeof(FD));
9 pnew->s_rfd=rfd;
10 pnew->s_wfd=wfd;
11 pnew->next = *phead;
12 *phead = pnew;
13 }
14 int fd_find(pFD phead??int rfd)
15 {
16 while(phead)
17 {
18 if(phead->s_rfd==rfd)
19 break;
20 else
21 phead = phead->next;
22 }
23 if(phead == NULL)
24 return -1;
25 else
26 return phead->s_wfd;
27 }
28
29 void fd_del(pFD *phead??int rfd)
30 {
31 pFD pcur??ppre;
32 pcur=*phead;
33 ppre=NULL;
34 while(pcur)
35 {
36 if(pcur->s_rfd == rfd)
37 break;
38 else
39 {
40 ppre=pcur;
41 pcur = pcur ->next;
42 }
43 }
44 if(ppre==NULL)
45 {
46 *phead=pcur->next;
47 free(pcur);
48 pcur=NULL;
49 }
50 else
51 {
52 ppre->next=pcur->next;
53 free(pcur);
54 pcur=NULL;
55 }
56 }
???????????????????????????????????????????á???е??
??????????????:
1 #include "head.h"
2 static int que_empty(pQUEUE pq)
3 {
4 return pq->front == pq->tail;
5 }
6 static int que_full(pQUEUE pq)
7 {
8 return (pq->tail+1)%(TASK_CNT+1)==pq->front;
9 }
10 static int que_cnt(pQUEUE pq)
11 {
12 return (pq->tail - pq->front +TASK_CNT+1)%(TASK_CNT + 1);
13 }
14 void add_task(pQUEUE pq ??pTASK pt)
15 {
16 pthread_mutex_lock(&lock);
17 while(que_full(pq))
18 pthread_cond_wait(&cond1??&lock);
19 pq->arr[pq->tail]=*pt;
20 pq->tail = (pq->tail+1)%(TASK_CNT+1);
21 if(que_cnt(pq)==1)
22 pthread_cond_broadcast(&cond2);
23 printf("????????????!! ");
24 pthread_mutex_unlock(&lock);
25 }
26 void get_task(pQUEUE pq ??pTASK pt)
27 {
28 pthread_mutex_lock(&lock);
29 while(que_empty(pq))
30 pthread_cond_wait(&cond2??&lock);
31 *pt=pq->arr[pq->front];
32 pq->front = (pq->front+1)%(TASK_CNT+1);
33 if(que_cnt(pq)== TASK_CNT -1)
34 pthread_cond_broadcast(&cond1);
35 printf("????????????!! ");
36 pthread_mutex_unlock(&lock);
37 }
38
39
40 void excute_task(pTASK pt)
41 {
42 char buf[1024];
43 memset(buf??0??1024);
44 strcpy(buf??pt->s_msg);
45 int index;
46 for(index=0;index < strlen(buf);index++)
47 buf[index]=toupper(buf[index]);
48 buf[index]='