2007年1月31日星期三

一个linux下面的线程池(个人注解)

http://blog.csdn.net/phus/archive/2005/06/09/390745.aspx
thrmgr.h文件

/*
 *  Copyright (C) 2004 Trog <trog@clamav.net >
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef __THRMGR_H__
#define __THRMGR_H__

#include <pthread.h>
#include <sys/time.h>

typedef struct work_item_tag {
 struct work_item_tag *next;
 void *data;
 struct timeval time_queued;
} work_item_t;
 
typedef struct work_queue_tag {
 work_item_t *head;
 work_item_t *tail;
 int item_count;
} work_queue_t;

typedef enum {
 POOL_INVALID,
 POOL_VALID,
 POOL_EXIT,
} pool_state_t;

typedef struct threadpool_tag {
 pthread_mutex_t pool_mutex;
 pthread_cond_t pool_cond;
 pthread_attr_t pool_attr;
 
 pool_state_t state;
 int thr_max;
 int thr_alive;
 int thr_idle;
 int idle_timeout;
 
 void (*handler)(void *);
 
 work_queue_t *queue;
} threadpool_t;

threadpool_t *thrmgr_new(int max_threads, int idle_timeout, void (*handler)(void *));
void thrmgr_destroy(threadpool_t *threadpool);
int thrmgr_dispatch(threadpool_t *threadpool, void *user_data);

2 条评论:

匿名 说...

You actually make it seem so easy with your
presentation but I find this matter to be actually something that I
think I might never understand. It seems too complex and very broad for me.

I am looking ahead on your subsequent submit, I will attempt to get the grasp of it!


Take a look at my website ... asbestos law firms

匿名 说...

Wow! At last I got a webpage from where I be able to truly get helpful facts regarding my study
and knowledge.

Here is my web page; term life insurance agent