static void test_thread_idle_time () { guint limit = 50; guint interval = 10000; gint i; idle_pool = g_thread_pool_new (test_thread_idle_time_entry_func, NULL, MAX_THREADS, FALSE, NULL); g_thread_pool_set_max_unused_threads (MAX_UNUSED_THREADS); g_thread_pool_set_max_idle_time (interval); g_assert (g_thread_pool_get_max_unused_threads () == MAX_UNUSED_THREADS); g_assert (g_thread_pool_get_max_idle_time () == interval); for (i = 0; i < limit; i++) { g_thread_pool_push (idle_pool, GUINT_TO_POINTER (i + 1), NULL); DEBUG_MSG (("[idle] ===> pushed new thread with id:%d, " "number of threads:%d, unprocessed:%d", i, g_thread_pool_get_num_threads (idle_pool), g_thread_pool_unprocessed (idle_pool))); } g_timeout_add ((interval - 1000), test_thread_idle_timeout, GUINT_TO_POINTER (interval)); }
static gboolean test_thread_idle_timeout (gpointer data) { guint interval; gint i; interval = GPOINTER_TO_UINT (data); for (i = 0; i < 2; i++) { g_thread_pool_push (idle_pool, GUINT_TO_POINTER (100 + i), NULL); DEBUG_MSG (("[idle] ===> pushed new thread with id:%d, number " "of threads:%d, unprocessed:%d", 100 + i, g_thread_pool_get_num_threads (idle_pool), g_thread_pool_unprocessed (idle_pool))); } return FALSE; }
/** * Preloads a given LOD map node and unloads its children if they were previously preloaded * * @param lodmap the LOD map for which to preload nodes * @param node the quadtree node which we should preload */ static void preloadLodMapNode(OpenGLLodMap *lodmap, QuadtreeNode *node) { OpenGLLodMapTile *tile = node->data; QuadtreeAABB box = quadtreeNodeAABB(node); switch(tile->status) { case OPENGL_LODMAP_TILE_ACTIVE: deactivateLodMapTile(tile); break; case OPENGL_LODMAP_TILE_INACTIVE: case OPENGL_LODMAP_TILE_META: logInfo("Preloading LOD node covering [%d,%d]x[%d,%d] (LOD level %d) - %d threads active", box.minX, box.maxX, box.minY, box.maxY, node->level, g_thread_pool_get_num_threads(lodmap->loadingPool)); tile->status = OPENGL_LODMAP_TILE_LOADING; g_thread_pool_push(lodmap->loadingPool, node, NULL); break; default: // nothing to do break; } if(!quadtreeNodeIsLeaf(node)) { // if this node has children, we can unload their data for(unsigned int i = 0; i < 4; i++) { QuadtreeNode *child = node->children[i]; OpenGLLodMapTile *childTile = child->data; QuadtreeAABB childBox = quadtreeNodeAABB(child); switch(childTile->status) { case OPENGL_LODMAP_TILE_ACTIVE: logInfo("Unloading LOD node covering [%d,%d]x[%d,%d] (LOD level %d)", childBox.minX, childBox.maxX, childBox.minY, childBox.maxY, child->level); deactivateLodMapTile(childTile); unloadLodMapTile(childTile); break; case OPENGL_LODMAP_TILE_READY: logInfo("Unloading LOD node covering [%d,%d]x[%d,%d] (LOD level %d)", childBox.minX, childBox.maxX, childBox.minY, childBox.maxY, child->level); unloadLodMapTile(childTile); break; default: // nothing to do break; } } } }