代码拉取完成,页面将自动刷新
同步操作将从 方瑾/async 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "io.h"
void creatIoServicePthread(IoService service) {
service->serviceThreadInfo = newServiceThreadInfo();
if (service->serviceThreadInfo == NULL) {
return;
}
pthread_cond_init(&(service->serviceThreadInfo->notifyCond), NULL);
pthread_cond_init(&(service->serviceThreadInfo->waitTimeoutCond), NULL);
pthread_mutex_init(&(service->serviceThreadInfo->notify), NULL);
pthread_mutex_init(&(service->serviceThreadInfo->undeal), NULL);
pthread_mutex_init(&(service->serviceThreadInfo->finish), NULL);
pthread_mutex_init(&(service->serviceThreadInfo->waitTimeout), NULL);
pthread_mutex_init(&(service->serviceThreadInfo->event), NULL);
pthread_create(&(service->serviceThreadInfo->pid), NULL, runIO, service);
}
void runIO(let args) {
// 允许退出线程
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
// 异步取消,线程接到取消信号后立即退出
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
IoService service = (IoService)args;
puts("io server start ....");
while (True) {
// 检查取消点
pthread_testcancel();
if (service->undealQueue->length != 0) {
// 从待处理中取出任务
pthread_mutex_lock(&(service->serviceThreadInfo->undeal));
IoEvent ioEvent = (IoEvent)service->undealQueue->shift(service->undealQueue);
pthread_mutex_unlock(&(service->serviceThreadInfo->undeal));
// 处理io事件
_sleep(100);
switch (ioEvent->eventType) {
case AccessFileEvent:
ioEvent->result = access(ioEvent->path, ioEvent->otherParams) == 0 ? True : False;
ioEvent->error = NULL;
break;
default: break;
}
pthread_mutex_lock(&(service->serviceThreadInfo->waitTimeout));
pthread_cond_signal(&(service->serviceThreadInfo->waitTimeoutCond), &(service->serviceThreadInfo->waitTimeout));
pthread_mutex_unlock(&(service->serviceThreadInfo->waitTimeout));
// 已完成的任务放到已完成队列中
pthread_mutex_lock(&(service->serviceThreadInfo->finish));
service->finishQueue->push(service->finishQueue, ioEvent);
pthread_mutex_unlock(&(service->serviceThreadInfo->finish));
}
else {
// 没有待处理任务,则等待主线程唤醒
pthread_mutex_lock(&(service->serviceThreadInfo->notify));
pthread_cond_wait(&(service->serviceThreadInfo->notifyCond), &(service->serviceThreadInfo->notify));
pthread_mutex_unlock(&(service->serviceThreadInfo->notify));
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。