void *entityMgr_get(unsigned long long entityId) { void *v = NULL; EnterCriticalSection(&csEntityMgr); v = hashTable_get(&ht_entityTable, entityId); LeaveCriticalSection(&csEntityMgr); return v; }
// will always return a valid cell if within valid range conditions mapCell_t* cellMgr_getCell(mapChannel_t *mapChannel, int x, int z) { unsigned cellSeed = (x&0xFFFF) | (z<<16); mapCell_t *mapCell = (mapCell_t*)hashTable_get(&mapChannel->mapCellInfo.ht_cells, cellSeed); if( mapCell == NULL ) { // create cell mapCell = (mapCell_t*)malloc(sizeof(mapCell_t)); // init cell hashTable_init(&mapCell->ht_playerList, 8); hashTable_init(&mapCell->ht_playerNotifyList, 8); hashTable_init(&mapCell->ht_objectList, 8); hashTable_init(&mapCell->ht_npcList, 8); hashTable_init(&mapCell->ht_creatureList, 8); if( mapChannel->mapCellInfo.loadedCellCount == mapChannel->mapCellInfo.loadedCellLimit ) { // enlarge buffer int newLimit = mapChannel->mapCellInfo.loadedCellLimit * 2; mapCell_t **newLoadedCellList = (mapCell_t**)malloc(sizeof(mapCell_t*) * newLimit); for(int i=0; i<mapChannel->mapCellInfo.loadedCellLimit; i++) newLoadedCellList[i] = mapChannel->mapCellInfo.loadedCellList[i]; free(mapChannel->mapCellInfo.loadedCellList); mapChannel->mapCellInfo.loadedCellList = newLoadedCellList; mapChannel->mapCellInfo.loadedCellLimit = newLimit; if( newLoadedCellList == NULL ) { printf("ERROR in 'cellMgr_getCell'\n"); Sleep(1000*30); ExitThread(-1); } } // save cell mapChannel->mapCellInfo.loadedCellList[mapChannel->mapCellInfo.loadedCellCount] = mapCell; mapChannel->mapCellInfo.loadedCellCount++; // register cell hashTable_set(&mapChannel->mapCellInfo.ht_cells, cellSeed, mapCell); return mapCell; } return mapCell; }
void likwid_markerStartRegion(const char* regionTag) { if ( ! likwid_init ) { return; } bstring tag = bfromcstralloc(100, regionTag); LikwidThreadResults* results; uint64_t res; int cpu_id = hashTable_get(tag, &results); bdestroy(tag); int socket_fd = thread_socketFD[cpu_id]; if (accessClient_mode != DAEMON_AM_DIRECT) { if (socket_fd == -1) { printf("ERROR: Invalid socket file handle on processor %d. \ Did you call likwid_markerThreadInit() ?\n", cpu_id); } }
bool msgQueue_postMessage(sint32 destNameId, sint32 msgId, uint32 param1, uint32 param2, void* data) { if( destNameId == MSGQUEUE_ALL ) { // send to all } else { // send to specific //EnterCriticalSection(&messageQueueEnvironment.criticalSection); msgQueue_t *msgQueue = (msgQueue_t*)hashTable_get(&messageQueueEnvironment.ht_msgQueues, destNameId); if( msgQueue == NULL ) { if( data ) free(data); return false; } // allocate and setup message msgInfoLink_t *msg = (msgInfoLink_t*)malloc(sizeof(msgInfoLink_t)); if( msg == NULL ) return false; msg->msgInfo.msgId = msgId; msg->msgInfo.paramA = param1; msg->msgInfo.paramB = param2; msg->msgInfo.data = data; // append #ifdef _WIN32 EnterCriticalSection(&msgQueue->criticalSection); #else pthread_mutex_lock(&msgQueue->criticalSection); #endif if( msgQueue->last == NULL ) { if( msgQueue->first != NULL ) #ifdef _WIN32 __debugbreak(); //BUG! #else raise(SIGTRAP); #endif // new entry msg->next = NULL; msgQueue->first = msg; msgQueue->last = msg; } else { // append to last if( msgQueue->last->next ) #ifdef _WIN32 __debugbreak(); #else raise(SIGTRAP); #endif msg->next = NULL; msgQueue->last->next = msg; msgQueue->last = msg; } #ifdef _WIN32 LeaveCriticalSection(&msgQueue->criticalSection); #else pthread_mutex_unlock(&msgQueue->criticalSection); #endif } return true; }
// will return the cell only if it exists mapCell_t* cellMgr_tryGetCell(mapChannel_t *mapChannel, int x, int z) { unsigned cellSeed = (x&0xFFFF) | (z<<16); mapCell_t *mapCell = (mapCell_t*)hashTable_get(&mapChannel->mapCellInfo.ht_cells, cellSeed); return mapCell; }