当前位置: 首页>>代码示例>>C++>>正文


C++ PTHREAD_MUTEX_LOCK函数代码示例

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


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

示例1: _handle_pending_node_data_requests

static void _handle_pending_node_data_requests(uint32_t src_node, unsigned force)
{
//	_STARPU_DEBUG("_starpu_handle_pending_node_data_requests ...\n");

	PTHREAD_MUTEX_LOCK(&data_requests_pending_list_mutex[src_node]);

	/* for all entries of the list */
	starpu_data_request_list_t local_list = data_requests_pending[src_node];
	data_requests_pending[src_node] = starpu_data_request_list_new();

	PTHREAD_MUTEX_UNLOCK(&data_requests_pending_list_mutex[src_node]);

	while (!starpu_data_request_list_empty(local_list))
	{
		starpu_data_request_t r;
		r = starpu_data_request_list_pop_back(local_list);

      if (r->src_handle != r->dst_handle) {
         _starpu_spin_lock(&r->src_handle->header_lock);
         _starpu_spin_lock(&r->dst_handle->header_lock);
      }
      else
         _starpu_spin_lock(&r->src_handle->header_lock);
	
		_starpu_spin_lock(&r->lock);
	
		/* wait until the transfer is terminated */
		if (force)
		{
			_starpu_driver_wait_request_completion(r, src_node);
			starpu_handle_data_request_completion(r);
		}
		else {
			if (_starpu_driver_test_request_completion(r, src_node))
			{
				
				starpu_handle_data_request_completion(r);
			}
			else {
				_starpu_spin_unlock(&r->lock);
            if (r->src_handle != r->dst_handle) {
               _starpu_spin_unlock(&r->src_handle->header_lock);
               _starpu_spin_unlock(&r->dst_handle->header_lock);
            }
            else
               _starpu_spin_unlock(&r->src_handle->header_lock);

				/* wake the requesting worker up */
				PTHREAD_MUTEX_LOCK(&data_requests_pending_list_mutex[src_node]);
				starpu_data_request_list_push_front(data_requests_pending[src_node], r);
				PTHREAD_MUTEX_UNLOCK(&data_requests_pending_list_mutex[src_node]);
			}
		}
	}

	starpu_data_request_list_delete(local_list);
}
开发者ID:alucas,项目名称:StarPU,代码行数:57,代码来源:data_request.c

示例2: _starpu_bind_thread_on_cpu

void *_starpu_gordon_worker(void *arg)
{
	struct starpu_worker_set_s *gordon_set_arg = arg;

	_starpu_bind_thread_on_cpu(gordon_set_arg->config, gordon_set_arg->workers[0].bindid);

	/* TODO set_local_memory_node per SPU */
	gordon_init(gordon_set_arg->nworkers);	

	/* NB: On SPUs, the worker_key is set to NULL since there is no point
	 * in associating the PPU thread with a specific SPU (worker) while
	 * it's handling multiple processing units. */
	_starpu_set_local_worker_key(NULL);

	/* TODO set workers' name field */
	unsigned spu;
	for (spu = 0; spu < gordon_set_arg->nworkers; spu++)
	{
		struct starpu_worker_s *worker = &gordon_set_arg->workers[spu];
		snprintf(worker->name, 32, "SPU %d", worker->id);
	}

	/*
 	 * To take advantage of PPE being hyperthreaded, we should have 2 threads
 	 * for the gordon driver : one injects works, the other makes sure that
 	 * gordon is progressing (and performs the callbacks).
	 */

	/* launch the progression thread */
	PTHREAD_MUTEX_INIT(&progress_mutex, NULL);
	PTHREAD_COND_INIT(&progress_cond, NULL);
	
	pthread_create(&progress_thread, NULL, gordon_worker_progress, gordon_set_arg);

	/* wait for the progression thread to be ready */
	PTHREAD_MUTEX_LOCK(&progress_mutex);
	while (!progress_thread_is_inited)
		PTHREAD_COND_WAIT(&progress_cond, &progress_mutex);
	PTHREAD_MUTEX_UNLOCK(&progress_mutex);

	_STARPU_DEBUG("progress thread is running ... \n");
	
	/* tell the core that gordon is ready */
	PTHREAD_MUTEX_LOCK(&gordon_set_arg->mutex);
	gordon_set_arg->set_is_initialized = 1;
	PTHREAD_COND_SIGNAL(&gordon_set_arg->ready_cond);
	PTHREAD_MUTEX_UNLOCK(&gordon_set_arg->mutex);

	gordon_worker_inject(gordon_set_arg);

	_STARPU_DEBUG("gordon deinit...\n");
	gordon_deinit();
	_STARPU_DEBUG("gordon was deinited\n");

	pthread_exit((void *)0x42);
}
开发者ID:alucas,项目名称:StarPU,代码行数:56,代码来源:gordon.c

示例3: ddc_receive_frame

static int ddc_receive_frame(void* data, int streamId, unsigned char* buffer, unsigned int bufferSize)
{
    DVDecodeStreamConnect* connect = (DVDecodeStreamConnect*)data;
    int status;
    int result = 1;

    if (connect->sourceStreamId != streamId)
    {
        ml_log_error("Received frame for unknown source stream %d in copy connect\n", streamId);
        return 0;
    }

    /* signal to ddc_sync at later time that we have received a frame to decode and send */
    connect->frameWasReceived = 1;


    if (!connect->useWorkerThread)
    {
        result = decode_and_send(connect);
    }
    else
    {

        /* check that the worker isn't busy */

        PTHREAD_MUTEX_LOCK(&connect->workerMutex);
        if (connect->workerIsBusy)
        {
            ml_log_error("DV connect worker thread is still busy, and therefore cannot receive a new frame\n");
            result = 0;
        }
        PTHREAD_MUTEX_UNLOCK(&connect->workerMutex);

        if (result != 1)
        {
            return result;
        }


        /* signal worker that a new frame is ready */

        PTHREAD_MUTEX_LOCK(&connect->workerMutex);
        connect->frameIsReady = 1;
        status = pthread_cond_signal(&connect->frameIsReadyCond);
        if (status != 0)
        {
            ml_log_error("DV connect worker thread failed to send frame is ready condition signal\n");
            result = 0;
        }
        PTHREAD_MUTEX_UNLOCK(&connect->workerMutex);
    }

    return result;
}
开发者ID:UIKit0,项目名称:bbc-ingex,代码行数:54,代码来源:dv_stream_connect.c

示例4: talloc

/** Inserts a backtrace marker into the provided context
 *
 * Allows for maximum laziness and will initialise a circular buffer if one has not already been created.
 *
 * Code augmentation should look something like:
@verbatim
	// Create a static cbuffer pointer, the first call to backtrace_attach will initialise it
	static fr_cbuff *my_obj_bt;

	my_obj_t *alloc_my_obj(TALLOC_CTX *ctx) {
		my_obj_t *this;

		this = talloc(ctx, my_obj_t);

		// Attach backtrace marker to object
		backtrace_attach(&my_obj_bt, this);

		return this;
	}
@endverbatim
 *
 * Then, later when a double free occurs:
@verbatim
	(gdb) call backtrace_print(&my_obj_bt, <pointer to double freed memory>)
@endverbatim
 *
 * which should print a limited backtrace to stderr. Note, this backtrace will not include any argument
 * values, but should at least show the code path taken.
 *
 * @param cbuff this should be a pointer to a static *fr_cbuff.
 * @param obj we want to generate a backtrace for.
 */
fr_bt_marker_t *fr_backtrace_attach(fr_cbuff_t **cbuff, TALLOC_CTX *obj)
{
	fr_bt_marker_t *marker;

	if (*cbuff == NULL) {
		PTHREAD_MUTEX_LOCK(&fr_debug_init);
		/* Check again now we hold the mutex - eww*/
		if (*cbuff == NULL) {
			TALLOC_CTX *ctx;

			ctx = fr_autofree_ctx();
			*cbuff = fr_cbuff_alloc(ctx, MAX_BT_CBUFF, true);
		}
		PTHREAD_MUTEX_UNLOCK(&fr_debug_init);
	}

	marker = talloc(obj, fr_bt_marker_t);
	if (!marker) {
		return NULL;
	}

	marker->obj = (void *) obj;
	marker->cbuff = *cbuff;

	talloc_set_destructor(marker, _fr_do_bt);

	return marker;
}
开发者ID:archsh,项目名称:freeradius-server,代码行数:60,代码来源:debug.c

示例5: http_player_state_txt

static void http_player_state_txt(struct shttpd_arg* arg)
{
    HTTPAccess* access = (HTTPAccess*)arg->user_data;
    int i;

    shttpd_printf(arg, "HTTP/1.1 200 OK\r\n");
    shttpd_printf(arg, "Content-type: text/plain\r\n\r\n");

    PTHREAD_MUTEX_LOCK(&access->playerStateMutex);

    shttpd_printf(arg, "length=%"PRId64"\n", access->currentFrameInfo.sourceLength);
    shttpd_printf(arg, "availableLength=%"PRId64"\n", access->currentFrameInfo.availableSourceLength);
    shttpd_printf(arg, "position=%"PRId64"\n", access->currentFrameInfo.position);
    shttpd_printf(arg, "startOffset=%"PRId64"\n", access->currentFrameInfo.startOffset);
    shttpd_printf(arg, "vtrErrorLevel=%u\n", access->currentFrameInfo.vtrErrorLevel);
    shttpd_printf(arg, "numMarkSelections=%d\n", access->currentFrameInfo.numMarkSelections);
    for (i = 0; i < access->currentFrameInfo.numMarkSelections; i++)
    {
        shttpd_printf(arg, "markFilter_%d=%u\n", i, access->currentFrameInfo.markTypeMasks[i]);
    }

    PTHREAD_MUTEX_UNLOCK(&access->playerStateMutex);

    arg->flags |= SHTTPD_END_OF_OUTPUT;
}
开发者ID:nxmirrors,项目名称:IngexPlayer,代码行数:25,代码来源:http_access.c

示例6: x11c_clear

void x11c_clear(X11Common* x11Common)
{
    x11Common->stopped = 1;
    join_thread(&x11Common->processEventThreadId, NULL, NULL);


    PTHREAD_MUTEX_LOCK(&x11Common->eventMutex) /* don't allow events to be processed */

    kic_free_keyboard_connect(&x11Common->keyboardConnect);
    pic_free_progress_bar_connect(&x11Common->progressBarConnect);
    mic_free_mouse_connect(&x11Common->mouseConnect);

    if (x11Common->createdWindowInfo)
    {
        x11c_close_window(&x11Common->windowInfo);
        x11Common->createdWindowInfo = 0;
    }

    SAFE_FREE(&x11Common->windowName);

    x11Common->osd = NULL;

    PTHREAD_MUTEX_UNLOCK(&x11Common->eventMutex)


    destroy_mutex(&x11Common->eventMutex);

    memset(x11Common, 0, sizeof(x11Common));
}
开发者ID:UIKit0,项目名称:bbc-ingex,代码行数:29,代码来源:x11_common.c

示例7: talloc

/** Inserts a backtrace marker into the provided context
 *
 * Allows for maximum laziness and will initialise a circular buffer if one has not already been created.
 *
 * Code augmentation should look something like:
@verbatim
	// Create a static cbuffer pointer, the first call to backtrace_attach will initialise it
	static fr_cbuff_t *my_obj_bt;

	my_obj_t *alloc_my_obj(TALLOC_CTX *ctx) {
		my_obj_t *this;

		this = talloc(ctx, my_obj_t);

		// Attach backtrace marker to object
		backtrace_attach(&my_obj_bt, this);

		return this;
	}
@endverbatim
 *
 * Then, later when a double free occurs:
@verbatim
	(gdb) call backtrace_print(&my_obj_bt, <pointer to double freed memory>)
@endverbatim
 *
 * which should print a limited backtrace to stderr. Note, this backtrace will not include any argument
 * values, but should at least show the code path taken.
 *
 * @param cbuff this should be a pointer to a static *fr_cbuff.
 * @param obj we want to generate a backtrace for.
 */
fr_bt_marker_t *fr_backtrace_attach(fr_cbuff_t **cbuff, TALLOC_CTX *obj)
{
	fr_bt_marker_t *marker;

	if (*cbuff == NULL) {
		PTHREAD_MUTEX_LOCK(&fr_debug_init);
		/* Check again now we hold the mutex - eww*/
		if (*cbuff == NULL) *cbuff = fr_cbuff_alloc(NULL, MAX_BT_CBUFF, true);
		PTHREAD_MUTEX_UNLOCK(&fr_debug_init);
	}

	marker = talloc(obj, fr_bt_marker_t);
	if (!marker) {
		return NULL;
	}

	marker->obj = (void *) obj;
	marker->cbuff = *cbuff;

	fprintf(stderr, "Backtrace attached to %s %p\n", talloc_get_name(obj), obj);
	/*
	 *	Generate the backtrace for memory allocation
	 */
	fr_backtrace_do(marker);
	talloc_set_destructor(marker, fr_backtrace_do);

	return marker;
}
开发者ID:janetuk,项目名称:freeradius,代码行数:60,代码来源:debug.c

示例8: _STARPU_DEBUG

void *gordon_worker_progress(void *arg)
{
	_STARPU_DEBUG("gordon_worker_progress\n");

	/* fix the thread on the correct cpu */
	struct starpu_worker_set_s *gordon_set_arg = arg;
	unsigned prog_thread_bind_id = 
		(gordon_set_arg->workers[0].bindid + 1)%(gordon_set_arg->config->nhwcores);
	_starpu_bind_thread_on_cpu(gordon_set_arg->config, prog_thread_bind_id);

	PTHREAD_MUTEX_LOCK(&progress_mutex);
	progress_thread_is_inited = 1;
	PTHREAD_COND_SIGNAL(&progress_cond);
	PTHREAD_MUTEX_UNLOCK(&progress_mutex);

	while (1) {
		/* the Gordon runtime needs to make sure that we poll it 
		 * so that we handle jobs that are done */

		/* wait for one task termination */
		int ret = gordon_wait(0);
		if (ret)
		{
			/* possibly wake the thread that injects work */
			starpu_wake_all_blocked_workers();
		}
	}

	return NULL;
}
开发者ID:alucas,项目名称:StarPU,代码行数:30,代码来源:gordon.c

示例9: rbtree_walk

/*
 *	walk the entire tree.  The compare function CANNOT modify
 *	the tree.
 *
 *	The compare function should return 0 to continue walking.
 *	Any other value stops the walk, and is returned.
 */
int rbtree_walk(rbtree_t *tree, rb_order_t order, rb_walker_t compare, void *context)
{
	int rcode;

	if (tree->root == NIL) return 0;

	PTHREAD_MUTEX_LOCK(tree);

	switch (order) {
	case RBTREE_PRE_ORDER:
		rcode = walk_node_pre_order(tree->root, compare, context);
		break;

	case RBTREE_IN_ORDER:
		rcode = walk_node_in_order(tree->root, compare, context);
		break;

	case RBTREE_POST_ORDER:
		rcode = walk_node_post_order(tree->root, compare, context);
		break;

	case RBTREE_DELETE_ORDER:
		rcode = walk_delete_order(tree, compare, context);
		break;

	default:
		rcode = -1;
		break;
	}

	PTHREAD_MUTEX_UNLOCK(tree);
	return rcode;
}
开发者ID:AirspeedTelecom,项目名称:freeradius,代码行数:40,代码来源:rbtree.c

示例10: _starpu_data_wait_until_available

/* If sequential consistency mode is enabled, this function blocks until the
 * handle is available in the requested access mode. */
int _starpu_data_wait_until_available(starpu_data_handle handle, starpu_access_mode mode)
{
	/* If sequential consistency is enabled, wait until data is available */
	PTHREAD_MUTEX_LOCK(&handle->sequential_consistency_mutex);
	int sequential_consistency = handle->sequential_consistency;
	if (sequential_consistency)
	{
		struct starpu_task *sync_task;
		sync_task = starpu_task_create();
		sync_task->destroy = 1;

		/* It is not really a RW access, but we want to make sure that
		 * all previous accesses are done */
		_starpu_detect_implicit_data_deps_with_handle(sync_task, sync_task, handle, mode);
		PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);

		/* TODO detect if this is superflous */
      starpu_event event;
		int ret = starpu_task_submit(sync_task, &event);
		STARPU_ASSERT(!ret);
      starpu_event_wait(event);
      starpu_event_release(event);
	}
	else {
		PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
	}

	return 0;
}
开发者ID:alucas,项目名称:StarPU,代码行数:31,代码来源:implicit_data_deps.c

示例11: _starpu_stack_pop_task

starpu_job_t _starpu_stack_pop_task(struct starpu_stack_jobq_s *stack_queue, pthread_mutex_t *sched_mutex)
{
	starpu_job_t j = NULL;

	if (stack_queue->njobs == 0)
		return NULL;

	if (stack_queue->njobs > 0) 
	{
		/* there is a task */
		j = starpu_job_list_pop_back(stack_queue->jobq);
	
		STARPU_ASSERT(j);
		stack_queue->njobs--;
		
		STARPU_TRACE_JOB_POP(j, 0);

		/* we are sure that we got it now, so at worst, some people thought 
		 * there remained some work and will soon discover it is not true */
		PTHREAD_MUTEX_LOCK(sched_mutex);
		total_number_of_jobs--;
		PTHREAD_MUTEX_UNLOCK(sched_mutex);
	}
	
	return j;

}
开发者ID:alucas,项目名称:StarPU,代码行数:27,代码来源:stack_queues.c

示例12: eap_handler_free

void eap_handler_free(rlm_eap_t *inst, eap_handler_t *handler)
{
	if (!handler)
		return;

	if (handler->identity) {
		talloc_free(handler->identity);
		handler->identity = NULL;
	}

	if (handler->prev_eapds) eap_ds_free(&(handler->prev_eapds));
	if (handler->eap_ds) eap_ds_free(&(handler->eap_ds));

	if ((handler->opaque) && (handler->free_opaque)) {
		handler->free_opaque(handler->opaque);
		handler->opaque = NULL;
	}

	handler->opaque = NULL;
	handler->free_opaque = NULL;

	if (handler->certs) pairfree(&handler->certs);

	PTHREAD_MUTEX_LOCK(&(inst->handler_mutex));
	if (inst->handler_tree) {
		rbtree_deletebydata(inst->handler_tree, handler);
	}
	talloc_free(handler);
	PTHREAD_MUTEX_UNLOCK(&(inst->handler_mutex));
}
开发者ID:jcartermeru,项目名称:freeradius-server,代码行数:30,代码来源:mem.c

示例13: proxy_tls_send

int proxy_tls_send(rad_listen_t *listener, REQUEST *request)
{
	int rcode;
	listen_socket_t *sock = listener->data;

	/*
	 *	Normal proxying calls us with the data already
	 *	encoded.  The "ping home server" code does not.  So,
	 *	if there's no packet, encode it here.
	 */
	if (!request->proxy->data) {
		request->proxy_listener->encode(request->proxy_listener,
						request);
	}

	DEBUG3("Proxy is writing %u bytes to SSL",
	       (unsigned int) request->proxy->data_len);
	PTHREAD_MUTEX_LOCK(&sock->mutex);
	while ((rcode = SSL_write(sock->ssn->ssl, request->proxy->data,
				  request->proxy->data_len)) < 0) {
		int err;
		while ((err = ERR_get_error())) {
			DEBUG("proxy SSL_write says %s",
			      ERR_error_string(err, NULL));
		}
		PTHREAD_MUTEX_UNLOCK(&sock->mutex);
		tls_socket_close(listener);
		return 0;
	}
	PTHREAD_MUTEX_UNLOCK(&sock->mutex);

	return 1;
}
开发者ID:SudoSource,项目名称:freeradius-server,代码行数:33,代码来源:tls_listen.c

示例14: hac_state_change_event

static void hac_state_change_event(void* data, const MediaPlayerStateEvent* event)
{
    HTTPAccess* access = (HTTPAccess*)data;

    PTHREAD_MUTEX_LOCK(&access->playerStateMutex);
    access->currentPlayerState = *event;
    PTHREAD_MUTEX_UNLOCK(&access->playerStateMutex);
}
开发者ID:nxmirrors,项目名称:IngexPlayer,代码行数:8,代码来源:http_access.c

示例15: hac_frame_displayed_event

static void hac_frame_displayed_event(void* data, const FrameInfo* frameInfo)
{
    HTTPAccess* access = (HTTPAccess*)data;

    PTHREAD_MUTEX_LOCK(&access->playerStateMutex);
    access->currentFrameInfo = *frameInfo;
    PTHREAD_MUTEX_UNLOCK(&access->playerStateMutex);
}
开发者ID:nxmirrors,项目名称:IngexPlayer,代码行数:8,代码来源:http_access.c


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