• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ BLI_mutex_lock函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中BLI_mutex_lock函数的典型用法代码示例。如果您正苦于以下问题:C++ BLI_mutex_lock函数的具体用法?C++ BLI_mutex_lock怎么用?C++ BLI_mutex_lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了BLI_mutex_lock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: BLI_task_pool_work_and_wait

void BLI_task_pool_work_and_wait(TaskPool *pool)
{
	TaskScheduler *scheduler = pool->scheduler;

	BLI_mutex_lock(&pool->num_mutex);

	while (pool->num != 0) {
		Task *task, *work_task = NULL;
		bool found_task = false;

		BLI_mutex_unlock(&pool->num_mutex);

		BLI_mutex_lock(&scheduler->queue_mutex);

		/* find task from this pool. if we get a task from another pool,
		 * we can get into deadlock */

		if (pool->num_threads == 0 ||
		    pool->currently_running_tasks < pool->num_threads)
		{
			for (task = scheduler->queue.first; task; task = task->next) {
				if (task->pool == pool) {
					work_task = task;
					found_task = true;
					BLI_remlink(&scheduler->queue, task);
					break;
				}
			}
		}

		BLI_mutex_unlock(&scheduler->queue_mutex);

		/* if found task, do it, otherwise wait until other tasks are done */
		if (found_task) {
			/* run task */
			atomic_add_z(&pool->currently_running_tasks, 1);
			work_task->run(pool, work_task->taskdata, 0);

			/* delete task */
			if (work_task->free_taskdata)
				MEM_freeN(work_task->taskdata);
			MEM_freeN(work_task);

			/* notify pool task was done */
			task_pool_num_decrease(pool, 1);
		}

		BLI_mutex_lock(&pool->num_mutex);
		if (pool->num == 0)
			break;

		if (!found_task)
			BLI_condition_wait(&pool->num_cond, &pool->num_mutex);
	}

	BLI_mutex_unlock(&pool->num_mutex);
}
开发者ID:flair2005,项目名称:mechanical-blender,代码行数:57,代码来源:task.c


示例2: preview_startjob

/* only this runs inside thread */
static void preview_startjob(void *data, short *stop, short *do_update, float *progress)
{
	PreviewJob *pj = data;
	PreviewJobAudio *previewjb;

	BLI_mutex_lock(pj->mutex);
	previewjb = pj->previews.first;
	BLI_mutex_unlock(pj->mutex);

	while (previewjb) {
		PreviewJobAudio *preview_next;
		bSound *sound = previewjb->sound;

		BKE_sound_read_waveform(sound, stop);

		if (*stop || G.is_break) {
			BLI_mutex_lock(pj->mutex);
			previewjb = previewjb->next;
			BLI_mutex_unlock(pj->mutex);
			while (previewjb) {
				sound = previewjb->sound;

				/* make sure we cleanup the loading flag! */
				BLI_spin_lock(sound->spinlock);
				sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING;
				BLI_spin_unlock(sound->spinlock);

				BLI_mutex_lock(pj->mutex);
				previewjb = previewjb->next;
				BLI_mutex_unlock(pj->mutex);
			}

			BLI_mutex_lock(pj->mutex);
			BLI_freelistN(&pj->previews);
			pj->total = 0;
			pj->processed = 0;
			BLI_mutex_unlock(pj->mutex);
			break;
		}

		BLI_mutex_lock(pj->mutex);
		preview_next = previewjb->next;
		BLI_freelinkN(&pj->previews, previewjb);
		previewjb = preview_next;
		pj->processed++;
		*progress = (pj->total > 0) ? (float)pj->processed / (float)pj->total : 1.0f;
		*do_update = true;
		BLI_mutex_unlock(pj->mutex);
	}
}
开发者ID:Ichthyostega,项目名称:blender,代码行数:51,代码来源:sequencer_preview.c


示例3: BLI_mutex_lock

void KX_BlenderSceneConverter::MergeAsyncLoads()
{
	vector<KX_Scene *> *merge_scenes;

	vector<KX_LibLoadStatus *>::iterator mit;
	vector<KX_Scene *>::iterator sit;

	BLI_mutex_lock(&m_threadinfo->m_mutex);

	for (mit = m_mergequeue.begin(); mit != m_mergequeue.end(); ++mit) {
		merge_scenes = (vector<KX_Scene *> *)(*mit)->GetData();

		for (sit=merge_scenes->begin(); sit!=merge_scenes->end(); ++sit) {
			(*mit)->GetMergeScene()->MergeScene(*sit);
			delete (*sit);
		}

		delete merge_scenes;
		(*mit)->SetData(NULL);

		(*mit)->Finish();
	}

	m_mergequeue.clear();

	BLI_mutex_unlock(&m_threadinfo->m_mutex);
}
开发者ID:sadmansk,项目名称:blender,代码行数:27,代码来源:KX_BlenderSceneConverter.cpp


示例4: task_scheduler_clear

static void task_scheduler_clear(TaskScheduler *scheduler, TaskPool *pool)
{
	Task *task, *nexttask;
	size_t done = 0;

	BLI_mutex_lock(&scheduler->queue_mutex);

	/* free all tasks from this pool from the queue */
	for (task = scheduler->queue.first; task; task = nexttask) {
		nexttask = task->next;

		if (task->pool == pool) {
			if (task->free_taskdata)
				MEM_freeN(task->taskdata);
			BLI_freelinkN(&scheduler->queue, task);

			done++;
		}
	}

	BLI_mutex_unlock(&scheduler->queue_mutex);

	/* notify done */
	task_pool_num_decrease(pool, done);
}
开发者ID:flair2005,项目名称:mechanical-blender,代码行数:25,代码来源:task.c


示例5: COM_execute

void COM_execute(RenderData *rd, Scene *scene, bNodeTree *editingtree, int rendering,
                 const ColorManagedViewSettings *viewSettings,
                 const ColorManagedDisplaySettings *displaySettings,
                 const char *viewName)
{
	/* initialize mutex, TODO this mutex init is actually not thread safe and
	 * should be done somewhere as part of blender startup, all the other
	 * initializations can be done lazily */
	if (is_compositorMutex_init == false) {
		BLI_mutex_init(&s_compositorMutex);
		is_compositorMutex_init = true;
	}

	BLI_mutex_lock(&s_compositorMutex);

	if (editingtree->test_break(editingtree->tbh)) {
		// during editing multiple calls to this method can be triggered.
		// make sure one the last one will be doing the work.
		BLI_mutex_unlock(&s_compositorMutex);
		return;
	}

	/* Make sure node tree has previews.
	 * Don't create previews in advance, this is done when adding preview operations.
	 * Reserved preview size is determined by render output for now.
	 */
	float aspect = rd->xsch > 0 ? (float)rd->ysch / (float)rd->xsch : 1.0f;
	BKE_node_preview_init_tree(editingtree, COM_PREVIEW_SIZE, (int)(COM_PREVIEW_SIZE * aspect), false);

	/* initialize workscheduler, will check if already done. TODO deinitialize somewhere */
	bool use_opencl = (editingtree->flag & NTREE_COM_OPENCL) != 0;
	WorkScheduler::initialize(use_opencl, BKE_render_num_threads(rd));

	/* set progress bar to 0% and status to init compositing */
	editingtree->progress(editingtree->prh, 0.0);
	editingtree->stats_draw(editingtree->sdh, IFACE_("Compositing"));

	bool twopass = (editingtree->flag & NTREE_TWO_PASS) > 0 && !rendering;
	/* initialize execution system */
	if (twopass) {
		ExecutionSystem *system = new ExecutionSystem(rd, scene, editingtree, rendering, twopass, viewSettings, displaySettings, viewName);
		system->execute();
		delete system;
		
		if (editingtree->test_break(editingtree->tbh)) {
			// during editing multiple calls to this method can be triggered.
			// make sure one the last one will be doing the work.
			BLI_mutex_unlock(&s_compositorMutex);
			return;
		}
	}

	ExecutionSystem *system = new ExecutionSystem(rd, scene, editingtree, rendering, false,
	                                              viewSettings, displaySettings, viewName);
	system->execute();
	delete system;

	BLI_mutex_unlock(&s_compositorMutex);
}
开发者ID:DarkDefender,项目名称:blender-npr-tess2,代码行数:59,代码来源:COM_compositor.cpp


示例6: UNUSED_FUNCTION

static void UNUSED_FUNCTION(COM_freeCaches)()
{
	if (is_compositorMutex_init) {
		BLI_mutex_lock(&s_compositorMutex);
		intern_freeCompositorCaches();
		BLI_mutex_unlock(&s_compositorMutex);
	}
}
开发者ID:tweakoz,项目名称:blender_toz,代码行数:8,代码来源:COM_compositor.cpp


示例7: task_pool_num_increase

static void task_pool_num_increase(TaskPool *pool)
{
	BLI_mutex_lock(&pool->num_mutex);

	pool->num++;
	BLI_condition_notify_all(&pool->num_cond);

	BLI_mutex_unlock(&pool->num_mutex);
}
开发者ID:LucaRood,项目名称:Blender,代码行数:9,代码来源:task.c


示例8: task_scheduler_thread_wait_pop

static bool task_scheduler_thread_wait_pop(TaskScheduler *scheduler, Task **task)
{
	bool found_task = false;
	BLI_mutex_lock(&scheduler->queue_mutex);

	while (!scheduler->queue.first && !scheduler->do_exit)
		BLI_condition_wait(&scheduler->queue_cond, &scheduler->queue_mutex);

	do {
		Task *current_task;

		/* Assuming we can only have a void queue in 'exit' case here seems logical (we should only be here after
		 * our worker thread has been woken up from a condition_wait(), which only happens after a new task was
		 * added to the queue), but it is wrong.
		 * Waiting on condition may wake up the thread even if condition is not signaled (spurious wake-ups), and some
		 * race condition may also empty the queue **after** condition has been signaled, but **before** awoken thread
		 * reaches this point...
		 * See http://stackoverflow.com/questions/8594591
		 *
		 * So we only abort here if do_exit is set.
		 */
		if (scheduler->do_exit) {
			BLI_mutex_unlock(&scheduler->queue_mutex);
			return false;
		}

		for (current_task = scheduler->queue.first;
		     current_task != NULL;
		     current_task = current_task->next)
		{
			TaskPool *pool = current_task->pool;

			if (scheduler->background_thread_only && !pool->run_in_background) {
				continue;
			}

			if (atomic_add_and_fetch_z(&pool->currently_running_tasks, 1) <= pool->num_threads ||
			    pool->num_threads == 0)
			{
				*task = current_task;
				found_task = true;
				BLI_remlink(&scheduler->queue, *task);
				break;
			}
			else {
				atomic_sub_and_fetch_z(&pool->currently_running_tasks, 1);
			}
		}
		if (!found_task)
			BLI_condition_wait(&scheduler->queue_cond, &scheduler->queue_mutex);
	} while (!found_task);

	BLI_mutex_unlock(&scheduler->queue_mutex);

	return true;
}
开发者ID:UPBGE,项目名称:blender,代码行数:56,代码来源:task.c


示例9: COM_deinitialize

void COM_deinitialize()
{
	if (is_compositorMutex_init) {
		BLI_mutex_lock(&s_compositorMutex);
		WorkScheduler::deinitialize();
		is_compositorMutex_init = false;
		BLI_mutex_unlock(&s_compositorMutex);
		BLI_mutex_end(&s_compositorMutex);
	}
}
开发者ID:DarkDefender,项目名称:blender-npr-tess2,代码行数:10,代码来源:COM_compositor.cpp


示例10: COM_deinitialize

void COM_deinitialize()
{
	if (is_compositorMutex_init) {
		BLI_mutex_lock(&s_compositorMutex);
		intern_freeCompositorCaches();
		WorkScheduler::deinitialize();
		is_compositorMutex_init = FALSE;
		BLI_mutex_unlock(&s_compositorMutex);
		BLI_mutex_end(&s_compositorMutex);
	}
}
开发者ID:tweakoz,项目名称:blender_toz,代码行数:11,代码来源:COM_compositor.cpp


示例11: eevee_lightbake_delete_resources

static void eevee_lightbake_delete_resources(EEVEE_LightBake *lbake)
{
  if (!lbake->resource_only) {
    BLI_mutex_lock(lbake->mutex);
  }

  if (lbake->gl_context) {
    DRW_opengl_render_context_enable(lbake->gl_context);
    DRW_gawain_render_context_enable(lbake->gpu_context);
  }
  else if (!lbake->resource_only) {
    DRW_opengl_context_enable();
  }

  /* XXX Free the resources contained in the viewlayer data
   * to be able to free the context before deleting the depsgraph.  */
  if (lbake->sldata) {
    EEVEE_view_layer_data_free(lbake->sldata);
  }

  DRW_TEXTURE_FREE_SAFE(lbake->rt_depth);
  DRW_TEXTURE_FREE_SAFE(lbake->rt_color);
  DRW_TEXTURE_FREE_SAFE(lbake->grid_prev);
  GPU_FRAMEBUFFER_FREE_SAFE(lbake->store_fb);
  for (int i = 0; i < 6; ++i) {
    GPU_FRAMEBUFFER_FREE_SAFE(lbake->rt_fb[i]);
  }

  if (lbake->gpu_context) {
    DRW_gawain_render_context_disable(lbake->gpu_context);
    DRW_gawain_render_context_enable(lbake->gpu_context);
    GPU_context_discard(lbake->gpu_context);
  }

  if (lbake->gl_context && lbake->own_resources) {
    /* Delete the baking context. */
    DRW_opengl_render_context_disable(lbake->gl_context);
    WM_opengl_context_dispose(lbake->gl_context);
    lbake->gpu_context = NULL;
    lbake->gl_context = NULL;
  }
  else if (lbake->gl_context) {
    DRW_opengl_render_context_disable(lbake->gl_context);
  }
  else if (!lbake->resource_only) {
    DRW_opengl_context_disable();
  }

  if (!lbake->resource_only) {
    BLI_mutex_unlock(lbake->mutex);
  }
}
开发者ID:wangyxuan,项目名称:blender,代码行数:52,代码来源:eevee_lightcache.c


示例12: task_pool_num_decrease

static void task_pool_num_decrease(TaskPool *pool, size_t done)
{
	BLI_mutex_lock(&pool->num_mutex);

	BLI_assert(pool->num >= done);

	pool->num -= done;

	if (pool->num == 0)
		BLI_condition_notify_all(&pool->num_cond);

	BLI_mutex_unlock(&pool->num_mutex);
}
开发者ID:mgschwan,项目名称:blensor,代码行数:13,代码来源:task.c


示例13: BLI_task_pool_cancel

void BLI_task_pool_cancel(TaskPool *pool)
{
	pool->do_cancel = true;

	task_scheduler_clear(pool->scheduler, pool);

	/* wait until all entries are cleared */
	BLI_mutex_lock(&pool->num_mutex);
	while (pool->num)
		BLI_condition_wait(&pool->num_cond, &pool->num_mutex);
	BLI_mutex_unlock(&pool->num_mutex);

	pool->do_cancel = false;
}
开发者ID:LucaRood,项目名称:Blender,代码行数:14,代码来源:task.c


示例14: BLI_task_scheduler_free

void BLI_task_scheduler_free(TaskScheduler *scheduler)
{
	Task *task;

	/* stop all waiting threads */
	BLI_mutex_lock(&scheduler->queue_mutex);
	scheduler->do_exit = true;
	BLI_condition_notify_all(&scheduler->queue_cond);
	BLI_mutex_unlock(&scheduler->queue_mutex);

	/* delete threads */
	if (scheduler->threads) {
		int i;

		for (i = 0; i < scheduler->num_threads; i++) {
			if (pthread_join(scheduler->threads[i], NULL) != 0)
				fprintf(stderr, "TaskScheduler failed to join thread %d/%d\n", i, scheduler->num_threads);
		}

		MEM_freeN(scheduler->threads);
	}

	/* Delete task thread data */
	if (scheduler->task_threads) {
		MEM_freeN(scheduler->task_threads);
	}

	/* Delete task memory pool */
	if (scheduler->task_mempool) {
		for (int i = 0; i <= scheduler->num_threads; ++i) {
			for (int j = 0; j < scheduler->task_mempool[i].num_tasks; ++j) {
				MEM_freeN(scheduler->task_mempool[i].tasks[j]);
			}
		}
		MEM_freeN(scheduler->task_mempool);
	}

	/* delete leftover tasks */
	for (task = scheduler->queue.first; task; task = task->next) {
		task_data_free(task, 0);
	}
	BLI_freelistN(&scheduler->queue);

	/* delete mutex/condition */
	BLI_mutex_end(&scheduler->queue_mutex);
	BLI_condition_end(&scheduler->queue_cond);

	MEM_freeN(scheduler);
}
开发者ID:LucaRood,项目名称:Blender,代码行数:49,代码来源:task.c


示例15: BKE_collection_object_cache_get

ListBase BKE_collection_object_cache_get(Collection *collection)
{
  if (!(collection->flag & COLLECTION_HAS_OBJECT_CACHE)) {
    static ThreadMutex cache_lock = BLI_MUTEX_INITIALIZER;

    BLI_mutex_lock(&cache_lock);
    if (!(collection->flag & COLLECTION_HAS_OBJECT_CACHE)) {
      collection_object_cache_fill(&collection->object_cache, collection, 0);
      collection->flag |= COLLECTION_HAS_OBJECT_CACHE;
    }
    BLI_mutex_unlock(&cache_lock);
  }

  return collection->object_cache;
}
开发者ID:wangyxuan,项目名称:blender,代码行数:15,代码来源:collection.c


示例16: task_pool_num_decrease

static void task_pool_num_decrease(TaskPool *pool, size_t done)
{
	BLI_mutex_lock(&pool->num_mutex);

	BLI_assert(pool->num >= done);

	pool->num -= done;
	atomic_sub_z(&pool->currently_running_tasks, done);
	pool->done += done;

	if (pool->num == 0)
		BLI_condition_notify_all(&pool->num_cond);

	BLI_mutex_unlock(&pool->num_mutex);
}
开发者ID:LucaRood,项目名称:Blender,代码行数:15,代码来源:task.c


示例17: task_scheduler_push

static void task_scheduler_push(TaskScheduler *scheduler, Task *task, TaskPriority priority)
{
	task_pool_num_increase(task->pool);

	/* add task to queue */
	BLI_mutex_lock(&scheduler->queue_mutex);

	if (priority == TASK_PRIORITY_HIGH)
		BLI_addhead(&scheduler->queue, task);
	else
		BLI_addtail(&scheduler->queue, task);

	BLI_condition_notify_one(&scheduler->queue_cond);
	BLI_mutex_unlock(&scheduler->queue_mutex);
}
开发者ID:LucaRood,项目名称:Blender,代码行数:15,代码来源:task.c


示例18: IMB_tiles_to_rect

void IMB_tiles_to_rect(ImBuf *ibuf)
{
	ImBuf *mipbuf;
	ImGlobalTile *gtile;
	unsigned int *to, *from;
	int a, tx, ty, y, w, h;

	for(a=0; a<ibuf->miptot; a++) {
		mipbuf= IMB_getmipmap(ibuf, a);

		/* don't call imb_addrectImBuf, it frees all mipmaps */
		if(!mipbuf->rect) {
			if((mipbuf->rect = MEM_mapallocN(ibuf->x*ibuf->y*sizeof(unsigned int), "imb_addrectImBuf"))) {
				mipbuf->mall |= IB_rect;
				mipbuf->flags |= IB_rect;
			}
			else
				break;
		}

		for(ty=0; ty<mipbuf->ytiles; ty++) {
			for(tx=0; tx<mipbuf->xtiles; tx++) {
				/* acquire tile through cache, this assumes cache is initialized,
				   which it is always now but it's a weak assumption ... */
				gtile= imb_global_cache_get_tile(mipbuf, tx, ty, NULL);

				/* setup pointers */
				from= mipbuf->tiles[mipbuf->xtiles*ty + tx];
				to= mipbuf->rect + mipbuf->x*ty*mipbuf->tiley + tx*mipbuf->tilex;

				/* exception in tile width/height for tiles at end of image */
				w= (tx == mipbuf->xtiles-1)? mipbuf->x - tx*mipbuf->tilex: mipbuf->tilex;
				h= (ty == mipbuf->ytiles-1)? mipbuf->y - ty*mipbuf->tiley: mipbuf->tiley;

				for(y=0; y<h; y++) {
					memcpy(to, from, sizeof(unsigned int)*w);
					from += mipbuf->tilex;
					to += mipbuf->x;
				}

				/* decrease refcount for tile again */
				BLI_mutex_lock(&GLOBAL_CACHE.mutex);
				gtile->refcount--;
				BLI_mutex_unlock(&GLOBAL_CACHE.mutex);
			}
		}
	}
}
开发者ID:OldBrunet,项目名称:BGERTPS,代码行数:48,代码来源:cache.c


示例19: BKE_cachefile_ensure_handle

void BKE_cachefile_ensure_handle(const Main *bmain, CacheFile *cache_file)
{
	BLI_spin_lock(&spin);
	if (cache_file->handle_mutex == NULL) {
		cache_file->handle_mutex = BLI_mutex_alloc();
	}
	BLI_spin_unlock(&spin);

	BLI_mutex_lock(cache_file->handle_mutex);

	if (cache_file->handle == NULL) {
		BKE_cachefile_reload(bmain, cache_file);
	}

	BLI_mutex_unlock(cache_file->handle_mutex);
}
开发者ID:mgschwan,项目名称:blensor,代码行数:16,代码来源:cachefile.c


示例20: task_scheduler_thread_wait_pop

static bool task_scheduler_thread_wait_pop(TaskScheduler *scheduler, Task **task)
{
	BLI_mutex_lock(&scheduler->queue_mutex);

	while (!scheduler->queue.first && !scheduler->do_exit)
		BLI_condition_wait(&scheduler->queue_cond, &scheduler->queue_mutex);

	if (!scheduler->queue.first) {
		BLI_mutex_unlock(&scheduler->queue_mutex);
		BLI_assert(scheduler->do_exit);
		return false;
	}
	
	*task = scheduler->queue.first;
	BLI_remlink(&scheduler->queue, *task);

	BLI_mutex_unlock(&scheduler->queue_mutex);

	return true;
}
开发者ID:Eibriel,项目名称:kiriblender,代码行数:20,代码来源:task.c



注:本文中的BLI_mutex_lock函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ BLI_mutex_unlock函数代码示例发布时间:2022-05-30
下一篇:
C++ BLI_make_file_string函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap