::switch_item_lock_type
void switch_item_lock_type(enum item_lock_types type) {
char buf[1];
int i;
switch (type) {
case ITEM_LOCK_GRANULAR:
buf[0] = ‘l‘;
break;
case ITEM_LOCK_GLOBAL:
buf[0] = ‘g‘;
break;
default:
fprintf(stderr, "Unknown lock type: %d\n", type);
assert(1 == 0);
break;
}
pthread_mutex_lock(&init_lock);
init_count = 0;
for (i = 0; i < settings.num_threads; i++) {
if (write(threads[i].notify_send_fd, buf, 1) != 1) { /* Listen for notifications from other threads */往管道写状态
perror("Failed writing to notify pipe");
/* TODO: This is a fatal problem. Can it ever happen temporarily? */
}
}
wait_for_thread_registration(settings.num_threads); //等待每个线程处理完设置完锁的类型,然后一直等待!!![标签1]
pthread_mutex_unlock(&init_lock);
}