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


C++ pthread_mutexattr_setprotocol函数代码示例

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


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

示例1: pa_mutex_new

pa_mutex* pa_mutex_new(pa_bool_t recursive, pa_bool_t inherit_priority) {
    pa_mutex *m;
    pthread_mutexattr_t attr;
    int r;

    pa_assert_se(pthread_mutexattr_init(&attr) == 0);

    if (recursive)
        pa_assert_se(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) == 0);

#ifdef HAVE_PTHREAD_PRIO_INHERIT
    if (inherit_priority)
        pa_assert_se(pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT) == 0);
#endif

    m = pa_xnew(pa_mutex, 1);

#ifndef HAVE_PTHREAD_PRIO_INHERIT
    pa_assert_se(pthread_mutex_init(&m->mutex, &attr) == 0);

#else
    if ((r = pthread_mutex_init(&m->mutex, &attr))) {

        /* If this failed, then this was probably due to non-available
         * priority inheritance. In which case we fall back to normal
         * mutexes. */
        pa_assert(r == ENOTSUP && inherit_priority);

        pa_assert_se(pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_NONE) == 0);
        pa_assert_se(pthread_mutex_init(&m->mutex, &attr) == 0);
    }
#endif

    return m;
}
开发者ID:Klayv,项目名称:pulseaudio,代码行数:35,代码来源:mutex-posix.c

示例2: rtsafe_memory_pool_create

bool rtsafe_memory_pool_create(RtMemPool_Handle* handlePtr,
                               const char* poolName,
                               size_t dataSize,
                               size_t maxPreallocated)
{
    assert(poolName == NULL || strlen(poolName) < RTSAFE_MEMORY_POOL_NAME_MAX);

    k_list_head* nodePtr;
    RtMemPool* poolPtr;

    poolPtr = malloc(sizeof(RtMemPool));

    if (poolPtr == NULL)
    {
        return false;
    }

    if (poolName != NULL)
    {
        strcpy(poolPtr->name, poolName);
    }
    else
    {
        sprintf(poolPtr->name, "%p", poolPtr);
    }

    poolPtr->dataSize = dataSize;
    poolPtr->maxPreallocated = maxPreallocated;

    INIT_LIST_HEAD(&poolPtr->used);
    poolPtr->usedCount = 0;

    INIT_LIST_HEAD(&poolPtr->unused);
    poolPtr->unusedCount = 0;

    pthread_mutexattr_t atts;
    pthread_mutexattr_init(&atts);
#ifdef __ARM_ARCH_7A__
    pthread_mutexattr_setprotocol(&atts, PTHREAD_PRIO_INHERIT);
#endif
    pthread_mutex_init(&poolPtr->mutex, &atts);
    pthread_mutexattr_destroy(&atts);

    while (poolPtr->unusedCount < poolPtr->maxPreallocated)
    {
        nodePtr = malloc(sizeof(k_list_head) + poolPtr->dataSize);

        if (nodePtr == NULL)
        {
            break;
        }

        list_add_tail(nodePtr, &poolPtr->unused);
        poolPtr->unusedCount++;
    }

    *handlePtr = (RtMemPool_Handle)poolPtr;

    return true;
}
开发者ID:moddevices,项目名称:mod-host,代码行数:60,代码来源:rtmempool.c

示例3: thr

void *
thr (void *arg)
{
  int ret = 0;
  pthread_mutexattr_t mutexAttr;
  ret = pthread_mutexattr_init (&mutexAttr);
  CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_mutexattr_init");

  ret = pthread_mutexattr_setprotocol (&mutexAttr, PTHREAD_PRIO_INHERIT);
  CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_mutexattr_setprotocol");

  ret = pthread_mutex_init (&mutex, &mutexAttr);
  CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_mutex_init");

  ret = pthread_cond_init (&cond, 0);
  CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_cond_init");

  puts ("th: Init done, entering wait...");

  pthread_cleanup_push (clean, (void *) &mutex);
  ret = pthread_mutex_lock (&mutex);
  CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_mutex_lock");
  while (1)
    {
      ret = pthread_cond_wait (&cond, &mutex);
      CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_cond_wait");
    }
  pthread_cleanup_pop (1);

out:
  return (void *) (uintptr_t) ret;
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:32,代码来源:tst-cond-except.c

示例4: do_test

int do_test(int argc, char **argv)
{
	pthread_mutexattr_t mutexattr;
	int retc, protocol;

#if HAS_PTHREAD_MUTEXATTR_PROTOCOL_FUNCTIONS

	if (pthread_mutexattr_init(&mutexattr) != 0)
		printf("Failed to init mutexattr\n");

	if (pthread_mutexattr_setprotocol(&mutexattr,
					  PTHREAD_PRIO_INHERIT) != 0)
		printf("Can't set protocol prio inherit\n");

	if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0)
		printf("Can't get mutexattr protocol\n");
	else
		printf("protocol in mutexattr is %d\n", protocol);

	retc = pthread_mutex_init(&child_mutex, &mutexattr);
	if (retc != 0)
		printf("Failed to init mutex: %d\n", retc);

	create_other_thread(child_thread, NULL);
	join_threads();

	return 0;
#else
	return 1;
#endif
}
开发者ID:Altiscale,项目名称:sig-core-t_ltp,代码行数:31,代码来源:testpi-5.c

示例5: clockobj_init

int clockobj_init(struct clockobj *clkobj,
		  const char *name, unsigned int resolution_ns)
{
	pthread_mutexattr_t mattr;
	struct timespec now;
	int ret;

	if (resolution_ns == 0)
		return __bt(-EINVAL);

	memset(clkobj, 0, sizeof(*clkobj));
	ret = __clockobj_set_resolution(clkobj, resolution_ns);
	if (ret)
		return __bt(ret);

	/*
	 * FIXME: this lock is only used to protect the wallclock
	 * offset readings from updates. We should replace this by a
	 * confirmed reading loop.
	 */
	__RT(pthread_mutexattr_init(&mattr));
	__RT(pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT));
	__RT(pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_PRIVATE));
	__RT(pthread_mutex_init(&clkobj->lock, &mattr));
	__RT(pthread_mutexattr_destroy(&mattr));
	__RT(clock_gettime(CLOCK_COPPERPLATE, &now));
	timespec_sub(&clkobj->offset, &clkobj->epoch, &now);
	clkobj->name = name;

	return 0;
}
开发者ID:Lmaths,项目名称:xenomai-forge,代码行数:31,代码来源:clockobj.c

示例6: PsychInitMutex

/* Init a Mutex: */
int	PsychInitMutex(psych_mutex* mutex)
{
	int rc;

	// Use mutex attributes:
	pthread_mutexattr_t attr;

	// Set them to default settings, except for...
	pthread_mutexattr_init(&attr);

	// ... priority inheritance: We absolutely want it for extra
	// good realtime behaviour - Avoidance of priority inversion
	// at lock contention points:
	pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);

	// Create mutex with attributes in attr:
	rc = pthread_mutex_init(mutex, &attr);
	if (rc != 0) {
		printf("\n\nPTB-CRITICAL: PsychInitMutex(): Mutex initialization failed [%s]! Expect huge trouble and serious malfunctions!!!\n", strerror(rc));
		printf("PTB-CRITICAL: PsychInitMutex(): Set a breakpoint on your debugger on pthread_mutexattr_destroy() to debug this.\n\n");
	}

	// Done with it:
	pthread_mutexattr_destroy(&attr);

	return(rc);
}
开发者ID:rennis250,项目名称:Psychtoolbox-3,代码行数:28,代码来源:PsychTimeGlue.c

示例7: ags_recycling_context_init

void
ags_recycling_context_init(AgsRecyclingContext *recycling_context)
{
  recycling_context->flags = 0;
  recycling_context->sound_scope = 0;

  /* object mutex */
  recycling_context->obj_mutexattr = (pthread_mutexattr_t *) malloc(sizeof(pthread_mutexattr_t));

  pthread_mutexattr_init(recycling_context->obj_mutexattr);
  pthread_mutexattr_settype(recycling_context->obj_mutexattr,
			    PTHREAD_MUTEX_RECURSIVE);

#ifdef __linux__
  pthread_mutexattr_setprotocol(recycling_context->obj_mutexattr,
				PTHREAD_PRIO_INHERIT);
#endif

  recycling_context->obj_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
  pthread_mutex_init(recycling_context->obj_mutex,
		     recycling_context->obj_mutexattr);

  /* recall id */
  recycling_context->recall_id = NULL;

  /* parent and child */
  recycling_context->parent = NULL;
  recycling_context->children = NULL;

  /* context */
  recycling_context->recycling = NULL;
  recycling_context->length = 0;
}
开发者ID:gsequencer,项目名称:gsequencer,代码行数:33,代码来源:ags_recycling_context.c

示例8: mon_init

PERIODIC_THREAD_END


void mon_init(void)
{
   ASSERT_ONCE();

   /* open monitoring socket: */
   mon_socket = scl_get_socket("ap_mon");
   ASSERT_NOT_NULL(mon_socket);
   int64_t hwm = 1;
   zmq_setsockopt(mon_socket, ZMQ_SNDHWM, &hwm, sizeof(hwm));

   /* create monitoring connection: */
   const struct timespec period = {0, 20 * NSEC_PER_MSEC};
   pthread_mutexattr_init(&mutexattr);
   pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT);
   pthread_mutex_init(&mutex, &mutexattr);

   /* init msgpack buffer: */
   ASSERT_NULL(msgpack_buf);
   msgpack_buf = msgpack_sbuffer_new();
   ASSERT_NOT_NULL(msgpack_buf);
   ASSERT_NULL(pk);
   pk = msgpack_packer_new(msgpack_buf, msgpack_sbuffer_write);

   periodic_thread_start(&emitter_thread, mon_emitter, "mon_thread", THREAD_PRIORITY, period, NULL);
}
开发者ID:Aerobota,项目名称:PenguPilot,代码行数:28,代码来源:mon.c

示例9: mutex_init

int mutex_init(mutex_t *mutex, int type, int pi)
{
	pthread_mutexattr_t mattr;
	int err;

	pthread_mutexattr_init(&mattr);
	pthread_mutexattr_settype(&mattr, type);
#ifdef HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
	if (pi != 0)
		pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT);

	err = pthread_mutex_init(mutex, &mattr);
#else
	if (pi != 0) {
		err = ENOSYS;
		goto out;
	}
	err = pthread_mutex_init(mutex, &mattr);

  out:
#endif
	pthread_mutexattr_destroy(&mattr);

	return -err;
}
开发者ID:xxha,项目名称:xenomai-2.5.6,代码行数:25,代码来源:cond-torture.c

示例10: initCondAndMutex

static int
initCondAndMutex(void)
{
    int                 status;
    pthread_mutexattr_t mutexAttr;

    status = pthread_mutexattr_init(&mutexAttr);
    if (status) {
        LOG_ERRNUM0(status, "Couldn't initialize mutex attributes");
    }
    else {
        (void)pthread_mutexattr_setprotocol(&mutexAttr, PTHREAD_PRIO_INHERIT);
        /*
         * Recursive in case `termSigHandler()` and `waitUntilDone()` execute
         * on the same thread
         */
        (void)pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE);

        if ((status = pthread_mutex_init(&mutex, &mutexAttr))) {
            LOG_ERRNUM0(status, "Couldn't initialize mutex");
        }
        else {
            if ((status = pthread_cond_init(&cond, NULL))) {
                LOG_ERRNUM0(status, "Couldn't initialize condition variable");
                (void)pthread_mutex_destroy(&mutex);
            }
        }

        (void)pthread_mutexattr_destroy(&mutexAttr);
    } // `mutexAttr` initialized

    return status;
}
开发者ID:dgaer,项目名称:LDM,代码行数:33,代码来源:up7_down7_test.c

示例11: main

int main()
{

	pthread_mutexattr_t mta;
	int protocol = INVALID_PROTOCOL;

	int ret;

	/* Initialize a mutex attributes object */
	if (pthread_mutexattr_init(&mta) != 0)
	{
		perror("Error at pthread_mutexattr_init()\n");
		return PTS_UNRESOLVED;
	}

	while (protocol == PTHREAD_PRIO_NONE || protocol == PTHREAD_PRIO_INHERIT
		|| protocol == PTHREAD_PRIO_PROTECT) {
		protocol--;
	}

	/* Set the protocol to an invalid value. */
	ret = pthread_mutexattr_setprotocol(&mta,protocol);
	if ((ret == ENOTSUP) || (ret == EINVAL))
	{
		printf("Test PASSED\n");
		return PTS_PASS;
	} else{

		printf("Test FAILED: Expected error code ENOTSUP, got %d.\n", ret);
		return PTS_FAIL;
	}
}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:32,代码来源:3-1.c

示例12: epicsMutexOsdCreate

epicsMutexOSD * epicsMutexOsdCreate(void) {
    epicsMutexOSD *pmutex;
    int           status;

    pmutex = callocMustSucceed(1, sizeof(*pmutex), "epicsMutexOsdCreate");
    status = pthread_mutexattr_init(&pmutex->mutexAttr);
    checkStatusQuit(status, "pthread_mutexattr_init", "epicsMutexOsdCreate");

#if defined _POSIX_THREAD_PRIO_INHERIT
    status = pthread_mutexattr_setprotocol(
        &pmutex->mutexAttr,PTHREAD_PRIO_INHERIT);
    if (errVerbose) checkStatus(status, "pthread_mutexattr_setprotocal");
#endif /*_POSIX_THREAD_PRIO_INHERIT*/

    status = pthread_mutex_init(&pmutex->lock, &pmutex->mutexAttr);
    checkStatusQuit(status, "pthread_mutex_init", "epicsMutexOsdCreate");

#if defined _POSIX_THREAD_PROCESS_SHARED
    status = pthread_condattr_init(&pmutex->condAttr);
    checkStatus(status, "pthread_condattr_init");
    status = pthread_condattr_setpshared(&pmutex->condAttr,
        PTHREAD_PROCESS_PRIVATE);
    checkStatus(status, "pthread_condattr_setpshared");
    status = pthread_cond_init(&pmutex->waitToBeOwner, &pmutex->condAttr);
#else
    status = pthread_cond_init(&pmutex->waitToBeOwner, 0);
#endif /*_POSIX_THREAD_PROCESS_SHARED*/
    checkStatusQuit(status, "pthread_cond_init", "epicsMutexOsdCreate");
    return pmutex;
}
开发者ID:ukaea,项目名称:epics,代码行数:30,代码来源:osdMutex.c

示例13: do_test

int do_test(int argc, char ** argv)
{
    pthread_mutexattr_t mutexattr;
    int retc, protocol;

    if (pthread_mutexattr_init(&mutexattr) != 0) {
      printf("Failed to init mutexattr\n");
    };
    if (pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT) != 0) {
      printf("Can't set protocol prio inherit\n");
    }
    if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0) {
      printf("Can't get mutexattr protocol\n");
    } else {
      printf("protocol in mutexattr is %d\n", protocol);
    }
    if ((retc = pthread_mutex_init(&child_mutex, &mutexattr)) != 0) {
      printf("Failed to init mutex: %d\n", retc);
    }

    create_other_thread(child_thread, NULL);
    join_threads();
    
    return 0;
}
开发者ID:ystk,项目名称:debian-ltp,代码行数:25,代码来源:testpi-5.c

示例14: initLocalioData

// initialize data arrays to zero
// create mutex
int initLocalioData(void)
{
    int i;
    pthread_mutexattr_init(&data1MutexAttr);
    pthread_mutexattr_setprotocol(&data1MutexAttr,PTHREAD_PRIO_INHERIT);
    pthread_mutex_init(&data1Mutex,&data1MutexAttr);

    pthread_mutex_lock(&data1Mutex);
    for (i=0;i<NUM_MECH;i++) {
        data1.xd[i].x = 0;
        data1.xd[i].y = 0;
        data1.xd[i].z = 0;
        data1.rd[i].yaw = 0;
        data1.rd[i].pitch = 0;
        data1.rd[i].roll = 0;
        data1.rd[i].grasp = 0;
        Q_ori[i] = Q_ori[i].getIdentity();
    }
    data1.surgeon_mode=0;
    {
        _localio_counter = 0;
        for (i=0;i<NUM_MECH;i++) {
        	master_raw_position[i] = btVector3(0,0,0);
            master_position[i] = btVector3(0,0,0);
        }
    }
    pthread_mutex_unlock(&data1Mutex);
    return 0;
}
开发者ID:animesh-garg,项目名称:raven_2,代码行数:31,代码来源:local_io.cpp

示例15: mutex_init_test

static void
mutex_init_test (void)
{
	pthread_mutexattr_t mattr;
	pthread_mutex_t	mutex;
	mutex_kind_t mkind;
	int mproto, ret;

	/*
	 * Initialize a mutex attribute.
	 *
	 * pthread_mutexattr_init not tested for: ENOMEM
	 */
	assert (pthread_mutexattr_init (&mattr) == 0);

	/*
	 * Initialize a mutex.
	 *
	 * pthread_mutex_init not tested for: EAGAIN ENOMEM EPERM EBUSY
	 */
	log ("Testing pthread_mutex_init\n");
	log ("--------------------------\n");

	for (mproto = 0; mproto < NELEMENTS(protocols); mproto++) {
		for (mkind = M_POSIX; mkind <= M_SS2_RECURSIVE; mkind++) {
			/* Initialize the mutex attribute. */
			assert (pthread_mutexattr_init (&mattr) == 0);
			assert (pthread_mutexattr_setprotocol (&mattr,
			    protocols[mproto]) == 0);

			/*
			 * Ensure that the first mutex type is a POSIX
			 * compliant mutex.
			 */
			if (mkind != M_POSIX) {
				assert (pthread_mutexattr_settype (&mattr,
				    mutex_types[mkind]) == 0);
			}

			log ("  Protocol %s, Type %s - ",
			    protocol_strs[mproto], mutextype_strs[mkind]);
			ret = pthread_mutex_init (&mutex, &mattr);
			check_result (/* expected */ 0, ret);
			assert (pthread_mutex_destroy (&mutex) == 0);

			/*
			 * Destroy a mutex attribute.
			 *
			 * XXX - There should probably be a magic number
			 *       associated with a mutex attribute so that
			 *       destroy can be reasonably sure the attribute
			 *       is valid.
			 *
			 * pthread_mutexattr_destroy not tested for: EINVAL
			 */
			assert (pthread_mutexattr_destroy (&mattr) == 0);
		}
	}
}
开发者ID:AhmadTux,项目名称:freebsd,代码行数:59,代码来源:mutex_d.c


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