void CDNSManager::threadFunc() { while (!isStop()) { if (m_pendingRecords.size() == 0) { getNextRecords(GetMainRecordCallback); } // // use libevent to do the dns lookup // s_pendingLookupCount = m_pendingRecords.size(); vector<DNS_RECORD_t*>::iterator it = m_pendingRecords.begin(); for (; it != m_pendingRecords.end(); ++it) { lookupDNS(**it); } if (s_pendingLookupCount == 0) { if (!addRecords()) // add the new records to database SleepMS(10); } else { event_base_dispatch(m_evbase); // wait until all the lookup are finished updateRecords(); } } }
// Listing 5 // Listing 3 code/ch17 int handle_parent (char *cmdLine) { ACE_TRACE (ACE_TEXT ("::handle_parent")); ALLOCATOR * shmem_allocator = 0; ACE_MMAP_Memory_Pool_Options options (ACE_DEFAULT_BASE_ADDR, ACE_MMAP_Memory_Pool_Options::ALWAYS_FIXED); ACE_NEW_RETURN (shmem_allocator, ALLOCATOR (BACKING_STORE, BACKING_STORE, &options), -1); MAP *map = smap (shmem_allocator); ACE_Process processa, processb; ACE_Process_Options poptions; poptions.command_line("%s a", cmdLine); { ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, coordMutex, -1); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Map has %d entries\n"), map->current_size ())); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("In parent, map is located at %@\n"), map)); // Then have the child show and eat them up. processa.spawn (poptions); // First append a few records. addRecords (map, shmem_allocator); } { ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, coordMutex, -1); // Add a few more records.. addRecords (map, shmem_allocator); // Let's see what's left. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Parent finished adding, ") ACE_TEXT ("map has %d entries\n"), map->current_size ())); // Have another child try to eat them up. processb.spawn (poptions); } processa.wait (); processb.wait (); // No processes are left and we don't want to keep the data // around anymore; it's now safe to remove it. // !!This will remove the backing store.!! shmem_allocator->remove (); delete shmem_allocator; return 0; }