/* SyncRegisterConnection */ PVRSRV_ERROR SyncRegisterConnection(SYNC_CONNECTION_DATA **ppsSyncConnectionData) { SYNC_CONNECTION_DATA *psSyncConnectionData; PVRSRV_ERROR eError; psSyncConnectionData = OSAllocMem(sizeof(SYNC_CONNECTION_DATA)); if (psSyncConnectionData == IMG_NULL) { eError = PVRSRV_ERROR_OUT_OF_MEMORY; goto fail_alloc; } eError = OSLockCreate(&psSyncConnectionData->hLock, LOCK_TYPE_PASSIVE); if (eError != PVRSRV_OK) { goto fail_lockcreate; } dllist_init(&psSyncConnectionData->sListHead); psSyncConnectionData->ui32RefCount = 1; *ppsSyncConnectionData = psSyncConnectionData; return PVRSRV_OK; fail_lockcreate: OSFreeMem(psSyncConnectionData); fail_alloc: PVR_ASSERT(eError != PVRSRV_OK); return eError; }
banlist_client_entry_t *banlist_client_add (banlist_client_t * list, unsigned char *client, double minVersion, double maxVersion, buffer_t * reason) { banlist_client_entry_t *b; /* delete any prior ban of this client */ banlist_client_del_byclient (list, client, minVersion, maxVersion); /* alloc and clear new element */ b = malloc (sizeof (banlist_client_entry_t)); /* init */ dllist_init (&b->dllist); strncpy (b->client, client, NICKLENGTH); b->client[NICKLENGTH - 1] = 0; b->minVersion = minVersion; b->maxVersion = maxVersion; if (reason) { b->message = bf_copy (reason, 1); } else b->message = bf_alloc (1); *b->message->e = 0; /* put in hashlist */ dlhashlist_prepend (list, SuperFastHash (client, strlen (client)) & BANLIST_NICK_HASHMASK, b); return b; }
static PVRSRV_ERROR SyncRecordListInit(IMG_VOID) { PVRSRV_ERROR eError; eError = OSLockCreate(&g_hSyncRecordListLock, LOCK_TYPE_NONE); if (eError != PVRSRV_OK) { goto fail_lock_create; } dllist_init(&g_sSyncRecordList); eError = PVRSRVRegisterDbgRequestNotify(&g_hSyncRecordNotify, _SyncRecordRequest, DEBUG_REQUEST_SERVERSYNC, IMG_NULL); if (eError != PVRSRV_OK) { goto fail_dbg_register; } return PVRSRV_OK; fail_dbg_register: OSLockDestroy(g_hSyncRecordListLock);; fail_lock_create: return eError; }
PVRSRV_ERROR ServerSyncInit(IMG_VOID) { PVRSRV_ERROR eError; eError = OSLockCreate(&g_hListLock, LOCK_TYPE_NONE); if (eError != PVRSRV_OK) { goto fail_lock_create; } dllist_init(&g_sAllServerSyncs); eError = PVRSRVRegisterDbgRequestNotify(&g_hNotify, _ServerSyncDebugRequest, DEBUG_REQUEST_SERVERSYNC, IMG_NULL); if (eError != PVRSRV_OK) { goto fail_dbg_register; } return PVRSRV_OK; fail_dbg_register: OSLockDestroy(g_hListLock);; fail_lock_create: return eError; }
int ptimer_init(ptimer_table_t *table, u16 allslots) { u16 vpower = 1; if(table == NULL) return -1; if(allslots > (1<<15)) /* 32768 */ vpower = (1<<15); else if(allslots < 64) vpower = 64; else { while(vpower < allslots) vpower = vpower << 1; } table->table = malloc(sizeof(dllist_node_t) * vpower); table->allslots = vpower; table->curslot = 0; if(table->table) { u32 i; for(i=0; i<table->allslots; i++) { dllist_init(&table->table[i]); } } return table->table?0:-1; }
banlist_entry_t *banlist_add (banlist_t * list, unsigned char *op, unsigned char *nick, uint32_t ip, uint32_t netmask, buffer_t * reason, unsigned long expire) { banlist_entry_t *b; uint32_t i; unsigned char n[NICKLENGTH]; unsigned int l; /* bad netmask */ i = netmask_to_numbits (netmask); if (i > 32) return NULL; l = nicktolower (n, nick); /* delete any earlier bans of this ip. */ if ((b = banlist_find_exact (list, nick, ip, netmask))) banlist_del (list, b); /* alloc and clear new element */ b = malloc (sizeof (banlist_entry_t)); /* init */ dllist_init (&b->list_ip); dllist_init (&b->list_name); strncpy (b->nick, nick, NICKLENGTH); b->nick[NICKLENGTH - 1] = 0; strncpy (b->op, op, NICKLENGTH); b->op[NICKLENGTH - 1] = 0; b->ip = ip & netmask; b->netmask = netmask; b->message = bf_copy (reason, 1); *b->message->e = 0; b->expire = expire; /* mask netmask as used */ list->netmask_inuse[i]++; /* put in hashlist */ dlhashlist_prepend (&list->list_ip, one_at_a_time (ip & netmask) & BANLIST_HASHMASK, (&b->list_ip)); dlhashlist_prepend (&list->list_name, SuperFastHash (n, l) & BANLIST_NICK_HASHMASK, (&b->list_name)); return b; }
void allocator_init(allocator_t *allocator, uint32_t block_size, uint32_t nr_blocks) { allocator->block_size = block_size; allocator->default_nr_blocks = nr_blocks; allocator->alloc_chunk = NULL; allocator->chunks_count = 0; dllist_init(&allocator->chunks); pthread_mutex_init(&allocator->lock, NULL); }
void simu_begin_event(void *timer, void* arg1, void* arg2) { /* FIXME: mac_free_pdu, mac_free_sdu */ /* 1. init the RLC entity (tx entity / rx entity) 2. set the sink function of the rx entity 3. generate the tx begin event at time 0? 4. put the packet tx begin event into the event timer queue */ simu_paras_t *pspt = (simu_paras_t*) arg1; assert((event_type_t)arg2 == SIMU_BEGIN); /* 1. */ /* @transmitter */ rlc_um_init(&(pspt->rlc_tx.um_tx), pspt->rlc_paras.ump.sn_FieldLength, \ pspt->rlc_paras.ump.UM_Window_Size, \ pspt->rlc_paras.ump.t_Reordering, \ mac_free_pdu, mac_free_sdu); /* @receiver in @free_sdu should be set to NULL, as we re-use the rlc sdu buffer through the entire simulation. */ rlc_um_init(&(pspt->rlc_rx.um_rx), pspt->rlc_paras.ump.sn_FieldLength, \ pspt->rlc_paras.ump.UM_Window_Size, \ pspt->rlc_paras.ump.t_Reordering, \ mac_free_pdu, NULL); /* 2. */ rlc_um_set_deliv_func(&pspt->rlc_rx.um_rx, sink); /* 3. */ ptimer_t *pkt_tx_begin = (ptimer_t*)FASTALLOC(pspt->g_mem_ptimer_t); assert(pkt_tx_begin); pkt_tx_begin->duration = 0; pkt_tx_begin->onexpired_func = pkt_tx_begin_event; pkt_tx_begin->param[0] = (void*) pspt; pkt_tx_begin->param[1] = (void*) PKT_TX_BEGIN; /* 4. */ rlc_timer_start(pkt_tx_begin); dllist_init(&g_sink_packet_list); }
PVRSRV_ERROR ServerSyncInit(IMG_VOID) { PVRSRV_ERROR eError; eError = OSLockCreate(&g_hListLock, LOCK_TYPE_NONE); if (eError != PVRSRV_OK) { goto fail_lock_create; } dllist_init(&g_sAllServerSyncs); eError = PVRSRVRegisterDbgRequestNotify(&g_hNotify, _ServerSyncDebugRequest, DEBUG_REQUEST_SERVERSYNC, IMG_NULL); if (eError != PVRSRV_OK) { goto fail_dbg_register; } #if defined(PVRSRV_ENABLE_FULL_SYNC_TRACKING) eError = SyncRecordListInit(); if (eError != PVRSRV_OK) { goto fail_record_list; } #endif return PVRSRV_OK; #if defined(PVRSRV_ENABLE_FULL_SYNC_TRACKING) fail_record_list: PVRSRVUnregisterDbgRequestNotify(g_hNotify); #endif fail_dbg_register: OSLockDestroy(g_hListLock);; fail_lock_create: return eError; }
uint32_t allocator_shrink(allocator_t *allocator) { uint32_t count = 0; dllist rem_list; dllist_init(&rem_list); pthread_mutex_lock(&allocator->lock); dllist_link *l = allocator->chunks.head; for (; l ;) { chunk_t *tmp = DLLIST_ELEMENT(l, chunk_t, link); dllist_link *nl = l->next; if (chunk_get_count(tmp) == tmp->nr_blocks) { allocator->chunks_count--; dllist_rem(&allocator->chunks, l); if (allocator->alloc_chunk == l) { allocator->alloc_chunk = allocator->chunks.head; } dllist_iat(&rem_list, l); count += tmp->nr_blocks; } l = nl; } pthread_mutex_unlock(&allocator->lock); while (!dllist_is_empty(&rem_list)) { dllist_link *head = dllist_rem_head(&rem_list); chunk_t *tmp = DLLIST_ELEMENT(head, chunk_t, link); chunk_destroy(tmp); free(tmp); } return count; }
// Allocate a new doubly linked list. dllist* dllist_new(){ dllist* this = (dllist*)malloc(sizeof(dllist)); // Extra construction stuff.... dllist_init(this); return this; }
/* @arg1 in pointer to the simu_paras_t struct @arg2 in event type ( = PKT_TX_BEGIN) */ void pkt_tx_begin_event(void *timer, void* arg1, void* arg2) { /* 1. get a @packet from the RLC UM entity TX 2. set this @packet's tx_begin_timestamp = current simu time 3. generate the packet tx end event for this packet 4. put this packet tx end event to the timer queue */ u8 *mac_pdu, *buffer, *new_mac_pdu; u32 mac_pdu_size; simu_paras_t *pspt = (simu_paras_t*) arg1; assert((event_type_t)arg2 == PKT_TX_BEGIN); /* 1. */ /* 2. */ /* the sdu_ptr is freed within the rlc_encode_sdu() */ u8* sdu_ptr = rlc_create_sdu(pspt->t.packet_size); rlc_um_tx_sdu_enqueue(&(pspt->rlc_tx.um_tx.umtx), sdu_ptr, pspt->t.packet_size, NULL); /* call the mac_build_pdu variant */ if( mac_build_pdu(&(pspt->rlc_tx.um_tx), &mac_pdu, &mac_pdu_size, &buffer) == 0 ) { ZLOG_ERR("failed to build MAC PDU\n"); return; } /* debug, dump the mac pdu */ ZLOG_DEBUG("Rx PDU length=%u.\n", mac_pdu_size); // macrlc_dump_buffer(mac_pdu, mac_pdu_size); new_mac_pdu = malloc(mac_pdu_size); assert(new_mac_pdu); memcpy(new_mac_pdu, mac_pdu, mac_pdu_size); free(buffer); /* 3. & 4. */ ptimer_t *pkt_tx_end = (ptimer_t*)FASTALLOC(pspt->g_mem_ptimer_t); assert(pkt_tx_end); /* cal tx delay */ pspt->tx_delay = (1e3 * OCTET * (mac_pdu_size + PHY_HEADER_SIZE)) / pspt->rl.link_bandwidth; ZLOG_DEBUG("tx delay = %d\n", pspt->tx_delay); pkt_tx_end->duration = pspt->tx_delay; /* tx delay */ pkt_tx_end->onexpired_func = pkt_tx_end_event; pkt_tx_end->param[0] = (void*) pspt; /* associate this mac pdu (rlc pdu) with the simulation packet info */ // packet_t *pktt = (packet_t*)FASTALLOC(pspt->g_mem_packet_t); packet_t *pktt = (packet_t*) malloc(sizeof(packet_t)); assert(pktt); dllist_init(&(pktt->node)); pktt->sequence_no = pspt->rlc_tx.um_tx.umtx.VT_US; pktt->mac_pdu = new_mac_pdu; pktt->mac_pdu_size = mac_pdu_size; pktt->ptt = ONGOING; pktt->packet_size = pspt->t.packet_size; pktt->tx_begin_timestamp = g_time_elasped_in_us; pktt->tx_end_timestamp = 0; /* not valid, in us */ pktt->rx_deliver_timestamp = 0; /* not valid, in us */ pktt->jitter = 0; /* not valid, in us */ pkt_tx_end->param[1] = (void*) pktt; rlc_timer_start(pkt_tx_end); /* ZLOG_DEBUG("going to be finished!\n"); g_is_finished = FINISHED; */ FASTFREE(pspt->g_mem_ptimer_t, timer); }