예제 #1
0
파일: dl_lists.c 프로젝트: OPENDAP/bes
int list_replace_items(pgenobj_cmp_t lri_cmp, DLL_NODE_PTR list)
{
	int error = 0;

	FF_VALIDATE(list);

	list = dll_first(list);
	while (!DLL_IS_HEAD_NODE(list))
	{
		DLL_NODE_PTR list_walker = NULL;

		list_walker = dll_next(list);

		while (!DLL_IS_HEAD_NODE(list_walker))
		{
			if ((*lri_cmp)(list->data.u.var, list_walker->data.u.var))
			{
				list = dll_previous(list);
				dll_delete(list->next);
				break;
			}

			list_walker = dll_next(list_walker);
		}

		list = dll_next(list);
	}

	return(error);
}
예제 #2
0
static BOOLEAN variable_list_comp
	(
	 VARIABLE_LIST vlist1,
	 VARIABLE_LIST vlist2
	)
{
	VARIABLE_PTR v1;
	VARIABLE_PTR v2;
	
	if (!vlist1 || !vlist2)
		return(FALSE);
	
	vlist1 = dll_first(vlist1);
	v1 = FF_VARIABLE(vlist1);
	
	vlist2 = dll_first(vlist2);
	v2 = FF_VARIABLE(vlist2);
	
	while (v1 || v2)
	{
		if (!(v1 && v2))
			return(FALSE);

		if (!variable_comp(v1, v2))
			return(FALSE);
		
		vlist1 = dll_next(vlist1);
		v1 = FF_VARIABLE(vlist1);
		
		vlist2 = dll_next(vlist2);
		v2 = FF_VARIABLE(vlist2);
	}
	
	return(TRUE);
}
예제 #3
0
static void remove_header_from_ac_list
	(
	 DATA_BIN_PTR dbin,
	 char *name
	)
{
	FF_ARRAY_CONDUIT_LIST aclist = NULL;
	FF_ARRAY_CONDUIT_PTR acptr = NULL;

	FF_VALIDATE(dbin);

	aclist = dbin->array_conduit_list;
	aclist = dll_next(aclist);
	acptr = FF_AC(aclist);
	while (acptr)
	{
		FF_VALIDATE(acptr);

		if (!strcmp(name, acptr->output->fd->format->name))
		{
			ff_destroy_array_pole(acptr->output);

			if (acptr->input)
				acptr->input->mate = NULL;

			acptr->output = NULL;

			break;
		}

		aclist = dll_next(aclist);
		acptr = FF_AC(aclist);
	}
}
예제 #4
0
파일: timer.c 프로젝트: ljvblfz/clearrtos
error_t timer_free (timer_handle_t _handle)
{
    interrupt_level_t level;

    level = global_interrupt_disable ();
    if (is_invalid_handle (_handle)) {
        global_interrupt_enable (level);
        return ERROR_T (ERROR_TIMER_FREE_INVHANDLE);
    }
    if (TIMER_STARTED == _handle->state_) {
        timer_handle_t next;
        bucket_t *p_bucket = &g_buckets [_handle->bucket_index_];

        if (g_timer_next == _handle) {
            g_timer_next = (timer_handle_t) dll_next (&g_bucket_firing->dll_,
                           &_handle->node_);
        }
        next = (timer_handle_t)dll_next (&p_bucket->dll_, &_handle->node_);
        if (0 != next) {
            next->round_ += _handle->round_;
        }
        dll_remove (&p_bucket->dll_, &_handle->node_);
        if (p_bucket->reentrance_ > 0) {
            g_bucket_firing->level_ ++;
        }
    }
    else {
        dll_remove (&g_inactive_timer, &_handle->node_);
    }
    _handle->magic_number_ = 0;
    dll_push_tail (&g_free_timer, &_handle->node_);
    global_interrupt_enable (level);

    return 0;
}
예제 #5
0
int main(int argc, char const *argv[])
{
    // creating a new list
    dll_t *list = dll_create();
    dll_registerCompareFn(list, compareFn);
    dll_registerFreeFn(list, freeFn);
    dll_registerPrintFn(list, printFn);

    // ask for the number of persons to enter
    puts("How many persons do you like to enter?");
    char input[sizeof(stdin)];
    fgets(input, sizeof(stdin), stdin);

    int x;
    sscanf(input, "%d", &x);

    // ask for person data for x times
    int i;
    for(i = 0; i < x; i++)
    {
        dll_pushTail(list, askPersonData() );
    }

    // print data
    dll_print(list);
    puts("");

    // reverse the list
    puts("reverse");
    dll_reverse(list);

    // use dll iterator functions in a for loop to print the reversed list
    for(dll_head(list); dll_hasNext(list); dll_next(list))
    {
        printFn(list->curr->data);
    }


    puts("sort");
    dll_sort(list);

    // use dll iterator functions in a while loop to print the sorted list
    dll_head(list);
    while(dll_hasNext(list))
    {
        printFn(list->curr->data);
        dll_next(list);
    }

    printf("List size: %ld\n", dll_size(list));

    // empty the whole list
    dll_clear(list);


    return 0;
}
예제 #6
0
파일: timer.c 프로젝트: ljvblfz/clearrtos
error_t timer_stop (timer_handle_t _handle, msecond_t *_p_remained)
{
    interrupt_level_t level;
    timer_handle_t next;
    bucket_t *p_bucket;

    level = global_interrupt_disable ();
    if (is_invalid_handle (_handle)) {
        global_interrupt_enable (level);
        return ERROR_T (ERROR_TIMER_STOP_INVHANDLE);
    }
    if (_handle->state_ != TIMER_STARTED) {
        g_statistics.abnormal_ ++;
        global_interrupt_enable (level);
        return ERROR_T (ERROR_TIMER_STOP_INVSTATE);
    }

    if (g_timer_next == _handle) {
        g_timer_next = (timer_handle_t) dll_next (&g_bucket_firing->dll_,
                       &_handle->node_);
    }
    p_bucket = &g_buckets [_handle->bucket_index_];
    if (_p_remained != null) {
        timer_remained_t remained = {_handle, 0};

        (void) dll_traverse (&p_bucket->dll_, timer_calculate_remained, &remained);
        *_p_remained = remained.remained_round_ * CONFIG_MAX_BUCKET;
        if (g_cursor > _handle->bucket_index_) {
            *_p_remained = (*_p_remained) * CONFIG_MAX_BUCKET -
                           (g_cursor - _handle->bucket_index_);
        }
        else {
            *_p_remained = (*_p_remained - 1) * CONFIG_MAX_BUCKET +
                           (g_cursor - _handle->bucket_index_) + 1;
        }
        *_p_remained *= CONFIG_TICK_DURATION_IN_MSEC;
    }
    _handle->state_ = TIMER_STOPPED;
    next = (timer_handle_t)dll_next (&p_bucket->dll_, &_handle->node_);
    if (0 != next) {
        next->round_ += _handle->round_;
    }
    dll_remove (&p_bucket->dll_, &_handle->node_);
    dll_push_tail (&g_inactive_timer, &_handle->node_);
    if (p_bucket->reentrance_ > 0) {
        p_bucket->level_ ++;
    }
    global_interrupt_enable (level);

    return 0;
}
예제 #7
0
파일: wdbBpLib.c 프로젝트: hermixy/vxworks5
static UINT32 wdbBpDelete
    (
    TGT_ADDR_T *	pId
    )
    {
    dll_t *	pDll;
    dll_t *	pNextDll;
    BRKPT *	pBp;

    pBp = *(BRKPT **) pId;

    /* 
     * Breakpoint ID of -1 means remove all breakpoints. 
     * We can only remove breakpoints set by the host tools. Breakpoints
     * set from target shell can't be removed
     */

    wdbTaskLock ();	/* disable task switching */
    if ((int ) pBp == -1)
	{
	for (pDll = dll_head(&bpList);
	     pDll != dll_end(&bpList);
	     pDll = pNextDll)
	    {
	    pNextDll = dll_next(pDll);

	    if (BP_BASE(pDll)->bp_flags & BP_HOST)
		wdbDbgBpRemove (BP_BASE(pDll));
	    }

	wdbTaskUnlock ();		/* re-enable task switching */
	return (WDB_OK);
	}

    /* else just remove one breakpoint */

    for (pDll = dll_head(&bpList); pDll != dll_end(&bpList);
	    pDll = dll_next(pDll))
	{
	if (BP_BASE(pDll) == pBp)
	    {
	    wdbDbgBpRemove (pBp);
	    wdbTaskUnlock ();	/* re-enable task switching */
	    return (WDB_OK);
	    }
	}
    wdbTaskUnlock ();	/* re-enable task switching */

    return (WDB_ERR_INVALID_EVENTPOINT);
    }
예제 #8
0
static void release_file_handles
	(
	 DATA_BIN_PTR dbin,
	 FF_TYPES_t io
	)
{
	PROCESS_INFO_LIST plist = NULL;
	PROCESS_INFO_PTR pinfo = NULL;

	FF_VALIDATE(dbin);

	if (!db_ask(dbin, DBASK_PROCESS_INFO, io, &plist))
	{
		plist = dll_first(plist);
		pinfo = FF_PI(plist);
		while (pinfo)
		{
			if (PINFO_SUPER_ARRAY(pinfo)->fp)
				fclose(PINFO_SUPER_ARRAY(pinfo)->fp);
			else if (PINFO_SUB_ARRAY(pinfo)->fp)
				fclose(PINFO_SUB_ARRAY(pinfo)->fp);

			plist = dll_next(plist);
			pinfo = FF_PI(plist);
		}

		ff_destroy_process_info_list(plist);
	}
}
예제 #9
0
struct DLLHASHTABLE_HASHTABLEVALUE* dllhashtable_next(
	struct DLLHASHTABLE* dllhashtable_ptr,
	struct DLLHASHTABLE_HASHTABLEVALUE* hashtablevalue_ptr)
{
	struct DLL* dll_ptr;
	struct DLLHASHTABLE_DLLITEM* dllitem_ptr;
	struct DLLHASHTABLE_DLLITEM* dllitem_next_ptr;
	struct DLLHASHTABLE_HASHTABLEVALUE* hashtablevalue_next_ptr;
	struct HASHITEM* hashitem_ptr;
	
	dll_ptr = dllhashtable_ptr->dll_ptr;
	if (hashtablevalue_ptr == NULL){
		dllitem_ptr = (struct DLLHASHTABLE_DLLITEM*)dll_ptr->head;
	}
	else {
		dllitem_ptr = hashtablevalue_ptr->dllitem_ptr;
	}

	dllitem_next_ptr = (struct DLLHASHTABLE_DLLITEM*)
		dll_next(dll_ptr, (struct DLLITEM*)dllitem_ptr);

	if (dllitem_next_ptr == NULL){
		/* no more item in dll */
		hashtablevalue_next_ptr = NULL;
	}
	else {
		hashitem_ptr = dllitem_next_ptr->hashitem_ptr;
		hashtablevalue_next_ptr = hashitem_ptr->value;
	}

	return hashtablevalue_next_ptr;
}
예제 #10
0
파일: wdbLib.c 프로젝트: andy345/vxworks5
void wdbResumeSystem (void)
    {
    dll_t *		pThisNode;
    WDB_REG_SET_OBJ *	pRegSet;

    wdbState &= (~WDB_STATE_EXTERN_RUNNING);	/* mark extern agent done */

    /* 
     * Set driver in interrupt mode only if task mode is supported by the
     * agent. Otherwise, it is not usefull.
     */

    if (wdbRunsTasking ())
	{
	(*pWdbExternCommIf->modeSet)		/* reset communication stack */
                (pWdbExternCommIf->commId,
		    WDB_COMM_MODE_INT);
	}

    wdbOneShot = FALSE;				/* ... */
    wdbExternExitHook();			/* call extern exit hook */

    /* restore inferior context */

    for (pThisNode  = dll_head (&wdbRegSetList);
         pThisNode != dll_end  (&wdbRegSetList);
         pThisNode  = dll_next (pThisNode))
        {
        pRegSet = (WDB_REG_SET_OBJ *)pThisNode;
	(*pRegSet->load)();
	}
    WDB_CTX_LOAD (&wdbExternSystemRegs);

    /*NOTREACHED*/
    }
예제 #11
0
파일: wdbLib.c 프로젝트: andy345/vxworks5
STATUS wdbExternRegsGet
    (
    WDB_REG_SET_TYPE	type,
    char **		ppRegs
    )
    {
    dll_t *		pThisNode;
    WDB_REG_SET_OBJ *	pRegSet;

    if (type == WDB_REG_SET_IU)
	{
	*ppRegs = (char *)&wdbExternSystemRegs;
	return (OK);
	}

    for (pThisNode  = dll_head (&wdbRegSetList);
	 pThisNode != dll_end  (&wdbRegSetList);
	 pThisNode  = dll_next (pThisNode))
	{
	pRegSet = (WDB_REG_SET_OBJ *)pThisNode;
	if (pRegSet->regSetType == type)
	    {
	    (*pRegSet->get) (ppRegs);
	    return (OK);
	    }
	}

    return (ERROR);
    }
예제 #12
0
파일: timer.c 프로젝트: ljvblfz/clearrtos
static void timer_insert (timer_handle_t _handle)
{
    interrupt_level_t interrupt_level;
    bucket_t *p_bucket;
    usize_t count = 0, round, level;
    timer_handle_t iterator;

    interrupt_level = global_interrupt_disable ();
    _handle->bucket_index_ = (g_cursor + _handle->ticks_) % CONFIG_MAX_BUCKET;
    dll_remove (&g_inactive_timer, &_handle->node_);

    p_bucket = &g_buckets [_handle->bucket_index_];
    round = _handle->ticks_ / CONFIG_MAX_BUCKET;
    level = ++ p_bucket->level_;
    p_bucket->reentrance_ ++;

redo:
    iterator = (timer_handle_t) dll_head (&p_bucket->dll_);
    _handle->round_ = round;
    for (;;) {
        if (0 == iterator) {
            dll_push_tail (&p_bucket->dll_, &_handle->node_);
            break;
        }
        if (_handle->round_ <= iterator->round_) {
            iterator->round_ -= _handle->round_;
            dll_insert_before (&p_bucket->dll_, &iterator->node_, &_handle->node_);
            break;
        }
        _handle->round_ -= iterator->round_;
        iterator = (timer_handle_t) dll_next (&p_bucket->dll_, &iterator->node_);

        count ++;
        if (count < CONFIG_INTERRUPT_FLASH_FREQUENCY) {
            continue;
        }

        count = 0;
        global_interrupt_enable (interrupt_level);
        // at this moment we give a chance to the higher pirority interrupt
        // (or task) for being served (or running)
        interrupt_level = global_interrupt_disable ();
        if (p_bucket->level_ != level) {
            level = ++ p_bucket->level_;
            p_bucket->redo_ ++;
            goto redo;
        }
    }
    if (g_bucket_firing == p_bucket) {
        if(0 == g_timer_next || _handle->round_ <= g_timer_next->round_) {
            g_timer_next = _handle;
        }
    }
    p_bucket->hit_ ++;
    if (0 == -- p_bucket->reentrance_) {
        p_bucket->level_ = 0;
    }
    _handle->state_ = TIMER_STARTED;
    global_interrupt_enable (interrupt_level);
}
예제 #13
0
파일: dl_lists.c 프로젝트: OPENDAP/bes
void dll_rewind
	(
	 DLL_NODE_HANDLE head_h
	)
{
	while (!DLL_IS_HEAD_NODE(*head_h))
		*head_h = dll_next(*head_h);
}
예제 #14
0
파일: dllists.c 프로젝트: sdrsdr/sdrclib
void dll_deinit_list (dll_listh_t *list, int freeblocks) {
    if (!list) return;
    if (freeblocks) {
        dll_list_iterator_t li;
        dll_iterate_fwd(list,&li);
        dll_blockh_t *bl;
        while (NULL!=(bl=dll_next(&li))) dll_deinit_block (bl,0);
    }
    if (list->dll_list_user_data && (list->dll_list_mem_flags & DLL_LIST_MEM_FLAG_FREE_USER_DATA) == DLL_LIST_MEM_FLAG_FREE_USER_DATA ) free (list->dll_list_user_data);
    if ((list->dll_list_mem_flags & DLL_LIST_MEM_FLAG_FREE_HEAD) == DLL_LIST_MEM_FLAG_FREE_HEAD ) free (list);
}
예제 #15
0
파일: wdbBpLib.c 프로젝트: hermixy/vxworks5
void wdbBpInstall (void)
    {
    dll_t *	pDll;
#if	DBG_HARDWARE_BP
    DBG_REGS	dbgRegs;
#endif	/* DBG_HARDWARE_BP */

    /* don't install system BP's if we are not in system mode */

    if (wdbIsNowTasking())
	return;

#if	DBG_HARDWARE_BP
    memset (&dbgRegs, 0, sizeof (DBG_REGS));
    wdbDbgRegsClear ();		/* clean debug registers */
#endif	/* DBG_HARDWARE_BP */

    /* if stepping, just set trace mode */

    if (wdbSysBpMode != 0)
	{
#if	DBG_NO_SINGLE_STEP
	wdbSysNpc = wdbDbgGetNpc (&wdbExternSystemRegs);
	wdbSysNpcInstr = *wdbSysNpc;
	usrBreakpointSet (wdbSysNpc, DBG_BREAK_INST);
#endif	/* DBG_NO_SINGLE_STEP */
	wdbBpData = wdbDbgTraceModeSet ((REG_SET *) &wdbExternSystemRegs);
	}
    else	/* if not stepping, insert breakpoints */
	{
	for (pDll = dll_head(&bpList); pDll != dll_end(&bpList);
		pDll = dll_next(pDll))
	    {
	    if (BP_BASE(pDll)->bp_task ==  -1)
		{
		if ((BP_BASE(pDll)->bp_flags & BRK_HARDWARE) == 0)
		    usrBreakpointSet (BP_BASE(pDll)->bp_addr, DBG_BREAK_INST);
#if	DBG_HARDWARE_BP
		else
		    wdbDbgHwBpSet (&dbgRegs, 
				   BP_BASE(pDll)->bp_flags & BRK_HARDMASK, 
				   (UINT32) BP_BASE(pDll)->bp_addr);
#endif	/* DBG_HARDWARE_BP */
		BP_BASE(pDll)->bp_flags |= BP_INSTALLED;
		}
	    }

#if	DBG_HARDWARE_BP
	wdbDbgRegsSet (&dbgRegs);	/* set debug registers. */
#endif	/* DBG_HARDWARE_BP */
	}
    }
예제 #16
0
파일: timer.c 프로젝트: ljvblfz/clearrtos
void timer_fire ()
{
    interrupt_level_t level;
    timer_handle_t handle;

    level = global_interrupt_disable ();
    g_bucket_firing = &g_buckets [g_cursor];
    if (0 == dll_size (&g_bucket_firing->dll_)) {
        // no timer is expired
        goto out;
    }

    handle  = (timer_handle_t) dll_head (&g_bucket_firing->dll_);
    while (0 != handle) {
        g_statistics.traversed_ ++;
        g_timer_next = (timer_handle_t) dll_next (&g_bucket_firing->dll_,
                       &handle->node_);
        if (handle->round_ > 0) {
            // in this case the timer is still not expired
            handle->round_ --;
            break;
        }
        else {
            // hooray, the timer is expired
            dll_remove (&g_bucket_firing->dll_, &handle->node_);
            dll_push_tail (&g_inactive_timer, &handle->node_);
            handle->state_ = TIMER_STOPPED;
            if (g_bucket_firing->reentrance_ > 0) {
                g_bucket_firing->level_ ++;
            }
            global_interrupt_enable (level);
            if (TIMER_TYPE_INTERRUPT == handle->type_) {
                handle->callback_(handle, handle->arg_);
            }
            else if (TIMER_TYPE_TASK == handle->type_) {
                timer_message_send (handle);
            }
            level = global_interrupt_disable ();
        }
        handle = g_timer_next;
    }

out:
    g_cursor ++;
    if (g_cursor > BUCKET_LAST_INDEX) {
        g_cursor = 0;
    }
    g_timer_next = 0;
    g_bucket_firing = 0;
    global_interrupt_enable (level);;
}
예제 #17
0
static int make_unique_format_titles(DATA_BIN_PTR dbin)
{
	PROCESS_INFO_LIST plist = NULL;
	PROCESS_INFO_PTR pinfo = NULL;

	int error = 0;
	int SCRATCH = strlen("Binary Output Separate Varied Record Header: ") + 1; /* Longest */

	char *cp = NULL;

	FF_VALIDATE(dbin);

	db_ask(dbin, DBASK_PROCESS_INFO, 0, &plist);

	plist = dll_first(plist);
	pinfo = FF_PI(plist);
	while (pinfo && !error)
	{
		FF_VALIDATE(pinfo);

		cp = (char *)memRealloc(PINFO_FORMAT(pinfo)->name, strlen(PINFO_FORMAT(pinfo)->name) + SCRATCH + 1, "PINFO_FORMAT(pinfo)->name");
		if (cp)
		{
			PINFO_FORMAT(pinfo)->name = cp;
			memmove(cp + SCRATCH, cp, strlen(cp) + 1);
		}
		else
		{
			error = err_push(ERR_MEM_LACK, "");
			break;
		}

		error = get_format_type(PINFO_FORMAT(pinfo), cp);
		if (error)
			break;

		memmove(cp + strlen(cp), cp + SCRATCH, strlen(cp + SCRATCH) + 1);

		plist = dll_next(plist);
		pinfo = FF_PI(plist);
	}

	ff_destroy_process_info_list(plist);

	return error;
}
예제 #18
0
파일: mrEd.c 프로젝트: isGregory/Classes
// Function to get the data of the cursor of a specified DlList_T
// Since there's no function to get the data of the cursor
void* getCursorData( DlList_T lst ) {

    // Get the data of the current location
    void* data = dll_next( lst );

    // If there is currently a cursor
    if( data != NULL ) {

        // Grab the index of that data
         int index = dll_index( lst, data );

        // Set the cursor back to that point
        dll_move_to( lst, index );
    }

    return data;
}
예제 #19
0
파일: mrEd.c 프로젝트: isGregory/Classes
// Function to get the index of the cursor of a specified DlList_T
// Since there's no function to get the index of the cursor
int getCursorIndex( DlList_T lst ) {

    // Get the data of the current location
    void* data = dll_next( lst );

    // There is no cursor currently
    if( data == NULL ) {
        return 0;
    }

    // Grab the index of that data
    int index = dll_index( lst, data );

    // Set the cursor back to that point
    dll_move_to( lst, index );

    return index;
}
예제 #20
0
int PullCache(INT h, int hash, int *width, int *height, int *format, unsigned char ** data)
{
	LPCACHE_NODE pNode;
	LPCACHE_HANDLE handle = (LPCACHE_HANDLE)h;
	int ret = 0;
	if (handle == GNull) {
		return PARAM_INVALID;
	}

	// search in rb-tree
	pNode = rbt_search(&handle->mRBRoot, hash);

	if (pNode != GNull) {
		//remove out.
		dl_remove_node(&(pNode->mDLNode), &(handle->mDLRoot));

		//add node
		dl_insert_node(&(pNode->mDLNode), GNull, &(handle->mDLRoot));

		cache_data_parse(&(pNode->mData), width, height, format, data);

	} else {
		//not found.
#if defined( _DEBUG )
		LPRB_NODE node;
		LPDLL_NODE link;
		LPCACHE_NODE data;
		LOGI("not found %ld\n", hash);
		for (node = rb_first(&(handle->mRBRoot)); node != GNull; node = rb_next(node)) {
			container_of(data, node, CACHE_NODE, mRBNode);
			LOGI("%ld\n", data->mKey);
		}
		LOGI("double link list:\n");
		for (link = dll_first(&(handle->mDLLRoot)); link != GNull; link = dll_next(link)) {
			container_of(data, link, CACHE_NODE, mDLLNode);
			LOGI("%ld\n", data->mKey);
		}

#endif
		return -1;
	}

	return ret;
}
예제 #21
0
void wdbExcGetEvent
    (
    void *	arg,
    WDB_EVT_DATA *	pEvtData
    )
    {
    wdbExcInfoNode_t *	pNode;
    wdbExcInfoNode_t *	pTmpNode;
    WDB_EXC_INFO *	pExcInfo;

    int lockKey;

    /* get a node from the exception queue */

    lockKey = intLock();
    pNode   = (wdbExcInfoNode_t *) dll_head (&wdbExcEvtList);
    dll_remove (&pNode->node);
    intUnlock (lockKey);

    /* give the node info to the host */

    pExcInfo = (WDB_EXC_INFO *)&pEvtData->eventInfo;
    pEvtData->evtType		= WDB_EVT_EXC;
    pExcInfo->numInts		= 4;
    pExcInfo->context		= pNode->context;
    pExcInfo->vec		= pNode->excVector;
    pExcInfo->pEsf		= (TGT_ADDR_T) pNode->pESF;

    /* mark the node invalid and put back in queue (after valid nodes) */

    pNode->valid = FALSE;
    lockKey = intLock();
    for (pTmpNode =  (wdbExcInfoNode_t *) dll_head (&wdbExcEvtList);
	 pTmpNode != (wdbExcInfoNode_t *) dll_end  (&wdbExcEvtList);
	 pTmpNode =  (wdbExcInfoNode_t *) dll_next (&pTmpNode->node))
	{
	if (pTmpNode->valid == FALSE)
	    break;
	}
    pTmpNode = (wdbExcInfoNode_t *) dll_prev (&pTmpNode->node);
    dll_insert (&pNode->node, &pTmpNode->node);
    intUnlock (lockKey);
    }
예제 #22
0
파일: dl_lists.c 프로젝트: OPENDAP/bes
static void dll_disconnect_node(DLL_NODE_PTR node)
{
	FF_VALIDATE(node);

#ifdef DLL_CHK
	assert(!DLL_IS_HEAD_NODE(node));
	assert(!DLL_IS_FREED(node));
	
	DLL_MARK_FREED(node);
	DLL_COUNT(find_head_node(node))--;
#endif

	node->previous->next = dll_next(node);     /* set next_node of prev_node */
	node->next->previous = dll_previous(node);     /* Set prev_node of next_node */

	node->previous = node->next = NULL;

#ifdef FF_CHK_ADDR
	node->check_address = NULL;
#endif
}
예제 #23
0
파일: wdbLib.c 프로젝트: andy345/vxworks5
void wdbSuspendSystem
    (
    WDB_IU_REGS * pRegs,			/* runtime context to save */
    void	  (*callBack)(),		/* callback after system is stopped */
    int		  arg			/* callback argument */
    )
    {
    dll_t *		pThisNode;
    WDB_REG_SET_OBJ *	pRegSet;

    intLock();

    wdbSuspendCallbackRtn = callBack;		/* install the callback */
    wdbSuspendCallbackArg = arg;		/* and the callback argument */
    wdbState |= WDB_STATE_EXTERN_RUNNING;	/* mark extern agent running */
    wdbExternEnterHook();			/* call extern enter hook */
    (*pWdbExternCommIf->modeSet)		/* reset communication stack */
		(pWdbExternCommIf->commId,
		WDB_COMM_MODE_POLL);
    bcopy ((caddr_t)pRegs,			/* save inferior context */
	   (caddr_t)&wdbExternSystemRegs,
	   sizeof (WDB_IU_REGS));
    for (pThisNode  = dll_head (&wdbRegSetList);
         pThisNode != dll_end  (&wdbRegSetList);
         pThisNode  = dll_next (pThisNode))
        {
        pRegSet = (WDB_REG_SET_OBJ *)pThisNode;
	(*pRegSet->save)();
	}

#if	CPU_FAMILY==MC680X0
    wdbExternAgentRegs.regSet.sr &= 0xefff;
    wdbExternAgentRegs.regSet.sr |= (wdbExternSystemRegs.regSet.sr & 0x1000);
#endif

    WDB_CTX_LOAD (&wdbExternAgentRegs); /* run external agent */

    /*NOTREACHED*/
    }
예제 #24
0
STATUS wdbVioChannelRegister
    (
    WDB_VIO_NODE *	pVioNode
    )
    {
    WDB_VIO_NODE *	pThisNode;
    int lockKey;

    for (pThisNode =  (WDB_VIO_NODE *)dll_head (&wdbVioDevList);
	 pThisNode != (WDB_VIO_NODE *)dll_end  (&wdbVioDevList);
	 pThisNode =  (WDB_VIO_NODE *)dll_next (&pThisNode->node)
	)
	{
	if (pThisNode->channel == pVioNode->channel)
	    return (ERROR);
	}

    lockKey = intLock();
    dll_insert (&pVioNode->node, &wdbVioDevList);
    intUnlock (lockKey);

    return (OK);
    }
예제 #25
0
static UINT32 wdbVioWrite
    (
    WDB_MEM_XFER *	pMemXfer,
    UINT32 *		pBytesWritten
    )
    {
    WDB_VIO_NODE *	pThisNode;

    for (pThisNode =  (WDB_VIO_NODE *)dll_head (&wdbVioDevList);
	 pThisNode != (WDB_VIO_NODE *)dll_end  (&wdbVioDevList);
	 pThisNode =  (WDB_VIO_NODE *)dll_next (&pThisNode->node)
	)
	{
	if (pThisNode->channel == (UINT32)pMemXfer->destination)
	    {
	    *pBytesWritten = (*pThisNode->inputRtn)(pThisNode,
				    pMemXfer->source,
				    pMemXfer->numBytes);
	    return (OK);
	    }
	}

    return (WDB_ERR_INVALID_VIO_CHANNEL);
    }
예제 #26
0
void *elevator(void *arg){
    Elevator *e = (Elevator *) arg; 
    Dllist item, next, pickup;
    Person *p;
    int direction = 1;
    pickup = new_dllist();

    while(1){

        if(e -> onfloor >= top) direction = -1;
        else if(e -> onfloor <= 1) direction = 1;
        //printf("\tElevator[%i] on floor %i going %s:\n",
        //        e -> id, e -> onfloor, direction == 1 ? "up": "down"); 

        /* pick people up */
        pthread_mutex_lock(lock);

        item = dll_first(people);
        while(!dll_empty(people) && item != dll_nil(people)){
            next = dll_next(item);
            p = (Person *) item -> val.v;

            //printf("\t\tShould I get %s %s going from %i to %i? ",
            //        p -> fname, p -> lname, p -> from, p -> to);

            if(e -> onfloor == p -> from){
                if(p -> to > e -> onfloor && direction == 1 || 
                   p -> to < e -> onfloor && direction == -1){
                    dll_append(pickup, item -> val);
                    dll_delete_node(item);
                    //printf("yes!\n");

                }
                //else printf("no!\n");
            }
            //else printf("no!\n");

            item = next;
        }

        pthread_mutex_unlock(lock);

        item = dll_first(pickup);
        while(!dll_empty(pickup) && item != dll_nil(pickup)){
            next = dll_next(item);
            p = (Person *) item -> val.v;

            if(!e -> door_open) open_door(e);
            pthread_mutex_lock(p -> lock);

            p -> e = e;

            pthread_cond_signal(p -> cond);
            pthread_mutex_lock(e -> lock);
            pthread_mutex_unlock(p -> lock);

            pthread_cond_wait(e -> cond, e -> lock);
            pthread_mutex_unlock(e -> lock);

            dll_delete_node(item);
            item = next;
        }
        if(e -> door_open) close_door(e);

        move_to_floor(e, e -> onfloor + direction);

        /* drop people off */
        item = dll_first(e -> people);
        while(!dll_empty(e -> people) && item != dll_nil(e -> people)){
            next = dll_next(item);
            p = (Person *) item -> val.v;

            if(p -> to == e -> onfloor){
               if(!e -> door_open) open_door(e);
                
               pthread_mutex_lock(p -> lock);
               pthread_cond_signal(p -> cond);
               pthread_mutex_lock(e -> lock);
               pthread_mutex_unlock(p -> lock);

               pthread_cond_wait(e -> cond, e -> lock);
               pthread_mutex_unlock(e -> lock);
            }

            item = next;
        }
        //if(e -> door_open) close_door(e);

    }

    return NULL;
}
예제 #27
0
int main()
{
    chk_msg("dll_init");
    dll_t list;
    dll_init(&list);
    chk_dll_size(&list, 0);

    chk_msg("dll_push_back");
    dll_push_back(&list);
    chk_dll_size(&list, 1);

    chk_msg("dll_push_front");
    dll_push_front(&list);
    chk_dll_size(&list, 2);

    chk_msg("dll_destroy");
    dll_destroy(&list);
    chk_dll_size(&list, 0);

    chk_msg("dll_push_front");
    dll_push_front(&list);
    chk_dll_size(&list, 1);

    chk_msg("dll_pop_back");
    dll_pop_back(&list);
    chk_dll_size(&list, 0);

    chk_msg("dll_destroy");
    dll_destroy(&list);
    chk_dll_size(&list, 0);

    chk_msg("dll_destroy");
    dll_destroy(&list);
    chk_dll_size(&list, 0);

    chk_msg("dll_push_back");
    dll_item_t *item = dll_push_back(&list);
    chk_dll_size(&list, 1);

    chk_msg("dll_insert_before");
    item = dll_insert_before(&list, item);
    chk_dll_size(&list, 2);

    chk_msg("dll_insert_after");
    item = dll_insert_after(&list, item);
    chk_dll_size(&list, 3);

#if TRIGGER_INV_BUG
    chk_msg("dll_remove");
    dll_remove(&list, dll_next(dll_prev(dll_prev(dll_end(&list)))));
    chk_dll_size(&list, 2);
#endif

    chk_msg("dll_pop_front");
    dll_pop_front(&list);
    chk_dll_size(&list, 1);

#if TRIGGER_INV_BUG
    chk_msg("dll_remove");
    dll_remove(&list, dll_beg(&list));
    chk_dll_size(&list, 0);
#endif

    ___sl_plot(NULL);

    return 0;
}
예제 #28
0
static int check_file_access(DATA_BIN_PTR dbin)
{
	PROCESS_INFO_LIST plist = NULL;
	PROCESS_INFO_PTR pinfo = NULL;

	int error = 0;

	error = db_ask(dbin, DBASK_PROCESS_INFO, FFF_OUTPUT, &plist);
	if (!error)
	{
		BOOLEAN no_overwrite = FALSE;

		if (nt_askexist(dbin, NT_ANYWHERE, "nooverwrite"))
			no_overwrite = TRUE;

		plist = dll_first(plist);
		pinfo = FF_PI(plist);
		while (pinfo)
		{
			if (PINFO_IS_FILE(pinfo))
			{
				if (os_file_exist(PINFO_FNAME(pinfo)))
				{
					if (PINFO_MATE(pinfo) && PINFO_MATE_IS_FILE(pinfo) && !strcmp(PINFO_FNAME(pinfo), PINFO_MATE_FNAME(pinfo)))
						error = err_push(ERR_GENERAL, "Input and output %s files have the same name!", IS_DATA(PINFO_FORMAT(pinfo)) ? "data" : "header");
					else if (!PINFO_IS_BROKEN(pinfo))
					{
						if (no_overwrite)
							error = err_push(ERR_FILE_EXISTS, PINFO_FNAME(pinfo));
						else
						{
							if (IS_SEPARATE(PINFO_FORMAT(pinfo)) && IS_FILE_HEADER(PINFO_FORMAT(pinfo)))
							{
								/* Is this a zero length file?  If so, go ahead and overwrite it. */
								if (os_filelength(PINFO_FNAME(pinfo)))
								{
									err_push(ERR_WARNING_ONLY + ERR_FILE_EXISTS, "Output header (%s) will not be overwritten", PINFO_FNAME(pinfo));

									remove_header_from_ac_list(dbin, PINFO_FORMAT(pinfo)->name);
								}
							}
							else
								err_push(ERR_WARNING_ONLY + ERR_WILL_OVERWRITE_FILE, "%s: \"%s\"", PINFO_FNAME(pinfo), PINFO_NAME(pinfo));
						}
					}
				}
			}

			plist = dll_next(plist);
			pinfo = FF_PI(plist);
		}

		ff_destroy_process_info_list(plist);
		error = db_ask(dbin, DBASK_PROCESS_INFO, FFF_OUTPUT, &plist);
		if (!error)
		{
			plist = dll_first(plist);
			pinfo = FF_PI(plist);
			while (pinfo)
			{
				if (PINFO_IS_FILE(pinfo) && !PINFO_IS_BROKEN(pinfo))
				{
					 /* Can we write to file? */
					if ((!error || error > ERR_WARNING_ONLY) && (!no_overwrite || !os_file_exist(PINFO_FNAME(pinfo))))
					{
#ifdef ND_FP 
						PINFO_SUB_ARRAY(pinfo)->fp = fopen(PINFO_FNAME(pinfo), "w");
						if (PINFO_SUB_ARRAY(pinfo)->fp)
						{
							fclose(PINFO_SUB_ARRAY(pinfo)->fp);

							PINFO_SUB_ARRAY(pinfo)->fp = fopen(PINFO_FNAME(pinfo), "w+b");
							if (!PINFO_SUB_ARRAY(pinfo)->fp)
							{
								release_file_handles(dbin, FFF_OUTPUT);
								break;
							}
						}
#else
						FILE *fp = NULL;

						fp = fopen(PINFO_FNAME(pinfo), "w");
						if (fp)
							fclose(fp);
#endif
						else
							error = err_push(ERR_CREATE_FILE, "%s: \"%s\"", PINFO_FNAME(pinfo), PINFO_NAME(pinfo));
					}
				}

				plist = dll_next(plist);
				pinfo = FF_PI(plist);
			}

			ff_destroy_process_info_list(plist);
		}
		else if (error == ERR_GENERAL)
			error = 0;
	}
	else if (error == ERR_GENERAL)
		error = 0;

#ifdef ND_FP 
	if (!error)
	{
		error = db_ask(dbin, DBASK_PROCESS_INFO, FFF_INPUT, &plist);
		if (!error)
		{
			plist = dll_first(plist);
			pinfo = FF_PI(plist);
			while (pinfo)
			{
				if (PINFO_IS_FILE(pinfo) && !PINFO_IS_BROKEN(pinfo))
				{
					PINFO_SUPER_ARRAY(pinfo)->fp = fopen(PINFO_FNAME(pinfo), "rb");
					if (!PINFO_SUPER_ARRAY(pinfo)->fp)
					{
						release_file_handles(dbin, FFF_INPUT);
						release_file_handles(dbin, FFF_OUTPUT);
						break;
					}
				}

				plist = dll_next(plist);
				pinfo = FF_PI(plist);
			}
		}

		ff_destroy_process_info_list(plist);
	}
#endif

	return(error);
}
예제 #29
0
파일: wdbBpLib.c 프로젝트: hermixy/vxworks5
static UINT32 wdbHwBpAdd
    (
    WDB_EVTPT_ADD_DESC *	pBreakPoint,	/* breakpoint to add */
    UINT32 *			pId		/* breakpoint ID */
    )
    {
    BRKPT *	pBp;
    dll_t *	pDll;
    int		status;
    DBG_REGS	dbgRegs;		/* debug registers */
    int		contextId;		/* context ID */
    UINT32	addr;			/* breakpoint address */
    UINT32	count = 0;		/* breakpoint count */
    int		type = DEFAULT_HW_BP;	/* hardware type */

    switch (pBreakPoint->numArgs)
	{
	default:
	case 3:
	    type = pBreakPoint->args[2];
	    /* FALL THROUGH */
	case 2:
	    count = pBreakPoint->args[1];
	    /* FALL THROUGH */
	case 1:
	    addr = pBreakPoint->args[0];
	    break;
	case 0:
	    return (WDB_ERR_INVALID_PARAMS);
	}

    /* check validity of hardware breakpoint address */

    if (wdbDbgHwAddrCheck (addr, type, (FUNCPTR) pWdbRtIf->memProbe) != OK)
        return (WDB_ERR_MEM_ACCES);

    /* check the agent mode */

    switch (pBreakPoint->context.contextType)
	{
	case WDB_CTX_SYSTEM:
	    if (!wdbIsNowExternal())
		return (WDB_ERR_AGENT_MODE);
	    break;

	default:
	    if (!wdbIsNowTasking())
		return (WDB_ERR_AGENT_MODE);
	}

    /* set the context ID */

    switch (pBreakPoint->context.contextType)
        {
        case WDB_CTX_SYSTEM:
            contextId = BP_SYS;
            break;
        case WDB_CTX_ANY_TASK:
            contextId = BP_ANY_TASK;
            break;
        case WDB_CTX_TASK:
        default:
            contextId = pBreakPoint->context.contextId;
        }

    /* clean dbgRegs structure */

    memset (&dbgRegs, 0, sizeof (DBG_REGS));

    /* fill dbgRegs structure with all hardware breakpoints */

    wdbTaskLock ();	/* disable task switching */
    for (pDll = dll_head(&bpList); pDll != dll_end(&bpList);
		pDll = dll_next(pDll))
	{
	pBp = BP_BASE(pDll);

	/* check if found breakpoint is applicable to new breakpoint context */

	if (((contextId == BP_SYS) && (pBp->bp_task == BP_SYS)) ||
		((contextId == BP_ANY_TASK) && (pBp->bp_task != BP_SYS)) ||
		((contextId != BP_SYS) && (pBp->bp_task == BP_ANY_TASK)))
	    {
	    if (pBp->bp_flags & BRK_HARDWARE)
		{
		if ((status = wdbDbgHwBpSet (&dbgRegs, 
				pBp->bp_flags & BRK_HARDMASK, 
				(UINT32) pBp->bp_addr)) != OK)
		    {
		    wdbTaskUnlock ();	/* re-enable task switching */
		    return (status);
		    }
		}
	    }
	}
    wdbTaskUnlock ();	/* re-enable task switching */

    if ((status = wdbDbgHwBpSet (&dbgRegs, type, addr)) != OK)
	return (status);

    if (dll_empty (&bpFreeList))
	return (WDB_ERR_EVENTPOINT_TABLE_FULL);

    wdbTaskLock ();		/* disable task switching */
    pBp = BP_BASE(dll_tail (&bpFreeList));
    dll_remove (&pBp->bp_chain);
    wdbTaskUnlock ();	/* re-enable task switching */

    pBp->bp_flags = BP_HOST | type | BRK_HARDWARE;
    pBp->bp_addr = (INSTR *)addr;
    pBp->bp_action = pBreakPoint->action.actionType;
    pBp->bp_count = count;
    pBp->bp_callRtn = (void (*)())pBreakPoint->action.callRtn;
    pBp->bp_callArg = pBreakPoint->action.callArg;
    pBp->bp_task = contextId;

    /* 
     * XXX - MS hack because host tools pass wrong info.
     * XXX - DBT This has been corrected in tornado 2.0 host tools but we
     * must keep this hack for backward compatibility.
     */

    if ((pBp->bp_action == 0) || (pBp->bp_action == WDB_ACTION_STOP))
	pBp->bp_action = WDB_ACTION_STOP | WDB_ACTION_NOTIFY;

    wdbTaskLock ();		/* disable task switching */
    dll_insert(&pBp->bp_chain, &bpList);
    wdbTaskUnlock ();		/* re-enable task switching */

    if (pBreakPoint->context.contextType != WDB_CTX_SYSTEM)
	if (_wdbTaskBpAdd != NULL)
	    _wdbTaskBpAdd (pBreakPoint);

    *pId = (UINT32)pBp;
    return (WDB_OK);
    }
예제 #30
0
int main ( void ) {
    DlList_T myList;

    myList = dll_create();
    if( myList == 0 ) {
        fputs( "Cannot create list!\n", stderr );
        return( 1 );
    }
    printf( "Initial list is %s\n", 
        dll_empty( myList ) ? "empty" : "not empty" );

    char* one = (char*)malloc( 11 * sizeof(char) );
    char* two = (char*)malloc( 12 * sizeof(char) );
    char* three = (char*)malloc( 11 * sizeof(char) );
    strcpy( one, "First Line" );
    strcpy( two, "Second Line" );
    strcpy( three, "Third Line" );

    printf( "Checking cursor initialized null...\n");
    if( dll_has_next( myList ) ) {
        printf( "Your possition is valid\n" );
    } else {
        printf( "Your possition is NOT valid\n" );
    }

    // Test append
    printf( "List size: %d\n", dll_size( myList ) );

    printf( "Adding \"%s\"\n", one );
    dll_append( myList, one );
    printf( "List size: %d\n", dll_size( myList ) );

    printf( "Adding \"%s\"\n", two );
    dll_append( myList, two );
    printf( "List size: %d\n", dll_size( myList ) );

    printf( "Adding \"%s\"\n", three );
    dll_append( myList, three );
    printf( "List size: %d\n", dll_size( myList ) );

    printf( "Checking cursor fixed with appends...\n");
    if( dll_has_next( myList ) ) {
        printf( "Your possition is valid\n" );
    } else {
        printf( "Your possition is NOT valid\n" );
    }

    printf( "Test cursor movement...\n" );
    if( dll_move_to( myList, 3 ) ) {
        printf( "You moved to an index you shouldn't be able to\n" );
    } else {
        printf( "You can't move the cursor to 3\n" );
    }

    if( dll_move_to( myList, 2 ) ) {
        printf( "moved to the last index\n" );
    } else { 
        printf( "movement problem to index 2\n" );
    }

    if( dll_move_to( myList, 0 ) ) {
        printf( "moved to the first index\n" );
    } else { 
        printf( "movement problem to index 0\n" );
    }

    printf( "Checking cursor still valid...\n" );
    if( dll_has_next( myList ) ) {
        printf( "Your possition is valid\n" );
    } else {
        printf( "Your possition is NOT valid\n" );
    }

    printf( "Print state and test dll_next:\n" );
    void* data = dll_next( myList );
    int index = 0;
    // Index 0
    printf( "[%d] \"%s\"\n", index, (char*)data );
    data = dll_next( myList );
    index++;
    // Index 1
    printf( "[%d] \"%s\"\n", index, (char*)data );
    data = dll_next( myList );
    index++;
    // Index 2
    printf( "[%d] \"%s\"\n", index, (char*)data );
    data = dll_next( myList );
    index++;
    // Index 3 (Should be the same as index 2 as it should not exist)
    printf( "[%d] \"%s\"\n", index, (char*)data );
    data = dll_next( myList );

    printf( "Lets work backwards:\n" );
    data = dll_prev( myList );
    index = dll_size( myList ) - 1;
    // Index 2
    printf( "[%d] \"%s\"\n", index, (char*)data );
    data = dll_prev( myList );
    index--;
    // Index 1
    printf( "[%d] \"%s\"\n", index, (char*)data );
    data = dll_prev( myList );
    index--;
    // Index 0
    printf( "[%d] \"%s\"\n", index, (char*)data );
    data = dll_prev( myList );
    index--;
    // Index -1 (Should be same as index 0 as it should not exist)
    printf( "[%d] \"%s\"\n", index, (char*)data );
    data = dll_prev( myList );

    char* four = (char*)malloc( 12 * sizeof(char) );
    char* five = (char*)malloc( 11 * sizeof(char) );
    char* six = (char*)malloc( 11 * sizeof(char) );
    char* seven = (char*)malloc( 13 * sizeof(char) );
    char* eight = (char*)malloc( 12 * sizeof(char) );
    strcpy( four, "Fourth Line" );
    strcpy( five, "Fifth Line" );
    strcpy( six, "Sixth Line" );
    strcpy( seven, "Seventh Line" );
    strcpy( eight, "Eighth Line" );

    printf( "Testing inserts\n" );
    dll_insert_at( myList, 0, six );
    printf( "List size: %d\n", dll_size( myList ) );

    dll_insert_at( myList, 2, seven );
    printf( "List size: %d\n", dll_size( myList ) );

    dll_insert_at( myList, 4, eight );
    printf( "List size: %d\n", dll_size( myList ) );

    printf( "Test full print and check inserts\n" );
    index = 0;
    data = dll_get( myList, index );
    while( data != NULL ) {
        printf( "[%d] \"%s\"\n", index, (char*)data );
        index++;
        data = dll_get( myList, index );
    }

    printf( "Test Sets\n" );
    data = dll_set( myList, 0, five );
    printf( "Switched \"%s\" with \"%s\"\n", (char*)data, five );
    free( data );

    data = dll_set( myList, 2, four );
    printf( "Switched \"%s\" with \"%s\"\n", (char*)data, four );
    free( data );

    printf( "Test full print and check sets\n" );
    index = 0;
    data = dll_get( myList, index );
    while( data != NULL ) {
        printf( "[%d] \"%s\"\n", index, (char*)data );
        index++;
        data = dll_get( myList, index );
    }
    
    printf( "Testing popping\n" );
    data = dll_pop( myList, dll_size( myList ) -1 );
    printf( "Last element is: \"%s\"\n", (char*)data );
    free( data );

    data = dll_pop( myList, 2 );
    printf( "Third element is: \"%s\"\n", (char*)data );
    free( data );

    printf( "Poping the rest...\n");
    index = 0;
    data = dll_pop( myList, 0 );
    while( data != NULL ) {
        printf( "[%d] \"%s\"\n", index, (char*)data );
        free( data );
        index++;
        data = dll_pop( myList, 0 );
    }

    printf( "Destroying\n" );
    dll_destroy( myList );
}