int WinMonitorData::RegisterCondition( unsigned int cvid ) { int ret = -1; assert( hMutex != NULL ); // check if there is already a condition associated with the chosen id if( cvmap[cvid] == NULL ) { // there was no condition already associated with this condition var // build one ConditionVariable* newcv = new ConditionVariable( hMutex ); // initialize the condition variable if( newcv->Init() == 0 ) { cvmap[cvid] = newcv; ret = 0; } else { // failed to initialized - release the object delete newcv; } } return ret; }
void slab_init_post_thread() { new(&sMaintenanceQueue) MaintenanceQueue; sMaintenanceCondition.Init(&sMaintenanceQueue, "object cache maintainer"); thread_id objectCacheResizer = spawn_kernel_thread(object_cache_maintainer, "object cache resizer", B_URGENT_PRIORITY, NULL); if (objectCacheResizer < 0) { panic("slab_init_post_thread(): failed to spawn object cache resizer " "thread\n"); return; } resume_thread(objectCacheResizer); }
status_t low_resource_manager_init(void) { new(&sLowResourceHandlers) HandlerList; // static initializers do not work in the kernel, // so we have to do it here, manually sLowResourceWaiterCondition.Init(NULL, "low resource waiters"); // compute the free memory limits off_t totalMemory = (off_t)vm_page_num_pages() * B_PAGE_SIZE; sNoteMemoryLimit = totalMemory / 16; if (sNoteMemoryLimit < kMinNoteMemoryLimit) { sNoteMemoryLimit = kMinNoteMemoryLimit; sWarnMemoryLimit = kMinWarnMemoryLimit; sCriticalMemoryLimit = kMinCriticalMemoryLimit; } else { sWarnMemoryLimit = totalMemory / 64; sCriticalMemoryLimit = totalMemory / 256; } return B_OK; }
status_t port_init(kernel_args *args) { size_t size = sizeof(struct port_entry) * sMaxPorts; // create and initialize ports table virtual_address_restrictions virtualRestrictions = {}; virtualRestrictions.address_specification = B_ANY_KERNEL_ADDRESS; physical_address_restrictions physicalRestrictions = {}; sPortArea = create_area_etc(B_SYSTEM_TEAM, "port_table", size, B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, CREATE_AREA_DONT_WAIT, &virtualRestrictions, &physicalRestrictions, (void**)&sPorts); if (sPortArea < 0) { panic("unable to allocate kernel port table!\n"); return sPortArea; } memset(sPorts, 0, size); for (int32 i = 0; i < sMaxPorts; i++) { mutex_init(&sPorts[i].lock, NULL); sPorts[i].id = -1; sPorts[i].read_condition.Init(&sPorts[i], "port read"); sPorts[i].write_condition.Init(&sPorts[i], "port write"); } addr_t base; if (create_area("port heap", (void**)&base, B_ANY_KERNEL_ADDRESS, kInitialPortBufferSize, B_NO_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA) < 0) { // TODO: Since port_init() is invoked before the boot partition is // mounted, the underlying VMAnonymousCache cannot commit swap space // upon creation and thus the pages aren't swappable after all. This // makes the area essentially B_LAZY_LOCK with additional overhead. panic("unable to allocate port area!\n"); return B_ERROR; } static const heap_class kBufferHeapClass = {"default", 100, PORT_MAX_MESSAGE_SIZE + sizeof(port_message), 2 * 1024, sizeof(port_message), 8, 4, 64}; sPortAllocator = heap_create_allocator("port buffer", base, kInitialPortBufferSize, &kBufferHeapClass, true); if (sPortAllocator == NULL) { panic("unable to create port heap"); return B_NO_MEMORY; } sNoSpaceCondition.Init(sPorts, "port space"); // add debugger commands add_debugger_command_etc("ports", &dump_port_list, "Dump a list of all active ports (for team, with name, etc.)", "[ ([ \"team\" | \"owner\" ] <team>) | (\"name\" <name>) ]\n" "Prints a list of all active ports meeting the given\n" "requirement. If no argument is given, all ports are listed.\n" " <team> - The team owning the ports.\n" " <name> - Part of the name of the ports.\n", 0); add_debugger_command_etc("port", &dump_port_info, "Dump info about a particular port", "(<id> | [ \"address\" ] <address>) | ([ \"name\" ] <name>) " "| (\"condition\" <address>)\n" "Prints info about the specified port.\n" " <address> - Pointer to the port structure.\n" " <name> - Name of the port.\n" " <condition> - address of the port's read or write condition.\n", 0); new(&sNotificationService) PortNotificationService(); sPortsActive = true; return B_OK; }