bool mutex_lock(mutex_t* mutex) { #if !BUILD_DEPLOY profile_trylock(mutex->name.str, mutex->name.length); #endif #if FOUNDATION_PLATFORM_WINDOWS EnterCriticalSection((CRITICAL_SECTION*)mutex->csection); #elif FOUNDATION_PLATFORM_POSIX || FOUNDATION_PLATFORM_PNACL if (pthread_mutex_lock(&mutex->mutex) != 0) { FOUNDATION_ASSERT_FAILFORMAT("unable to lock mutex %s", mutex->name.str); return false; } #else # error mutex_lock not implemented #endif #if !BUILD_DEPLOY profile_lock(mutex->name.str, mutex->name.length); #endif FOUNDATION_ASSERT_MSGFORMAT(!mutex->lockcount || (thread_id() == mutex->lockedthread), "Mutex lock acquired with lockcount > 0 (%d) and locked thread not self (%" PRIx64 " != %" PRIx64 ")", mutex->lockcount, mutex->lockedthread, thread_id()); if (!mutex->lockcount) mutex->lockedthread = thread_id(); ++mutex->lockcount; return true; }
objectmap_t* objectmap_allocate( unsigned int size ) { uint64_t bits; unsigned int ip; uintptr_t next_indexshift; objectmap_t* map; void** slot; FOUNDATION_ASSERT_MSG( size > 2, "Invalid objectmap size" ); if( size <= 2 ) size = 2; bits = math_round( math_log2( (real)size ) ); //Number of bits needed FOUNDATION_ASSERT_MSGFORMAT( bits < 50, "Invalid objectmap size %d", size ); //Top two bits unused for Lua compatibility map = memory_allocate_zero( sizeof( objectmap_t ) + ( sizeof( void* ) * size ), 16, MEMORY_PERSISTENT ); map->size_bits = bits; map->id_max = ((1ULL<<(62ULL-bits))-1); map->size = size; map->mask_index = ((1ULL<<bits)-1ULL); map->mask_id = ( 0x3FFFFFFFFFFFFFFFULL & ~map->mask_index ); atomic_store64( &map->free, 0 ); atomic_store64( &map->id, 1 ); slot = map->map; for( ip = 0, next_indexshift = 3; ip < ( size - 1 ); ++ip, next_indexshift += 2, ++slot ) *slot = (void*)next_indexshift; *slot = (void*)((uintptr_t)-1); return map; }
size_t render_vertex_decl_calculate_size(const render_vertex_decl_t* decl) { size_t size = 0; for (unsigned int i = 0; i < decl->num_attributes; ++i) { FOUNDATION_ASSERT_MSGFORMAT(decl->attribute[i].format <= VERTEXFORMAT_UNKNOWN, "Invalid vertex format type %d index %d", decl->attribute[i].format, i); size_t end = decl->attribute[i].offset + _vertex_format_size[ decl->attribute[i].format ]; if (end > size) size = end; } return size; }