Chinaunix首页 | 论坛 | 博客
  • 博客访问: 60183
  • 博文数量: 40
  • 博客积分: 1607
  • 博客等级: 上尉
  • 技术积分: 382
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-09 16:35
文章分类

全部博文(40)

文章存档

2011年(1)

2010年(30)

2009年(9)

我的朋友

分类: LINUX

2010-02-28 12:31:35

/*-
 * Copyright (c) 2006 Verdens Gang AS
 * Copyright (c) 2006-2008 Linpro AS
 * All rights reserved.
 *
 * Author: Poul-Henning Kamp
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: cache_main.c 3615 2009-02-05 11:38:45Z tfheen $
 */


#include "config.h"

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>

#include "shmlog.h"
#include "cache.h"
#include "stevedore.h"
#include "hash_slinger.h"

/*--------------------------------------------------------------------
 * Per thread storage for the session currently being processed by
 * the thread. This is used for panic messages.
 */


static pthread_key_t sp_key;

void
THR_SetSession(const struct sess *sp)
{

    AZ(pthread_setspecific(sp_key, sp));
}

const struct sess *
THR_GetSession(void)
{

    return (pthread_getspecific(sp_key));
}

/*--------------------------------------------------------------------
 * Name threads if our pthreads implementation supports it.
 */


static pthread_key_t name_key;

void
THR_SetName(const char *name)//来自pthread.h

{

    AZ(pthread_setspecific(name_key, name));
#ifdef HAVE_PTHREAD_SET_NAME_NP
    pthread_set_name_np(pthread_self(), name);
#endif
}

const char *
THR_GetName(void)
{

    return (pthread_getspecific(name_key));
}

/*--------------------------------------------------------------------
 * XXX: Think more about which order we start things
 */


void
child_main(void)
{

    setbuf(stdout, NULL);
    setbuf(stderr, NULL);
    printf("Child starts\n");

    AZ(pthread_key_create(&sp_key, NULL));//pthread.h中出现,属于unix标准库里面的

    AZ(pthread_key_create(&name_key, NULL));

    THR_SetName("cache-main");

    VSL_Init();    /* First, LCK needs it. */ //初始化一个varnsh_share_log,详见shmlog.c


    LCK_Init();    /* Locking, must be first */
    //lock the cache

    //Build our own locks on top of pthread mutexes and hope that the next

     //civilization is better at such crucial details than this one.

    //

    PAN_Init(); //cahe_panic.c这里目前感觉就是发现cache的问题,就是它是否panic的验证

     CLI_Init(); //读取command line 的功能修改命令

    Fetch_Init(); // 根据cli结果设置fetch方式


    CNT_Init(); //cache_center.c,有注释,但是不是很清楚其中作用

    VCL_Init(); //加载vcl的选项,利用vcl动态编译后的文件


    HTTP_Init(); //http头的一些描述

    SES_Init(); //work周期初始化


    VBE_Init();//对backend状态的初始化

    VBP_Init();//这个还得琢磨琢磨

    WRK_Init(); //这个可是重头戏

    EXP_Init()// 初始化expire线程

    HSH_Init(); //hash存储模块初始化

    BAN_Init(); //疑似为限定条件条件初始

    VCA_Init();// hash接收器??

    SMS_Init();//存储互斥综合体??

    STV_open(); //搬运??


    VSL_stats->start_time = (time_t)TIM_real(); //Varnish Share-memory Log 设置启动时间


    CLI_Run(); //安照commande-line的启动


    printf("Child dies\n");
}


阅读(356) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~