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

C++ pthread_mutexattr_setprotocol函数代码示例

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

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



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


示例16: swTable_create

int swTable_create(swTable *table)
{
    uint32_t row_num = table->size * (1 + SW_TABLE_CONFLICT_PROPORTION);

    //header + data
    uint32_t row_memory_size = sizeof(swTableRow) + table->item_size;

    /**
     * row data & header
     */
    size_t memory_size = row_num * row_memory_size;

    /**
     * memory pool for conflict rows
     */
    memory_size += sizeof(swMemoryPool) + sizeof(swFixedPool) + ((row_num - table->size) * sizeof(swFixedPool_slice));

    /**
     * for iterator, Iterate through all the elements
     */
    memory_size += table->size * sizeof(swTableRow *);

    void *memory = sw_shm_malloc(memory_size);
    if (memory == NULL)
    {
        return SW_ERR;
    }

    memset(memory, 0, memory_size);
    table->memory = memory;
    table->compress_threshold = table->size * SW_TABLE_COMPRESS_PROPORTION;

    table->rows = memory;
    memory += table->size * sizeof(swTableRow *);
    memory_size -= table->size * sizeof(swTableRow *);

#if SW_TABLE_USE_SPINLOCK == 0
    pthread_mutexattr_t attr;
    pthread_mutexattr_init(&attr);
    pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
    pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
    pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP);
#endif

    int i;
    for (i = 0; i < table->size; i++)
    {
        table->rows[i] = memory + (row_memory_size * i);
#if SW_TABLE_USE_SPINLOCK == 0
        pthread_mutex_init(&table->rows[i]->lock, &attr);
#endif
    }

    memory += row_memory_size * table->size;
    memory_size -= row_memory_size * table->size;
    table->pool = swFixedPool_new2(row_memory_size, memory, memory_size);

    return SW_OK;
}
开发者ID:netcode,项目名称:swoole-src,代码行数:59,代码来源:Table.c


示例17: fifo_init

int fifo_init(struct fifo *fifo, size_t size, bool_t prio_inherit) {
#if defined(HAVE_LIBPTHREAD) && !defined(SDL_FIFOS)

#ifndef _POSIX_THREAD_PROCESS_SHARED
#error "no _POSIX_THREAD_PROCESS_SHARED"
#endif /* _POSIX_THREAD_PROCESS_SHARED */

	/* linux multi-process locking */
	pthread_mutexattr_t mutex_attr;
	pthread_condattr_t cond_attr;
	struct utsname utsname;
	int err;

	if ((err = pthread_mutexattr_init(&mutex_attr)) < 0) {
		return err;
	}
	if (prio_inherit) {
		if ((err = pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_SHARED)) < 0) {
			return err;
		}
#ifdef _POSIX_THREAD_PRIO_INHERIT
		/* only on PREEMPT kernels */
		if ((err = uname(&utsname)) < 0) {
			return err;
		}
		if (!RUNNING_ON_VALGRIND && strstr(utsname.version, "PREEMPT") != NULL) {
			if ((err = pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT)) < 0) {
				return err;
			}
		}
#endif /* _POSIX_THREAD_PRIO_INHERIT */
	}
	if ((err = pthread_mutex_init(&fifo->mutex, &mutex_attr)) < 0) {
		return err;
	}

	if ((err = pthread_condattr_init(&cond_attr)) < 0) {
		return err;
	}
	if (prio_inherit) {
		if ((err = pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED)) < 0) {
			return err;
		}
	}
	if ((err = pthread_cond_init(&fifo->cond, &cond_attr)) < 0) {
		return err;
	}
#else
	/* cross platform locks */
	fifo->mutex = SDL_CreateMutex();
	fifo->cond = SDL_CreateCond();
#endif
	fifo->rptr = 0;
	fifo->wptr = 0;
	fifo->size = size;

	return 0;
}
开发者ID:gnalbandian,项目名称:squeezeplay,代码行数:58,代码来源:fifo.c


示例18: SeInternalCreateEmptySegmentList

SeInternalCreateEmptySegmentList(	ENGINE_HANDLE hEngine,
									SeStatus *ErrorStatus )
{
	//--------------------------------
	Engine_t *Engine;
	SegmentList_t *SegmentList;
    pthread_mutexattr_t attr;
    int rc;
	//--------------------------------

    if (ErrorStatus == NULL){
        return NULL;
    }

	//
	//  Recover our engine object
	//
	Engine = (Engine_t *)hEngine;
	if (Engine->Signature != ENGINE_SIGNATURE){
		*ErrorStatus = SeInvalidParameters;
		return NULL;
	}

	//
	//  Start creating a SegmentList
	//
	SegmentList = (SegmentList_t *)malloc(sizeof(SegmentList_t));

	if (!SegmentList){
		*ErrorStatus = SeOutOfMemory;
		return NULL;
	}

	SegmentList->Signature = SEGMENT_LIST_SIGNATURE;
	SegmentList->Engine = Engine;
 
    rc = pthread_mutexattr_init(&attr);
    ASSERT(rc == 0);

    rc = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
    ASSERT(rc == 0);

    rc = pthread_mutex_init(&SegmentList->InUse, &attr);
    ASSERT(rc == 0);

    rc = pthread_mutexattr_destroy(&attr);
    ASSERT(rc == 0);
    
	SegmentList->Segments = new vector<Segment_t *>();
    SegmentList->Segments->reserve(20);

    //
    //  There isn't one.
    //
    SegmentList->CurIndex = -1;

    return (SE_SEGMENT_LIST_HANDLE)SegmentList;
}
开发者ID:michaelbecker,项目名称:mercury-common-libs,代码行数:58,代码来源:ParseSegmentList.cpp


示例19: main

int main(void)
{
#if defined(_SC_PRIORITY_SCHEDULING)

	if (sysconf(_SC_PRIORITY_SCHEDULING) == -1) {
		printf("PRIORITY_SCHEDULING not supported\n");
		return PTS_UNSUPPORTED;
	}

	pthread_mutexattr_t mutex_attr;
	pthread_mutex_t mutex;
	int error, prioceiling;

	error = pthread_mutexattr_init(&mutex_attr);
	if (error) {
		printf("pthread_mutexattr_init failed: %s\n", strerror(error));
		return PTS_UNRESOLVED;
	}

	/*
	 * Has to be something other than PTHREAD_PRIO_NONE, the default as per
	 * pthread_mutexattr_getprotocol.
	 */
	error = pthread_mutexattr_setprotocol(&mutex_attr,
					      PTHREAD_PRIO_PROTECT);
	if (error) {
		printf("pthread_mutexattr_setprotocol failed: %s\n",
		       strerror(error));
		return PTS_UNRESOLVED;
	}

	/* Initialize a mutex object */
	error = pthread_mutex_init(&mutex, &mutex_attr);
	if (error) {
		printf("pthread_mutex_init failed: %s\n", strerror(error));
		return PTS_UNRESOLVED;
	}

	/* Get the prioceiling of the mutex. */
	error = pthread_mutex_getprioceiling(&mutex, &prioceiling);
	if (error) {
		printf("pthread_mutex_getprioceiling failed: %s\n",
		       strerror(error));
		return PTS_FAIL;
	}

	(void)pthread_mutexattr_destroy(&mutex_attr);
	(void)pthread_mutex_destroy(&mutex);

	printf("Prioceiling returned: %d\n", prioceiling);
	return PTS_PASS;
#else
	printf("pthread_mutex_getprioceiling not supported");
	return PTS_UNSUPPORTED;
#endif

}
开发者ID:1587,项目名称:ltp,代码行数:57,代码来源:1-1.c


示例20: Pthread_mutexattr_setprotocol

void Pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol)
{
	int err;
	err = pthread_mutexattr_setprotocol(attr, protocol);
	if (err) {
		err_msg("%s: pthread_mutexattr_setprotocol(): ", __func__);
		err_exit(err, NULL);
	}
}
开发者ID:1023xp,项目名称:training,代码行数:9,代码来源:pip_stress.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ pthread_mutexattr_setpshared函数代码示例发布时间:2022-05-30
下一篇:
C++ pthread_mutexattr_destroy函数代码示例发布时间: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