iothreads代码阅读笔记.doc
文本预览下载声明
1.常见数据结构
1)io请求结构,对stub的简单封装,将stub组织成双向队列
struct iot_request {
struct list_head list; /* 将io请求加入链表*/
call_stub_t *stub;
};
2)工作者结构,负责为请求服务
struct iot_worker {
struct list_head rqlist; /* 分派给我的io请求链表*/
struct iot_conf *conf;
int64_t q,dq;
pthread_cond_t dq_cond;
pthread_mutex_t qlock;
int32_t queue_size;
pthread_t thread;
int state; /* 线程所处状态. */
int thread_idx;
/* Threads index into the worker array. Since this will be thread local data,for ensuring that number of threads dont fall below a minimum, we just dont allow threads with specific indices to exit. Helps us in eliminating one place where otherwise a lock would have been required to update centralized state inside conf. */
};
struct iot_conf {
int32_t thread_count;
struct iot_worker **workers;
xlator_t *this;
/* Config state for ordered threads. */
pthread_mutex_t otlock; /* Used to sync any state that needs
to be changed by the ordered
threads.
*/
int max_o_threads;
/* 已排序(ordered)线程的最大数目*/
int min_o_threads;
/* 已排序线程的最小值,已排序线程的数目永远不低于这个数目*/
int o_idle_time;
/*以秒为单位,某已排序线程退出后的空闲时间*/
gf_boolean_t o_scaling;
/*如果用户不想动态增减线程数目,则设置为IOT_SCALING_OFF。此时,io-threads维护维护min_o
显示全部