예제 #1
0
파일: sample.c 프로젝트: Moumou38/ITD
int main(void) {
	A* a = malloc(sizeof(A)), *b = malloc(sizeof(A)), *c = NULL;
	List* l = list_init();
	Stack* s = stack_init();
	Queue* q = queue_init();
	DoubleLinkedList* d = dll_init();
	printf("a: %d\nB: %d\nc: %d\n", (int)a, (int)b, (int)c);
	a->a1 = 1;
	a->a2 = 'c';
	b->a1 = 2;
	b->a2 = 'a';

	printf("\n=== LIST TEST ===\n");
	list_add(l, a, 0);
	list_append(l, b);
	list_remove(l, 0);
	list_print(l);	
	c = list_get(l, 0);
	printf("c: %d\n", (int)c);
	list_delete(l);

	printf("\n=== STACK TEST ===\n");
	stack_push(s, b);
	stack_push(s, a);
	stack_pop(s);
	stack_print(s);
	c = stack_peek(s);
	printf("c: %d\n", (int)c);
	stack_delete(s);

	printf("\n=== QUEUE TEST ===\n");
	queue_push(q, a);
	queue_push(q, b);
	queue_pop(q);
	queue_print(q);
	c = queue_peek(q);
	printf("c: %d\n", (int)c);
	queue_delete(q);

	printf("\n=== DOUBLE LINKED LIST TEST ===\n");
	dll_add(d, b, 0);
	dll_prepend(d, a);
	dll_remove(d, 1);
	dll_print(d);
	c = dll_get(d, 0);
	printf("c: %d\n", (int)c);
	dll_delete(d);

	free(a);
	free(b);
	return 0;
}
예제 #2
0
void dll_merge (dll_t *_p_to, dll_t *_p_from)
{
    if (0 == _p_to->count_) {
        *_p_to = *_p_from;
    }
    else if (0 != _p_from->count_) {
        _p_from->head_->prev_ = _p_to->tail_;
        _p_to->tail_->next_ = _p_from->head_;
        _p_to->tail_ = _p_from->tail_;
        _p_to->count_ += _p_from->count_;
    }
    dll_init (_p_from);
}
예제 #3
0
void dllht_init (dllht_t *_p_dllht, dllht_bucket_t *_buckets, 
    usize_t _bucket_size, calculate_callback_t _key_calc_func, traverse_callback_t _compare_func)
{
    usize_t index;
    
    for (index = 0; index < _bucket_size; ++ index) {
        dll_init (&_buckets[index].dll_);
    }
    
    _p_dllht->buckets_ = _buckets;
    _p_dllht->key_calc_func_ = _key_calc_func;
    _p_dllht->compare_func_ = _compare_func;
}
예제 #4
0
파일: dtq.c 프로젝트: AHCALMonitoring/dim
int dim_dtq_init(int thr_flag)
{
	int tid = 1;
	void create_alrm_thread(void);

	if( !sigvec_done ) {
		Inside_ast = 0;
	    Alarm_runs = 0;
	    DIM_last_time = 0;
/*
	    for(i = 0; i < MAX_TIMER_QUEUES + 2; i++)
	    {
	        timer_queues[i].queue_head = 0;
			timer_queues[i].remove_entries = 0;
	    }
*/
		if( timer_queues[SPECIAL_QUEUE].queue_head == NULL ) {
			timer_queues[SPECIAL_QUEUE].queue_head = (TIMR_ENT *)malloc(sizeof(TIMR_ENT));
			memset(timer_queues[SPECIAL_QUEUE].queue_head, 0, sizeof(TIMR_ENT));
			dll_init( (DLL *)timer_queues[SPECIAL_QUEUE].queue_head);
		}
		if( timer_queues[WRITE_QUEUE].queue_head == NULL ) {
			timer_queues[WRITE_QUEUE].queue_head = (TIMR_ENT *)malloc(sizeof(TIMR_ENT));
			memset(timer_queues[WRITE_QUEUE].queue_head, 0, sizeof(TIMR_ENT));
			dll_init( (DLL *)timer_queues[WRITE_QUEUE].queue_head);
		}
/*
#ifndef STDCALL
		tid = _beginthread((void *)(void *)dtq_task,0,NULL);
#else
		tid = _beginthreadex(NULL, NULL,
			dtq_task,0,0,NULL);
#endif
*/
		create_alrm_thread();
		sigvec_done = 1;
	}
	return(tid);
}
예제 #5
0
CVectorObj::CVectorObj()
{ 
	m_drvidx = 0;

	m_channel = 0;
	m_channelMask = 0;
	m_initFlag = 0;
	m_nBrdType = 0;
	m_idxBoard = 0;
	m_portHandle = INVALID_PORTHANDLE;
	
	// No filter mask
	m_filter = 0;
	m_mask = 0;

	m_bRun = false;

#ifdef WIN32
	
	m_hTreadReceive = 0;
	m_hTreadTransmit = 0;

	// Create the device AND LIST access mutexes
	m_vectorMutex = CreateMutex( NULL, true, CANAL_DLL_VECTOR_OBJ_MUTEX );
	m_receiveMutex = CreateMutex( NULL, true, CANAL_DLL_VECTOR_RECEIVE_MUTEX );
	m_transmitMutex = CreateMutex( NULL, true, CANAL_DLL_VECTOR_TRANSMIT_MUTEX );

#else
	
	m_flog = NULL;
	pthread_mutex_init( &m_vectorMutex, NULL );
	pthread_mutex_init( &m_receiveMutex, NULL );
	pthread_mutex_init( &m_transmitMutex, NULL );

#endif

	dll_init( &m_transmitList, SORT_NONE );
	dll_init( &m_receiveList, SORT_NONE );
}
예제 #6
0
void dll_split (dll_t *_p_orig, dll_t *_p_derived, dll_node_t *_p_breakpoint, 
    bool _breakpoint_belongs_to_orig)
{
    dll_node_t *p_node;
    
    if (_breakpoint_belongs_to_orig) {
        if (0 == _p_breakpoint->next_) {
            dll_init (_p_derived);
            return;
        }
        *_p_derived = *_p_orig;
        _p_orig->tail_ = _p_breakpoint;
        _p_derived->head_ = _p_breakpoint->next_;
        _p_breakpoint->next_->prev_ = 0;
        _p_breakpoint->next_ = 0;
    }
    else {
        if (0 == _p_breakpoint->prev_) {
            *_p_derived = *_p_orig;
            dll_init (_p_orig);
            return;
        }
        *_p_derived = *_p_orig;
        _p_orig->tail_ = _p_breakpoint->prev_;
        _p_derived->head_ = _p_breakpoint;
        _p_breakpoint->prev_->next_ = 0;
        _p_breakpoint->prev_ = 0;
    }

    _p_orig->count_ = 0;
    p_node = _p_orig->head_;
    while (p_node != 0) {
        _p_orig->count_ ++;
        p_node = p_node->next_;
    }

    _p_derived->count_ -= _p_orig->count_;
}
예제 #7
0
static void si_init(void) {
    // Create stack for linenumbers
    lineno_stack = dll_init();

    // Initialize scope
    scope_stack = stack_init();

    // Add global scope
    t_scope *tmp = smm_malloc(sizeof(t_scope));
    tmp->context = NULL;
    tmp->depth = 0;
    tmp->entrypoint = NULL;
    stack_push(scope_stack, tmp);
}
예제 #8
0
BOOL dll_removeAllNodes( struct DoubleLinkedList *pdll )
{	
  if ( NULL == pdll ) return FALSE;

  while ( NULL != pdll->pHead ) {
    dll_removeNode( pdll, pdll->pTail );
  }	
  
  dll_init( pdll, 0 );

  pdll->nCount = 0;

  return TRUE;
};
예제 #9
0
void spirit1_waitforstandby() {
/// Wait for the Ready Pin to go low (reset pin is remapped in init).
///@todo implement this using WFE instead of while loop
    ot_uint watchdog = 10;

    spirit1_waitforstandby_TOP:
    while (spirit1_readypin_ishigh() && (--watchdog));

    // Critical Failure
    if (watchdog == 0) {
        ///@todo failure code that logs hardware fault and resets OT
        spirit1_shutdown(300);
        dll_init();
    }
}
예제 #10
0
static BOOL LoadHSP(void)
{
	int res;
#ifdef HSPDEBUG
	res = hsp3ax2dll_init( hDllInstance, "obj" );
#else
	res = hsp3ax2dll_init( hDllInstance, NULL );
#endif
	if (res)
	{
		return FALSE;
	}
	dll_init();
	return TRUE;
}
예제 #11
0
CIxxObj::CIxxObj()
{ 
	
	m_channel = 0;
	m_initFlag = 0;
	m_dwBrdType = VCI_UNKNOWN;
	m_dwBrdTypeRelatedIndex = 0;
	
	// No filter mask
	m_filter = 0;
	m_mask = 0;

	m_bRun = false;

#ifdef WIN32
	
	m_hTreadReceive = 0;
	m_hTreadTransmit = 0;

	// Create the device AND LIST access mutexes
	m_ixxMutex = CreateMutex( NULL, true, CANAL_DLL_IXXATVCIDRV_OBJ_MUTEX );
	m_receiveMutex = CreateMutex( NULL, true, CANAL_DLL_IXXATVCIDRV_RECEIVE_MUTEX );
	m_transmitMutex = CreateMutex( NULL, true, CANAL_DLL_IXXATVCIDRV_TRANSMIT_MUTEX );

#else
	
	m_flog = NULL;
	pthread_mutex_init( &m_ixxMutex, NULL );
	pthread_mutex_init( &m_receiveMutex, NULL );
	pthread_mutex_init( &m_transmitMutex, NULL );

#endif

	dll_init( &m_transmitList, SORT_NONE );
	dll_init( &m_receiveList, SORT_NONE );
}
void d7ap_stack_init(void)
{
    assert(d7ap_stack_state == D7AP_STACK_STATE_STOPPED);
    d7ap_stack_state = D7AP_STACK_STATE_IDLE;

    d7asp_init();
    d7atp_init();
    d7anp_init();
    packet_queue_init();
    dll_init();
    init_session_list();

    for(int i = 0; i < 15; i++)
      fs_register_file_modified_callback(D7A_FILE_ACCESS_PROFILE_ID + i, &on_access_profile_file_changed);
}
예제 #13
0
CApoxObj::CApoxObj()
{ 
	m_initFlag = 0;
	
	// No filter mask
	m_filter = 0;
	m_mask = 0;

	m_bRun = false;

#ifdef WIN32
	
	m_hTreadReceive = 0;
	m_hTreadTransmit = 0;

	// Create the device AND LIST access mutexes
	m_apoxMutex = CreateMutex( NULL, true, CANAL_DLL_APOXDRV_OBJ_MUTEX );
	m_receiveMutex = CreateMutex( NULL, true, CANAL_DLL_APOXDRV_RECEIVE_MUTEX );
	m_transmitMutex = CreateMutex( NULL, true, CANAL_DLL_APOXDRV_TRANSMIT_MUTEX );
	m_responseMutex = CreateMutex( NULL, true, CANAL_DLL_APOXDRV_RESPONSE_MUTEX );

#else
	
	m_flog = NULL;
	pthread_mutex_init( &m_apoxMutex, NULL );
	pthread_mutex_init( &m_receiveMutex, NULL );
	pthread_mutex_init( &m_transmitMutex, NULL );
	pthread_mutex_init( &m_responseMutex, NULL );

#endif

	dll_init( &m_transmitList, SORT_NONE );
	dll_init( &m_receiveList, SORT_NONE );
	dll_init( &m_responseList, SORT_NONE );
	
}
예제 #14
0
void /* Initialize a flow ring's queue */
dhd_flow_queue_init(dhd_pub_t *dhdp, flow_queue_t *queue, int max)
{
	ASSERT((queue != NULL) && (max > 0));

	dll_init(&queue->list);
	queue->head = queue->tail = NULL;
	queue->len = 0;
	queue->max = max - 1;
	queue->failures = 0U;
	queue->cb = &dhd_flow_queue_overflow;
	queue->lock = dhd_os_spin_lock_init(dhdp->osh);

	if (queue->lock == NULL)
		DHD_ERROR(("%s: Failed to init spinlock for queue!\n", __FUNCTION__));
}
예제 #15
0
파일: FINDZIP.C 프로젝트: wkoiking/xyzzy
BOOL   WINAPI   DllMain (HANDLE hInst, ULONG ul_reason_for_call,LPVOID lpReserved)
{
   switch( ul_reason_for_call) {
    case DLL_PROCESS_ATTACH:
		return dll_init();
		break;
    case DLL_THREAD_ATTACH:
		break;
    case DLL_PROCESS_DETACH:
		return dll_end();
		break;
    case DLL_THREAD_DETACH:
		break;
    }
    return TRUE;
}	
예제 #16
0
void spirit1_waitforabort() {
/// Wait for the RX/TX indicator pin to go off.
/// @todo this may need to be state-based.  In other words, if ABORT is
///       called during the CSMA mode, the pin may be different or it may
///       not be included at all.

    ///@todo implement this using WFE instead of while loop
    ot_uint watchdog = 100;
    while (spirit1_abortpin_ishigh() && (--watchdog));

    if (watchdog == 0) {
        //abort_fails++;
        ///@todo failure code that logs hardware fault and resets OT
        spirit1_shutdown(300);
        dll_init();
    }
}
예제 #17
0
파일: device.c 프로젝트: ljvblfz/clearrtos
error_t driver_install (const char _name [], const device_operation_t *_p_operation, 
    device_mode_t _mode)
{
    int idx;
    driver_handle_t p_driver = null;
    const char *dev_root = "/dev/";

    if ((null == _name) || (strncmp (_name, dev_root, strlen (dev_root)) != 0)) {
        // a driver has no name?
        return ERROR_T (ERROR_DRIVER_INVNAME);
    }
    if (null == _p_operation || null == _p_operation->open_ ||
        null == _p_operation->close_) {
        return ERROR_T (ERROR_DRIVER_INVOPT);
    }
    // a driver only can be installed before system is UP
    if (system_state () > STATE_INITIALIZING) {
        return ERROR_T (ERROR_DRIVER_INVSTATE);
    }
    // check whether the driver is already installed
    for (idx = 0; idx <= DRIVER_LAST_INDEX; idx ++) {
        if ((MAGIC_NUMBER_DRIVER == g_driver_pool [idx].magic_number_) &&
            (0 == strncmp (g_driver_pool [idx].name_, _name, strlen (_name)))) {
            return ERROR_T (ERROR_DRIVER_INSTALLED);
        }
    }

    for (idx = 0; idx <= DRIVER_LAST_INDEX; idx ++) {
        if (g_driver_pool [idx].magic_number_ != MAGIC_NUMBER_DRIVER) {
            p_driver = &g_driver_pool [idx];
            break;
        }
    }
    if (null == p_driver) {
        return ERROR_T (ERROR_DRIVER_NODRV);
    }
    p_driver->magic_number_ = MAGIC_NUMBER_DRIVER;
    p_driver->operation_ = *_p_operation;
    p_driver->mode_ = _mode;
    strncpy (p_driver->name_, _name, sizeof (p_driver->name_) - 1);
    p_driver->name_ [sizeof (p_driver->name_) - 1] = 0;
    dll_init (&p_driver->devices_);
    return 0;
}
예제 #18
0
void wdbExcLibInit (void)
    {
    int ix;

    /* initialize our event node */

    wdbEventNodeInit (&wdbExcEvtNode, wdbExcGetEvent,
			wdbExcDeqEvent, NULL);

    /* initialize the linked list of exceptions */

    dll_init (&wdbExcEvtList);
    for (ix = 0; ix < MAX_EXC_EVENTS; ix++)
	dll_insert (&excInfoNode[ix].node, &wdbExcEvtList);

    /* add our exception hook to the run-time exception handler */

    (*pWdbRtIf->excHookAdd)(wdbExcHook);
    }
예제 #19
0
void spirit1_waitforready() {
/// Wait for the Ready Pin to go high (reset pin is remapped in init).
/// STANDBY->READY should take about 75us, although the absolute worst
/// case is: 220us, 230us, 240us, 440us, 460us, 480us with respective
/// 52, 50, 48, 26, 25, 24 MHz crystals.  By inspection, the loop takes
/// 8 cycles to complete one iteration, and we assume a clock speed of
/// 16 MHz.

    ///@todo implement this using WFE instead of while loop
    ot_uint watchdog = 500;
    while ((spirit1_readypin_ishigh() == 0) && (--watchdog));

    if (watchdog == 0){
        //ready_fails++;
        ///@todo failure code that logs hardware fault and resets OT
        spirit1_shutdown(300);
        dll_init();
    }
}
예제 #20
0
파일: estrella.c 프로젝트: ninloth/estrella
int estrella_get_device(estrella_dev_t *dev, int num)
{
    int rc;
    unsigned int listsize;
    dll_list_t devices;
    void *devtmp;

    if (!dev)
        return ESTRINV;

    rc = dll_init(&devices);
    if (rc != EDLLOK)
        return ESTRERR;

    rc = estrella_find_devices(&devices);
    if (rc != ESTROK) {
        dll_clear(&devices);
        return ESTRERR;
    }

    rc = dll_count(&devices, &listsize);
    if (rc != EDLLOK) {
        dll_clear(&devices);
        return ESTRERR;
    }

    if ((num >= (int)listsize) || (num < 0)) {
        dll_clear(&devices);
        return ESTRINV;
    }

    rc = dll_get(&devices, (void**)&devtmp, NULL, num);
    if (rc != EDLLOK) {
        dll_clear(&devices);
        return ESTRERR;
    }

    memcpy(dev, (estrella_dev_t*)devtmp, sizeof(estrella_dev_t));
    dll_clear(&devices);

    return ESTROK;
}
예제 #21
0
파일: DLList.c 프로젝트: co0p/piquet
int main(int argc, char *argv[]) {

  dllist_t *list = (dllist_t*) malloc(sizeof(dllist_t));
  dll_init(list);
  dll_print(list);

  dll_add(list, 12);
  dll_print(list);

  dll_add(list, 12);
  dll_add(list, 13);
  dll_add(list, 14);
  dll_print(list);
  
  dll_remove(list, 12);
  dll_print(list);

  dll_delete(list);
  free(list);
  return 0;
}
예제 #22
0
파일: dtq.c 프로젝트: AHCALMonitoring/dim
int dtq_create()
{
	int i;
	extern void dim_init_threads(void);

	if(!Threads_off)
	{
		dim_init_threads();
	}
	dim_dtq_init(0);
	for( i = 1; i < MAX_TIMER_QUEUES; i++ )
		if( timer_queues[i].queue_head == 0 )
			break;

	if( i == MAX_TIMER_QUEUES )
		return(0);

	timer_queues[i].queue_head = (TIMR_ENT *)malloc( sizeof(TIMR_ENT) );
	memset( timer_queues[i].queue_head, 0, sizeof(TIMR_ENT) );
	dll_init( (DLL *)timer_queues[i].queue_head);

	return(i);
}
예제 #23
0
파일: mp1client.c 프로젝트: fairymane/cs438
int main(int argc, char *argv[])
{
	int sockfd;  
	struct addrinfo hints, *servinfo, *p;
	int rv;
	char s[INET6_ADDRSTRLEN];

	if (argc != 4) {
	    fprintf(stderr,"usage: %s <hostname> <port #> <output file>\n",argv[0]);
	    exit(1);
	}

	memset(&hints, 0, sizeof hints);
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;

	if ((rv = getaddrinfo(argv[1], argv[2], &hints, &servinfo)) != 0) {
		fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
		exit(1);
	}

	// loop through all the results and connect to the first we can
	for(p = servinfo; p != NULL; p = p->ai_next) {
		if ((sockfd = socket(p->ai_family, p->ai_socktype,
				p->ai_protocol)) == -1) {
			perror("client: socket");
			continue;
		}

		if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
			close(sockfd);
			perror("client: connect");
			continue;
		}
		break;
	}

	if (p == NULL) {
		fprintf(stderr, "client: failed to connect");
		exit(1);
	}
	inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),s, sizeof s);
	
	printf("client: connecting to %s\n",s);
	freeaddrinfo(servinfo); // all done with this structure

	FILE *file=fopen(argv[3],"w");
	if(file==NULL){
		fprintf(stderr,"file %s open error",argv[3]);
		exit(1);
	}
		
	pthread_t read_tid,write_tid;
	dll_init(&l);
	pthread_cond_init(&c,NULL);
	pthread_mutex_init(&m,NULL);

	pthread_create(&read_tid,NULL,&myread,(void*)&sockfd);
	pthread_create(&write_tid,NULL,&mywrite,(void*)file);

	pthread_join(read_tid, NULL);
	pthread_join(write_tid,NULL);

	fclose(file);
	dll_destroy(&l);
	pthread_mutex_destroy(&m);
	pthread_cond_destroy(&c);
	return 0;
}
예제 #24
0
static t_snode *_interpreter(t_ast_element *p) {
    t_object *obj, *obj1, *obj2, *obj3;
    t_snode *node1, *node2, *node3;
    int initial_loop;
    t_ast_element *hte;
    char *ctx_name, *name;
    wchar_t *wchar_tmp;
    t_dll *dll;
    t_scope *scope;

    // Append to lineno
    dll_append(lineno_stack, (void *)p->lineno);

    // No element found, return NULL object
    if (!p) {
        RETURN_SNODE_OBJECT(Object_Null);
    }


    switch (p->type) {
        case typeAstNull :
            RETURN_SNODE_NULL();
            break;
        case typeAstInterface:
            // @TODO
            RETURN_SNODE_NULL();
            break;
        case typeAstString :
            DEBUG_PRINT("new string object: '%s'\n", p->string.value);

            // Allocate enough room to hold string in wchar and convert
            int len = strlen(p->string.value) * sizeof(wchar_t);
            wchar_tmp = (wchar_t *)smm_malloc(len * sizeof(wchar_t));
            memset(wchar_tmp, 0, len * sizeof(wchar_t));
            mbstowcs(wchar_tmp, p->string.value, strlen(p->string.value));

            // create string object
            obj = object_new(Object_String, wchar_tmp);

            // Free tmp wide string
            smm_free(wchar_tmp);
            RETURN_SNODE_OBJECT(obj);
            break;

        case typeAstNumerical :
            DEBUG_PRINT("new numerical object: %d\n", p->numerical.value);
            // Create numerical object
            obj = object_new(Object_Numerical, p->numerical.value);
            RETURN_SNODE_OBJECT(obj);
            break;

        case typeAstIdentifier :
            // Do constant vars
            if (strcasecmp(p->string.value, "True") == 0) {
                //RETURN_SNODE_OBJECT(Object_True);
                RETURN_SNODE_IDENTIFIER(NULL, Object_True);
            }
            if (strcasecmp(p->string.value, "False") == 0) {
                DEBUG_PRINT("Retuning false!");
                //RETURN_SNODE_OBJECT(Object_False);
                RETURN_SNODE_IDENTIFIER(NULL, Object_False);
            }
            if (strcasecmp(p->string.value, "Null") == 0) {
                //RETURN_SNODE_OBJECT(Object_Null);
                RETURN_SNODE_IDENTIFIER(NULL, Object_Null);
            }

            obj = si_find_var_in_context(p->string.value, NULL);
            RETURN_SNODE_IDENTIFIER(p->string.value, obj);
            break;

        case typeAstClass :
            obj = (t_object *)smm_malloc(sizeof(t_object));
            obj->ref_count = 0;
            obj->type = objectTypeAny;
            obj->name = smm_strdup(p->class.name);
            obj->flags = OBJECT_TYPE_CLASS;
            obj->parent = NULL;
            obj->implement_count = 0;
            obj->implements = NULL;
            obj->methods = ht_create();
            obj->properties = ht_create();
            obj->constants = ht_create();
            obj->operators = NULL;
            obj->comparisons = NULL;
            obj->funcs = &user_funcs;

            // @TODO: Add modifier flags to obj->flags


            // Check extends
            obj->parent = Object_Base;

            // Interpret body.
            t_object *saved_obj = current_obj;
            current_obj = obj;
            _interpreter(p->class.body);
            current_obj = saved_obj;

            // Add the object to the current context
            t_ns_context *ctx = si_get_current_context();
            si_context_add_object(ctx, obj);
            break;

        case typeAstMethod :
            if (current_obj == NULL) {
                saffire_error("Trying to define a method outside a class. This should be caught by the parser!");
            }
            DEBUG_PRINT("Adding method: %s to %s\n", p->method.name, current_obj->name);

            // @TODO: ADD FLAGS AND VISIBILITY
            int vis = 0;
            if (p->method.modifiers & MODIFIER_PUBLIC) vis |= METHOD_VISIBILITY_PUBLIC;
            if (p->method.modifiers & MODIFIER_PROTECTED) vis |= METHOD_VISIBILITY_PROTECTED;
            if (p->method.modifiers & MODIFIER_PRIVATE) vis |= METHOD_VISIBILITY_PRIVATE;

            int flags = 0;
            if (p->method.modifiers & MODIFIER_FINAL) flags |= METHOD_FLAG_FINAL;
            if (p->method.modifiers & MODIFIER_ABSTRACT) flags |= METHOD_FLAG_ABSTRACT;
            if (p->method.modifiers & MODIFIER_STATIC) flags |= METHOD_FLAG_STATIC;

            object_add_external_method(current_obj, p->method.name, flags, vis, p->method.body);
            break;

        case typeAstOpr :
            DEBUG_PRINT("opr.oper: %s(%d)\n", get_token_string(p->opr.oper), p->opr.oper);
            switch (p->opr.oper) {
                case T_PROGRAM :
                    SI0(p); // parse use declarations
                    SI1(p); // parse top statements
                    break;
                case T_TOP_STATEMENTS:
                case T_USE_STATEMENTS:
                case T_STATEMENTS :
                    for (int i=0; i!=OP_CNT(p); i++) {
                        _interpreter(p->opr.ops[i]);
                    }
                    // Statements do not return anything
                    RETURN_SNODE_NULL(); // (well, it should)
                    break;

                case T_IMPORT :
                    // Class to import
                    node1 = SI0(p);
                    obj1 = si_get_object(node1);
                    char *classname = OBJ2STR(obj1);

                    // Fetch alias
                    node2 = SI1(p);
                    if (IS_NULL(node2)) {
                        node2 = node1;  // Alias X as X if needed
                    }
                    obj2 = si_get_object(node2);
                    char *alias = OBJ2STR(obj2);

                    // context to import from
                    node3 = SI2(p);
                    obj3 = si_get_object(node3);
                    ctx_name = OBJ2STR(obj3);


                    // Check if variable is free
                    if (si_find_var_in_context(alias, NULL)) {
                        saffire_error("A variable named %s is already present or imported.", alias);
                    }

                    // Find class in context
                    ctx = si_get_context(ctx_name);
                    if (ctx == NULL) {
                        saffire_error("Cannot find context: %s", ctx_name);
                    }
                    obj = si_find_var_in_context(classname, ctx);
                    if (! obj) {
                        saffire_error("Cannot find class %s inside context: %s", classname, ctx_name);
                    }

                    // Add the object to the current context as the alias variable
                    si_create_var_in_context(alias, NULL, obj, CTX_CREATE_ONLY);

                    DEBUG_PRINT("Imported class %s as %s from %s into %s\n", classname, alias, ctx_name, ctx->name);
                    break;
                case T_USE :
                    // Class to use
                    node1 = SI0(p);
                    obj1 = si_get_object(node1);
                    name = OBJ2STR(obj1);

                    if (OP_CNT(p) > 1) {
                        // Fetch alias
                        node2 = SI1(p);
                        if (IS_NULL(node2)) {
                            node2 = node1;  // Alias X as X
                        }
                    } else {
                        node2 = node1;  // Alias X as X
                    }
                    obj2 = si_get_object(node2);
                    alias = OBJ2STR(obj2);

                    // Check if variable is free
                    ctx = si_find_context(alias);
                    if (ctx != NULL) {
                        saffire_error("A context named %s is already present or imported.", alias);
                    }

                    ctx = si_find_context(name);
                    if (ctx == NULL) {
                        saffire_error("Context %s was not found.", name);
                    }

                    si_create_context_alias(alias, ctx);
                    break;

                case T_RETURN :
                    // Check the current scope.
                    scope = get_current_scope();
                    if (scope->depth == 1) {
                        DEBUG_PRINT("Cannot leave the global scope!");
                    }
                    
                    node1 = SI0(p);
                    obj = si_get_object(node1);
                    RETURN_SNODE_OBJECT(obj);
                    break;

                case T_EXPRESSIONS :
                    // No expression, just return NULL
                    if (OP_CNT(p) == 0) {
                        RETURN_SNODE_NULL();
                    }

                    // Do all expressions
                    for (int i=0; i!=OP_CNT(p); i++) {
                        node1 = _interpreter(p->opr.ops[i]);
                        // Remember the first node
                        if (i == 0) node2 = node1;
                    }
                    return node2;
                    break;

                case T_ASSIGNMENT :
                    // Fetch LHS node
                    node1 = SI0(p);

                    // it should be a variable, otherwise we cannot write to it..

                    // @TODO: THIS IS WRONG. AN ID ALWAYS HAS AN KEY?
                    if (! HAS_IDENTIFIER_ID(node1)) {
                        saffire_error("Left hand side is not writable!");
                    }

                    // Check if we have a normal assignment. We only support this for now...
                    t_ast_element *e = p->opr.ops[1];
                    if (e->type != typeAstOpr || e->opr.oper != T_ASSIGNMENT) {
                        saffire_error("We only support = assignments (no += etc)");
                    }

                    // Evaluate the RHS
                    node3 = SI2(p);

                    // Get the object and store it
                    obj1 = si_get_object(node3);
                    si_set_object(node1, obj1);

                    RETURN_SNODE_OBJECT(obj1);
                    break;

                /**
                 * Control structures
                 */
                case T_DO :
                    do {
                        // Always execute our inner block at least once
                        SI0(p);

                        // Check condition
                        node1 = SI1(p);
                        obj1 = si_get_object(node1);
                        // Check if it's already a boolean. If not, cast this object to boolean
                        if (! OBJECT_IS_BOOLEAN(obj1)) {
                            obj2 = object_find_method(obj1, "boolean");
                            obj1 = object_call(obj1, obj2, 0);
                        }

                        // False, we can break our do-loop
                        if (obj1 == Object_False) {
                            break;
                        }
                    } while (1);

                    RETURN_SNODE_NULL();
                    break;

                case T_WHILE :
                    initial_loop = 1;
                    while (1) {
                        // Check condition first
                        node1 = SI0(p);
                        obj1 = si_get_object(node1);
                        // Check if it's already a boolean. If not, cast this object to boolean
                        if (! OBJECT_IS_BOOLEAN(obj1)) {
                            obj2 = object_find_method(obj1, "boolean");
                            obj1 = object_call(obj1, obj2, 0);
                        }

                        // if condition is true, execute our inner block
                        if (obj1 == Object_True) {
                            SI1(p);
                        } else {
                            // If the first loop is false and we've got an else statement, execute it.
                            if (initial_loop && OP_CNT(p) > 2) {
                                SI2(p);
                            }
                            break;
                        }

                        initial_loop = 0;
                    }

                    RETURN_SNODE_NULL();
                    break;

                case T_FOR :
                    // Evaluate first part
                    node1 = SI0(p);

                    while (1) {
                        // Check condition first
                        node2 = SI1(p);
                        obj1 = si_get_object(node2);
                        // Check if it's already a boolean. If not, cast this object to boolean
                        if (! OBJECT_IS_BOOLEAN(obj1)) {
                            obj2 = object_find_method(obj1, "boolean");
                            obj1 = object_call(obj1, obj2, 0);
                        }

                        // if condition is not true, break our loop
                        if (obj1 != Object_True) {
                            break;
                        }

                        // Condition is true, execute our inner loop
                        SI3(p);

                        // Finally, evaluate our last block
                        SI2(p);
                    }

                    // All done
                    break;

                /**
                 * Conditional statements
                 */
                case T_IF:
                    node1 = SI0(p);
                    obj1 = si_get_object(node1);

                    // Check if it's already a boolean. If not, cast this object to boolean
                    if (! OBJECT_IS_BOOLEAN(obj1)) {
                        obj2 = object_find_method(obj1, "boolean");
                        obj1 = object_call(obj1, obj2, 0);
                    }

                    if (obj1 == Object_True) {
                        // Execute if-block
                        node2 = SI1(p);
                    } else if (OP_CNT(p) > 2) {
                        // Execute (optional) else-block
                        node2 = SI2(p);
                    }
                    break;

                case T_ARGUMENT_LIST:
                    dll = dll_init();
                    for (int i=0; i!=OP_CNT(p); i++) {
                        node1 = _interpreter(p->opr.ops[i]);
                        obj1 = si_get_object(node1);
                        dll_append(dll, obj1);
                    }
                    RETURN_SNODE_DLL(dll);

                case T_METHOD_CALL :
                    // Get object
                    node1 = SI0(p);
                    obj1 = IS_NULL(node1) ? NULL : si_get_object(node1);

                    if (obj1 != NULL) {
                        hte = p->opr.ops[1];
                        obj2 = object_find_method(obj1,  hte->identifier.name);
                        if (! obj2) {
                            saffire_error("Cannot find method or property named '%s' in '%s'", hte->identifier.name, obj1->name);
                        }
                    } else {
                        // Get object
                        node2 = SI1(p);
                        obj2 = si_get_object(node2);
                    }



                    // Get arguments (or NULL)
                    t_dll *dll = NULL;
                    node2 = SI2(p);
                    if (IS_DLL(node2)) {
                        dll = node2->data.dll;
                    } else if (IS_NULL(node2)) {
                        dll = NULL;
                    } else {
                        saffire_error("Expected a DLL (or null)");
                    }

                    // assume nothing found
                    obj3 = Object_Null;

                    if (OBJECT_IS_METHOD(obj2)) {
                        /*
                         * Lots of method checks before we can actually call this
                         */
                        t_method_object *method = (t_method_object *)obj2;
                        if (METHOD_IS_CONSTRUCTOR(method)) {
                            saffire_error("Cannot call constructor");
                        }
                        if (METHOD_IS_DESTRUCTOR(method)) {
                            saffire_error("Cannot call destructor");
                        }
                        if (OBJECT_TYPE_IS_ABSTRACT(obj1)) {
                            saffire_error("Cannot call an abstract class");
                        }
                        if (OBJECT_TYPE_IS_INTERFACE(obj1)) {
                            saffire_error("Cannot call an interface");
                        }

                        if (OBJECT_TYPE_IS_INSTANCE(obj1) && METHOD_IS_STATIC(method)) {
                            saffire_error("Cannot call a static method from an instance. Hint: use %s.%s()", obj1->name, obj2->name);
                        }
                        if (OBJECT_TYPE_IS_CLASS(obj1) && ! METHOD_IS_STATIC(method)) {
                            saffire_error("Cannot call a non-static method directly from a class. Hint: instantiate first");
                        }


                        // Set new scope
                        enter_scope(p);

                        // We need to do a method call
                        DEBUG_PRINT("+++ Calling method %s \n", obj2->name);
                        obj3 = object_call_args(obj1, obj2, dll);

                        leave_scope();

                    } else if (OBJECT_TYPE_IS_CLASS(obj2)) {
                        // We need to instantiate
                        DEBUG_PRINT("+++ Instantiating a new class for %s\n", obj2->name);

                        enter_scope(p);

                        obj3 = object_new(obj2, dll);
                        if (! obj3) {
                            saffire_error("Cannot instantiate class %s", obj2->name);
                        }

                        leave_scope();
                    } else {
                        saffire_error("Cannot call or instantiate %s", obj2->name);
                    }

//                    } else {
//
//                        // get class or method name
//                        hte = p->opr.ops[1];
//                        if (hte->type != typeAstIdentifier) {
//                            saffire_error("Can only have identifiers here", hte->identifier.name);
//                        }
//
//                        method_name = smm_strdup(hte->identifier.name);
//                    }
//
//                    // At this point we need to fetch the objec,
//
//
//
////                    if (hte->type == typeAstNull && (obj->flags & OBJECT_TYPE_CLASS) == OBJECT_TYPE_CLASS) {
//
//                    if (instantiation) {
//                        // Instantiating
//                        DEBUG_PRINT("+++ Instantiating a new class for %s\n", obj1->name);
//
//                        if (! OBJECT_TYPE_IS_CLASS(obj1)) {
//                            saffire_error("Can only instantiate classes");
//                        }
//
//                        obj2 = object_new(obj1, dll);
//                        if (! obj2) {
//                            saffire_error("Cannot instantiate class %s", obj1->name);
//                        }
//
//                    } else {
//
//                        if (hte->type != typeAstIdentifier) {
//                            saffire_error("Can only have identifiers here", hte->identifier.name);
//                        }
//                        method_name = smm_strdup(hte->identifier.name);
//
//                        obj2 = object_call_args(obj1, method_name, dll);
//
//                        smm_free(method_name);
//                    }


                    if (dll) dll_free(dll);

                    RETURN_SNODE_OBJECT(obj3);
                    break;

                /* Comparisons */
                case '<' :
                    return si_comparison(p, COMPARISON_LT);
                    break;
                case '>' :
                    return si_comparison(p, COMPARISON_GT);
                    break;
                case T_GE :
                    return si_comparison(p, COMPARISON_GE);
                    break;
                case T_LE :
                    return si_comparison(p, COMPARISON_LE);
                    break;
                case T_NE :
                    return si_comparison(p, COMPARISON_NE);
                    break;
                case T_EQ :
                    return si_comparison(p, COMPARISON_EQ);
                    break;

                /* Operators */
                case '+' :
                    return si_operator(p, OPERATOR_ADD);
                    break;
                case '-' :
                    return si_operator(p, OPERATOR_SUB);
                    break;
                case '*' :
                    return si_operator(p, OPERATOR_MUL);
                    break;
                case '/' :
                    return si_operator(p, OPERATOR_DIV);
                    break;
                case T_AND :
                    return si_operator(p, OPERATOR_AND);
                    break;
                case T_OR :
                    return si_operator(p, OPERATOR_OR);
                    break;
                case '^' :
                    return si_operator(p, OPERATOR_XOR);
                    break;
                case T_SHIFT_LEFT :
                    return si_operator(p, OPERATOR_SHL);
                    break;
                case T_SHIFT_RIGHT :
                    return si_operator(p, OPERATOR_SHR);
                    break;

                /* Unary operators */
                case T_OP_INC :
                    // We must be a variable
                    node1 = SI0(p);
                    if (! HAS_IDENTIFIER_ID(node1)) {
                        saffire_error("Left hand side is not writable!");
                    }

                    obj1 = si_get_object(node1);
                    obj2 = object_new(Object_Numerical, 1);
                    obj3 = object_operator(obj1, OPERATOR_ADD, 0, 1, obj2);

                    si_set_object(node1, obj3);

                    RETURN_SNODE_OBJECT(obj3);
                    break;
                case T_OP_DEC :
                    // We must be a variable
                    node1 = SI0(p);
                    if (! HAS_IDENTIFIER_ID(node1)) {
                        saffire_error("Left hand side is not writable!");
                    }

                    obj1 = si_get_object(node1);
                    obj2 = object_new(Object_Numerical, 1);
                    obj3 = object_operator(obj1, OPERATOR_SUB, 0, 1, obj2);

                    si_set_object(node1, obj3);

                    RETURN_SNODE_OBJECT(obj3);
                    break;

                case '.' :
                    node1 = SI0(p);
                    obj1 = si_get_object(node1);

                    // get method name from object
                    hte = p->opr.ops[1];
                    if (hte->type != typeAstIdentifier) {
                        saffire_error("Can only have identifiers here", hte->identifier.name);
                    }

                    DEBUG_PRINT("Figuring out: '%s' in object '%s'\n", hte->identifier.name, obj1->name);
                    obj = ht_find(obj1->properties, hte->identifier.name);
                    if (obj == NULL) {
                        obj = ht_find(obj1->constants, hte->identifier.name);
                        if (obj == NULL) {
                            saffire_error("Cannot find constant or property '%s' from '%s'", hte->identifier.name, obj1->name);
                        }
                    }
                    RETURN_SNODE_OBJECT(obj);

                    break;

                case T_CONST :
                    if (current_obj == NULL) {
                        // @TODO: We could create constants OUTSIDE a class!
                        saffire_error("Defining constants outside classes is not yet supported!");
                    }

                    hte = p->opr.ops[0];
                    if (hte->type != typeAstIdentifier) {
                        saffire_error("Constant name needs to be an identifier");
                    }

                    node2 = SI1(p);
                    obj2 = si_get_object(node2);

                    DEBUG_PRINT("Added constant %s to %s\n", hte->identifier.name, current_obj->name);
                    ht_add(current_obj->constants, hte->identifier.name, obj2);
                    break;

                case T_PROPERTY :
                    if (current_obj == NULL) {
                        saffire_error("Cannot define properties outside classes. This should be caught by the parser!");
                    }

                    hte = p->opr.ops[0];
                    if (hte->type != typeAstNumerical) {
                        saffire_error("Flags name needs to be numerical");
                    }

                    hte = p->opr.ops[1];
                    if (hte->type != typeAstIdentifier) {
                        saffire_error("Property name needs to be an identifier");
                    }

                    node2 = SI2(p);
                    obj2 = si_get_object(node2);

                    DEBUG_PRINT("Added property %s to %s\n", hte->identifier.name, current_obj->name);
                    ht_add(current_obj->properties, hte->identifier.name, obj2);
                    break;

                default:
                    saffire_error("Unhandled opcode: %d\n", p->opr.oper);
                    break;
            }
            break;
    }
    RETURN_SNODE_NULL();
}
예제 #25
0
/* Init Flow Ring specific data structures */
int
dhd_flow_rings_init(dhd_pub_t *dhdp, uint32 num_flow_rings)
{
	uint32 idx;
	uint32 flow_ring_table_sz;
	uint32 if_flow_lkup_sz;
	void * flowid_allocator;
	flow_ring_table_t *flow_ring_table;
	if_flow_lkup_t *if_flow_lkup;

	DHD_INFO(("%s\n", __FUNCTION__));

	/* Construct a 16bit flow1d allocator */
	flowid_allocator = id16_map_init(dhdp->osh,
	                       num_flow_rings - FLOW_RING_COMMON, FLOWID_RESERVED);
	if (flowid_allocator == NULL) {
		DHD_ERROR(("%s: flowid allocator init failure\n", __FUNCTION__));
		return BCME_ERROR;
	}

	/* Allocate a flow ring table, comprising of requested number of rings */
	flow_ring_table_sz = (num_flow_rings * sizeof(flow_ring_node_t));
	flow_ring_table = (flow_ring_table_t *)MALLOC(dhdp->osh, flow_ring_table_sz);
	if (flow_ring_table == NULL) {
		DHD_ERROR(("%s: flow ring table alloc failure\n", __FUNCTION__));
		id16_map_fini(dhdp->osh, flowid_allocator);
		return BCME_ERROR;
	}

	/* Initialize flow ring table state */
	bzero((uchar *)flow_ring_table, flow_ring_table_sz);
	for (idx = 0; idx < num_flow_rings; idx++) {
		flow_ring_table[idx].status = FLOW_RING_STATUS_CLOSED;
		flow_ring_table[idx].flowid = (uint16)idx;
		dll_init(&flow_ring_table[idx].list);

		/* Initialize the per flow ring backup queue */
		dhd_flow_queue_init(dhdp, &flow_ring_table[idx].queue,
		                    FLOW_RING_QUEUE_THRESHOLD);
	}

	/* Allocate per interface hash table */
	if_flow_lkup_sz = sizeof(if_flow_lkup_t) * DHD_MAX_IFS;
	if_flow_lkup = (if_flow_lkup_t *)MALLOC(dhdp->osh, if_flow_lkup_sz);
	if (if_flow_lkup == NULL) {
		DHD_ERROR(("%s: if flow lkup alloc failure\n", __FUNCTION__));
		MFREE(dhdp->osh, flow_ring_table, flow_ring_table_sz);
		id16_map_fini(dhdp->osh, flowid_allocator);
		return BCME_ERROR;
	}

	/* Initialize per interface hash table */
	bzero((uchar *)if_flow_lkup, if_flow_lkup_sz);
	for (idx = 0; idx < DHD_MAX_IFS; idx++) {
		int hash_ix;
		if_flow_lkup[idx].status = 0;
		if_flow_lkup[idx].role = 0;
		for (hash_ix = 0; hash_ix < DHD_FLOWRING_HASH_SIZE; hash_ix++)
			if_flow_lkup[idx].fl_hash[hash_ix] = NULL;
	}

	/* Now populate into dhd pub */
	dhdp->num_flow_rings = num_flow_rings;
	dhdp->flowid_allocator = (void *)flowid_allocator;
	dhdp->flow_ring_table = (void *)flow_ring_table;
	dhdp->if_flow_lkup = (void *)if_flow_lkup;

	dhdp->flow_prio_map_type = DHD_FLOW_PRIO_AC_MAP;
	bcopy(prio2ac, dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO);

	DHD_INFO(("%s done\n", __FUNCTION__));
	return BCME_OK;
}
예제 #26
0
void nwl_init()
{
	dll_init();
	dll_set_tx_callback(&dll_tx_callback);
	dll_set_rx_callback(&dll_rx_callback);
}
예제 #27
0
CClientList::CClientList()
{
	m_clientIDCounter = 1;
	dll_init( &m_clientList, SORT_NUMERIC );	// Numeric => priotities are handled	 
}
예제 #28
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;
}
예제 #29
0
/* Init Flow Ring specific data structures */
int
dhd_flow_rings_init(dhd_pub_t *dhdp, uint32 num_flow_rings)
{
	uint32 idx;
	uint32 flow_ring_table_sz;
	uint32 if_flow_lkup_sz;
	void * flowid_allocator;
	flow_ring_table_t *flow_ring_table;
	if_flow_lkup_t *if_flow_lkup = NULL;
#ifdef PCIE_TX_DEFERRAL
	uint32 count;
#endif
	void *lock = NULL;
	unsigned long flags;

	DHD_INFO(("%s\n", __FUNCTION__));

	/* Construct a 16bit flow1d allocator */
	flowid_allocator = id16_map_init(dhdp->osh,
	                       num_flow_rings - FLOW_RING_COMMON, FLOWID_RESERVED);
	if (flowid_allocator == NULL) {
		DHD_ERROR(("%s: flowid allocator init failure\n", __FUNCTION__));
		return BCME_NOMEM;
	}

	/* Allocate a flow ring table, comprising of requested number of rings */
	flow_ring_table_sz = (num_flow_rings * sizeof(flow_ring_node_t));
	flow_ring_table = (flow_ring_table_t *)MALLOC(dhdp->osh, flow_ring_table_sz);
	if (flow_ring_table == NULL) {
		DHD_ERROR(("%s: flow ring table alloc failure\n", __FUNCTION__));
		goto fail;
	}

	/* Initialize flow ring table state */
	bzero((uchar *)flow_ring_table, flow_ring_table_sz);
	for (idx = 0; idx < num_flow_rings; idx++) {
		flow_ring_table[idx].status = FLOW_RING_STATUS_CLOSED;
		flow_ring_table[idx].flowid = (uint16)idx;
		flow_ring_table[idx].lock = dhd_os_spin_lock_init(dhdp->osh);
		if (flow_ring_table[idx].lock == NULL) {
			DHD_ERROR(("%s: Failed to init spinlock for queue!\n", __FUNCTION__));
			goto fail;
		}

		dll_init(&flow_ring_table[idx].list);

		/* Initialize the per flow ring backup queue */
		dhd_flow_queue_init(dhdp, &flow_ring_table[idx].queue,
		                    FLOW_RING_QUEUE_THRESHOLD);
	}

	/* Allocate per interface hash table */
	if_flow_lkup_sz = sizeof(if_flow_lkup_t) * DHD_MAX_IFS;
	if_flow_lkup = (if_flow_lkup_t *)DHD_OS_PREALLOC(dhdp,
		DHD_PREALLOC_IF_FLOW_LKUP, if_flow_lkup_sz);
	if (if_flow_lkup == NULL) {
		DHD_ERROR(("%s: if flow lkup alloc failure\n", __FUNCTION__));
		goto fail;
	}

	/* Initialize per interface hash table */
	bzero((uchar *)if_flow_lkup, if_flow_lkup_sz);
	for (idx = 0; idx < DHD_MAX_IFS; idx++) {
		int hash_ix;
		if_flow_lkup[idx].status = 0;
		if_flow_lkup[idx].role = 0;
		for (hash_ix = 0; hash_ix < DHD_FLOWRING_HASH_SIZE; hash_ix++)
			if_flow_lkup[idx].fl_hash[hash_ix] = NULL;
	}

#ifdef PCIE_TX_DEFERRAL
	count = BITS_TO_LONGS(num_flow_rings);
	dhdp->bus->delete_flow_map = kzalloc(count, GFP_ATOMIC);
	if  (!dhdp->bus->delete_flow_map) {
		DHD_ERROR(("%s: delete_flow_map alloc failure\n", __FUNCTION__));
		goto fail;
	}
#endif

	lock = dhd_os_spin_lock_init(dhdp->osh);
	if (lock == NULL)
		goto fail;

	dhdp->flow_prio_map_type = DHD_FLOW_PRIO_AC_MAP;
	bcopy(prio2ac, dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO);

	/* Now populate into dhd pub */
	DHD_FLOWID_LOCK(lock, flags);
	dhdp->num_flow_rings = num_flow_rings;
	dhdp->flowid_allocator = (void *)flowid_allocator;
	dhdp->flow_ring_table = (void *)flow_ring_table;
	dhdp->if_flow_lkup = (void *)if_flow_lkup;
	dhdp->flowid_lock = lock;
	DHD_FLOWID_UNLOCK(lock, flags);

	DHD_INFO(("%s done\n", __FUNCTION__));
	return BCME_OK;

fail:

#ifdef PCIE_TX_DEFERRAL
	if (dhdp->bus->delete_flow_map)
		kfree(dhdp->bus->delete_flow_map);
#endif
	/* Destruct the per interface flow lkup table */
	if (dhdp->if_flow_lkup != NULL) {
		DHD_OS_PREFREE(dhdp, if_flow_lkup, if_flow_lkup_sz);
	}
	if (flow_ring_table != NULL) {
		for (idx = 0; idx < num_flow_rings; idx++) {
			if (flow_ring_table[idx].lock != NULL)
				dhd_os_spin_lock_deinit(dhdp->osh, flow_ring_table[idx].lock);
		}
		MFREE(dhdp->osh, flow_ring_table, flow_ring_table_sz);
	}
	id16_map_fini(dhdp->osh, flowid_allocator);

	return BCME_NOMEM;
}
예제 #30
0
void wdbVioLibInit (void)
    {
    dll_init (&wdbVioDevList);

    wdbSvcAdd (WDB_VIO_WRITE, wdbVioWrite, xdr_WDB_MEM_XFER, xdr_UINT32);
    }