⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dblfcns.c

📁 db.* (pronounced dee-be star) is an advanced, high performance, small footprint embedded database fo
💻 C
📖 第 1 页 / 共 4 页
字号:
        task->no_of_dbs = 0;        task->dbwait_time = 1;        task->db_lockmgr = 0;        task->session_active = FALSE;        task->cache_ovfl = FALSE;        task->ov_initaddr = 0L;        task->ov_rootaddr = 0L;        task->ov_nextaddr = 0L;        task->size_ft = 0;        task->size_rt = 0;        task->size_fd = 0;        task->size_st = 0;        task->size_mt = 0;        task->size_srt = 0;        task->size_kt = 0;        task->no_of_keys = 0;        task->dbopen = 0;        task->page_size = 0;        task->curr_rec = NULL_DBA;    }    else    {        /* incremental close, adjust current database information */        task->no_of_dbs--;        /* if the current database if less than the closed database,            no adjustment is necessary        */        if (task->curr_db >= dbn)        {            if (task->curr_db > dbn)                task->curr_db--;            else            {                /* if task->curr_db was the one closed, set to 0 */                task->curr_db = 0;            }            task->curr_db_table = &task->db_table[task->curr_db];            task->curr_rn_table = &task->rn_table[task->curr_db];            task->curr_rec = task->curr_db_table->curr_dbt_rec;        }        if (task->set_db >= dbn)        {            if (task->set_db > dbn)                task->set_db--;            else            {                /* if task->set_db was the one closed, set to 0 */                task->set_db = 0;            }        }    }    return (task->db_status);}/* ======================================================================    Terminate lock manager session*/static int INTERNAL_FCN termses(int dbn, DB_TASK *task){    LM_DBCLOSE       *send_pkt;    register int      ft_lc;    FILE_ENTRY       *file_ptr;    int               total;    unsigned short    send_size;    register FILE_NO *fref_ptr;    register short   *snd_fref_ptr;    int               low, high;    if (task->session_active)    {        if (dbn == ALL_DBS)        {            low  = 0;            high = task->size_ft;        }        else        {            low  = task->db_table[dbn].ft_offset;            high = task->db_table[dbn].Size_ft;        }        for (total = 0, ft_lc = high, file_ptr = &task->file_table[low];             --ft_lc >= 0; ++file_ptr)        {            if (!(file_ptr->ft_flags & TEMPORARY))                ++total;        }        send_size = (unsigned short)sizeof(LM_DBCLOSE) + (total - 1) * sizeof(short);        send_pkt = (LM_DBCLOSE *) psp_lmcAlloc(send_size);        if (send_pkt == NULL)            return (dberr(S_NOMEMORY));        /* copy the file reference numbers into packet */        for ( ft_lc = high, fref_ptr = &task->file_refs[low],              snd_fref_ptr = send_pkt->frefs, file_ptr = &task->file_table[low];              --ft_lc >= 0; ++fref_ptr, ++file_ptr)        {            if (!(file_ptr->ft_flags & TEMPORARY))                *snd_fref_ptr++ = *fref_ptr;        }        send_pkt->nfiles = (short) total;        msg_trans(L_DBCLOSE, send_pkt, send_size, NULL, NULL, task);        psp_lmcFree(send_pkt);        /* close the session with the lockmgr only if final close */        if (dbn == ALL_DBS)        {            msg_trans(L_LOGOUT, NULL, 0, NULL, NULL, task);            psp_lmcDisconnect(task->lmc);        }    }    return (task->db_status);}/* ======================================================================    Free all allocated memory upon termination*/void INTERNAL_FCN termfree(int dbn, DB_TASK *task){    int                 low;    int                 high;    int                 total;    register int        i;    int                 j;    FILE_NO            *fl_ptr;    struct lock_descr  *ld_ptr;    FIELD_ENTRY        *fld_ptr;    int                 fd_lc;    int                 extra_file = 0;          /* for ONE_DB */    int                 temp;    DB_ENTRY           *db_ptr;    DB_ENTRY           *close_db_ptr;    extra_file = 1;    /* free all allocated memory */    if (dbn == ALL_DBS)    {        low = 0;        high = task->size_st;        total = task->size_st;    }    else    {        low = task->db_table[dbn].st_offset;        high = low + task->db_table[dbn].Size_st;        total = task->size_st;    }    if (task->curr_mem)    {        free_table((void **) &task->curr_mem, low, high, total, sizeof(DB_ADDR),                task);    }    if (task->curr_own)    {        free_table((void **) &task->curr_own, low, high, total, sizeof(DB_ADDR),                task);    }    if (task->co_time)    {        free_table((void **) &task->co_time, low, high, total, sizeof(DB_ULONG),                task);    }    if (task->cm_time)    {        free_table((void **) &task->cm_time, low, high, total, sizeof(DB_ULONG),                task);    }    if (task->cs_time)    {        free_table((void **) &task->cs_time, low, high, total, sizeof(DB_ULONG),                task);    }    if (task->set_table)    {        if (total > high && high >= 0)        {            for (i = high; i < total; i++)            {                task->set_table[i].st_own_rt -= task->db_table[dbn].Size_rt;                task->set_table[i].st_members -= task->db_table[dbn].Size_mt;            }        }        free_table((void **) &task->set_table, low, high, total,                sizeof(SET_ENTRY), task);        if (task->set_names)        {            free_table((void **) &task->set_names, low, high, total,                    sizeof(DB_TCHAR *), task);        }    }    if (task->set_locks)    {        for (i = (dbn == ALL_DBS) ? 0 : task->db_table[dbn].st_offset,              ld_ptr = &task->set_locks[i];              i < ((dbn == ALL_DBS)                ? task->size_st : task->db_table[dbn].st_offset + task->db_table[dbn].Size_st);              ++i, ++ld_ptr)        {            psp_freeMemory(ld_ptr->fl_list, 0);            ld_ptr->fl_list = NULL;        }        free_table((void **) &task->set_locks, low, high, total,                sizeof(struct lock_descr), task);    }    if (dbn == ALL_DBS)        task->size_st = 0;    else    {        task->size_st -= task->db_table[dbn].Size_st;        if (task->size_st < 0)            task->size_st = 0;        if (task->set_locks)        {            i = task->db_table[dbn].st_offset;            for (ld_ptr = &task->set_locks[i]; i < task->size_st; i++, ld_ptr++)            {                fl_ptr = ld_ptr->fl_list;                for (j = 0; j < ld_ptr->fl_cnt; j++, fl_ptr++)                    *fl_ptr = (FILE_NO) ((*fl_ptr) - task->db_table[dbn].Size_ft);            }        }    }    /* All the above tables - Set_locks, Curr_mem, Curr_own, Co_time, Cm_time,        and Cs_time - are the same size as the set table. The member table is        not if there are any multi-member sets.    */    if (task->member_table)    {        if (dbn == ALL_DBS)        {            low = 0;            high = task->size_mt;            total = task->size_mt;        }        else        {            low = task->db_table[dbn].mt_offset;            high = low + task->db_table[dbn].Size_mt;            total = task->size_mt;        }        if ((total > high) && (high >= 0))        {            for (i = high; i < total; i++)            {                task->member_table[i].mt_record -= task->db_table[dbn].Size_rt;                task->member_table[i].mt_sort_fld -= task->db_table[dbn].Size_srt;            }        }        free_table((void **) &task->member_table, low, high, total,                sizeof(MEMBER_ENTRY), task);        if (dbn == ALL_DBS)            task->size_mt = 0;        else            task->size_mt -= task->db_table[dbn].Size_mt;    }    if (task->key_locks)    {        for ( fd_lc = low = high = 0, fld_ptr = task->field_table, ld_ptr = task->key_locks;                fd_lc < ((dbn == ALL_DBS) ?                    task->size_fd : task->db_table[dbn].fd_offset + task->db_table[dbn].Size_fd);                ++fd_lc, ++fld_ptr)        {            if (fld_ptr->fd_key != NOKEY)            {                if (dbn == ALL_DBS)                {                    high++;                    psp_freeMemory(ld_ptr->fl_list, 0);                    ld_ptr->fl_list = NULL;                    ld_ptr++;                }                else if (fd_lc < DB_REF(fd_offset))                {                    ld_ptr++;                    low++;                }                else                {                    psp_freeMemory(ld_ptr->fl_list, 0);                    ld_ptr->fl_list = NULL;                    ld_ptr++;                    high++;                }            }        }        high += low;        total = task->keyl_cnt;        free_table((void **) &task->key_locks, low, high, total,                sizeof(struct lock_descr), task);        if (dbn == ALL_DBS)            task->keyl_cnt = 0;        else        {            task->keyl_cnt -= (high - low);            for (ld_ptr = &task->key_locks[low], i = low; i < task->keyl_cnt; i++, ld_ptr++)            {                *(ld_ptr->fl_list) =                    (short) ((*(ld_ptr->fl_list)) - task->db_table[dbn].Size_ft);            }        }    }    if (dbn == ALL_DBS)    {        low = 0;        high = task->size_srt;        total = task->size_srt;    }    else    {        low = task->db_table[dbn].srt_offset;        high = low + task->db_table[dbn].Size_srt;        total = task->size_srt;    }    if (task->sort_table)    {        if ((total > high) && (high >= 0))        {            for (i = high; i < total; i++)            {                task->sort_table[i].se_fld -= task->db_table[dbn].Size_fd;                task->sort_table[i].se_set -= task->db_table[dbn].Size_st;            }        }        free_table((void **) &task->sort_table, low, high, total,                sizeof(SORT_ENTRY), task);        if (dbn == ALL_DBS)            task->size_srt = 0;        else            task->size_srt -= task->db_table[dbn].Size_srt;    }    if (dbn == ALL_DBS)    {        low = 0;        high = task->size_fd;        total = task->size_fd;    }    else    {        low = task->db_table[dbn].fd_offset;        high = low + task->db_table[dbn].Size_fd;        total = task->size_fd;    }    if (task->field_table)    {        if (total > high && high >= 0)        {            int key_count;            for (key_count = 0, i = low; i < high; i++)            {                if (task->field_table[i].fd_key != NOKEY)                    key_count++;            }            for (i = high; i < total; i++)            {                task->field_table[i].fd_keyfile -= task->db_table[dbn].Size_ft;                task->field_table[i].fd_rec -= task->db_table[dbn].Size_rt;                if (task->field_table[i].fd_key != NOKEY)                    task->field_table[i].fd_keyno -= (short) key_count;                if (task->field_table[i].fd_type == COMKEY)                    task->field_table[i].fd_ptr -= task->db_table[dbn].Size_kt;            }        }        free_table((void **) &task->field_table, low, high, total,                sizeof(FIELD_ENTRY), task);        if (task->field_names)        {            free_table((void **) &task->field_names, low, high, total,                    sizeof(DB_TCHAR *), task);        }        if (dbn == ALL_DBS)            task->size_fd = 0;        else            task->size_fd -= task->db_table[dbn].Size_fd;    }    if (dbn == ALL_DBS)    {        low = 0;        high = task->size_kt;        total = task->size_kt;    }    else    {        low = task->db_table[dbn].kt_offset;        high = low + task->db_table[dbn].Size_kt;        total = task->size_kt;    }    if (task->key_table)    {        if ((total > high) && (high >= 0))        {            for (i = high; i < total; i++)            {                task->key_table[i].kt_field -= task->db_table[dbn].Size_fd;                task->key_table[i].kt_key -= task->db_table[dbn].Size_fd;            }        }        free_table((void **) &task->key_table, low, high, total,                 sizeof(KEY_ENTRY), task);        if (dbn == ALL_DBS)            task->size_kt = 0;        else            task->size_kt -= task->db_table[dbn].Size_kt;    }    if (dbn == ALL_DBS)    {        low = 0;        high = task->size_rt;        total = task->size_rt;    }    else    {        low = task->db_table[dbn].rt_offset;        high = low + task->db_table[dbn].Size_rt;        total = task->size_rt;    }    if (task->record_table)    {        if ((total > high) && (high >= 0))        {            for (i = high; i < total; i++)            {                task->record_table[i].rt_file -= task->db_table[dbn].Size_ft;                task->record_table[i].rt_fields -= task->db_table[dbn].Size_fd;            }        }        free_table((void **) &task->record_table, low, high, total,                sizeof(RECORD_ENTRY), task);        if (task->record_names)        {            free_table((void **) &task->record_names, low, high, total,                    sizeof(DB_TCHAR *), task);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -