Ejemplo n.º 1
0
/**
 * Initializes a condition variable.
 */
void vlc_cond_init (vlc_cond_t *p_condvar)
{
    pthread_condattr_t attr;

    if (unlikely(pthread_condattr_init (&attr)))
        abort ();
#if !defined (_POSIX_CLOCK_SELECTION)
   /* Fairly outdated POSIX support (that was defined in 2001) */
# define _POSIX_CLOCK_SELECTION (-1)
#endif
#if (_POSIX_CLOCK_SELECTION >= 0)
    /* NOTE: This must be the same clock as the one in mtime.c */
    pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
#endif

    if (unlikely(pthread_cond_init (p_condvar, &attr)))
        abort ();
    pthread_condattr_destroy (&attr);
}
Ejemplo n.º 2
0
Archivo: rthreads.c Proyecto: ieei/rlib
void
r_cond_init (RCond * cond)
{
#if defined (R_OS_WIN32)
  PCONDITION_VARIABLE pc = *cond = r_mem_new (CONDITION_VARIABLE);
  InitializeConditionVariable (pc);
#elif defined (HAVE_PTHREAD_H)
  pthread_condattr_t attr;
  pthread_cond_t * pc;

  pthread_condattr_init (&attr);
  pc = *cond = r_mem_new (pthread_cond_t);

  pthread_cond_init (pc, &attr);
  pthread_condattr_destroy (&attr);
#else
  (void) cond;
#endif
}
Ejemplo n.º 3
0
int traceobj_init(struct traceobj *trobj, const char *label, int nr_marks)
{
	pthread_mutexattr_t mattr;
	pthread_condattr_t cattr;
	int ret;

	pthread_mutexattr_init(&mattr);
	pthread_mutexattr_settype(&mattr, mutex_type_attribute);
	pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT);
	pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_PRIVATE);
	ret = __bt(-__RT(pthread_mutex_init(&trobj->lock, &mattr)));
	pthread_mutexattr_destroy(&mattr);
	if (ret)
		return ret;

	pthread_condattr_init(&cattr);
	pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_PRIVATE);
	ret = __bt(-__RT(pthread_cond_init(&trobj->join, &cattr)));
	pthread_condattr_destroy(&cattr);
	if (ret) {
		__RT(pthread_mutex_destroy(&trobj->lock));
		return ret;
	}

	/*
	 * We make sure not to unblock from threadobj_join() until at
	 * least one thread has called trace_enter() for this trace
	 * object.
	 */
	trobj->nr_threads = -1;

	trobj->label = label;
	trobj->nr_marks = nr_marks;
	trobj->cur_mark = 0;

	if (nr_marks > 0) {
		trobj->marks = pvmalloc(sizeof(struct tracemark) * nr_marks);
		if (trobj->marks == NULL)
			panic("cannot allocate mark table for tracing");
	}

	return 0;
}
Ejemplo n.º 4
0
Archivo: 2-1.c Proyecto: Nan619/ltp-ddt
int main()
{

	/* Make sure there is process-shared capability. */
#ifndef PTHREAD_PROCESS_SHARED
	fprintf(stderr,
		"process-shared attribute is not available for testing\n");
	return PTS_UNRESOLVED;
#endif

	pthread_condattr_t attr;
	int ret;

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

	/* Set 'pshared' to INVALID_PSHARED_VALUE. */
	ret = pthread_condattr_setpshared(&attr, INVALID_PSHARED_VALUE);
	if (ret != 0) {
		if (ret == EINVAL) {
			printf("Test PASSED\n");
			return PTS_PASS;
		}

		printf
		    ("Test FAILED: Invalid return code, expected 0 or EINVAL, but got: %d\n",
		     ret);
		return PTS_FAIL;
	}

	/* Destory the cond attributes object */
	if (pthread_condattr_destroy(&attr) != 0) {
		perror("Error at pthread_condattr_destroy()\n");
		return PTS_UNRESOLVED;
	}

	printf
	    ("Test PASSED: NOTE*: Returned 0 when passed an invalid 'pshared', but standard says 'may' fail.\n");
	return PTS_PASS;
}
Ejemplo n.º 5
0
int
xsim_barrier_init(xsim_barrier_t *barrier, int needed) {

  pthread_mutexattr_t mattr;
  pthread_condattr_t  cattr;

  barrier->count   = needed;
  barrier->current = 0;

  pthread_mutexattr_init(&mattr);
  pthread_mutexattr_setpshared(&mattr, 1);
  pthread_mutex_init(&barrier->lock, &mattr);

  pthread_condattr_init(&cattr);
  pthread_condattr_setpshared(&cattr, 1);
  pthread_cond_init(&barrier->cond, &cattr);
  
  return XSIM_SUCCESS;
}
inline interprocess_condition::interprocess_condition()
{
   int res;
   pthread_condattr_t cond_attr;
   res = pthread_condattr_init(&cond_attr);
   if(res != 0){
      throw interprocess_exception();
   }
   res = pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED);
   if(res != 0){
      pthread_condattr_destroy(&cond_attr);
      throw interprocess_exception(res);
   }
   res = pthread_cond_init(&m_condition, &cond_attr);
   pthread_condattr_destroy(&cond_attr);
   if(res != 0){
      throw interprocess_exception(res);
   }
}
Ejemplo n.º 7
0
ca_cond ca_cond_new(void)
{
    ca_cond retVal = NULL;
    ca_cond_internal *eventInfo = (ca_cond_internal*) OICMalloc(sizeof(ca_cond_internal));
    if (NULL != eventInfo)
    {
        int ret = pthread_condattr_init(&(eventInfo->condattr));
        if(0 != ret)
        {
            OIC_LOG_V(ERROR, TAG, "%s: Failed to initialize condition variable attribute %d!",
                    __func__, ret);
            OICFree(eventInfo);
            return retVal;
        }

#if defined(__ANDROID__) || _POSIX_TIMERS > 0
        ret = pthread_condattr_setclock(&(eventInfo->condattr), CLOCK_MONOTONIC);

        if(0 != ret)
        {
            OIC_LOG_V(ERROR, TAG, "%s: Failed to set condition variable clock %d!",
                    __func__, ret);
            pthread_condattr_destroy(&(eventInfo->condattr));
            OICFree(eventInfo);
            return retVal;
        }
#endif
        ret = pthread_cond_init(&(eventInfo->cond), &(eventInfo->condattr));
        if (0 == ret)
        {
            retVal = (ca_cond) eventInfo;
        }
        else
        {
            OIC_LOG_V(ERROR, TAG, "%s: Failed to initialize condition variable %d!", __func__, ret);
            pthread_condattr_destroy(&(eventInfo->condattr));
            OICFree(eventInfo);
        }
    }

    return retVal;
}
Ejemplo n.º 8
0
SemaphoreImpl::SemaphoreImpl(int n, int max): _n(n), _max(max)
{
	poco_assert (n >= 0 && max > 0 && n <= max);

#if defined(POCO_VXWORKS)
	// This workaround is for VxWorks 5.x where
	// pthread_mutex_init() won't properly initialize the mutex
	// resulting in a subsequent freeze in pthread_mutex_destroy()
	// if the mutex has never been used.
	std::memset(&_mutex, 0, sizeof(_mutex));
#endif
	if (pthread_mutex_init(&_mutex, NULL))
		throw SystemException("cannot create semaphore (mutex)");

#if defined(POCO_HAVE_MONOTONIC_PTHREAD_COND_TIMEDWAIT)
	pthread_condattr_t attr;
	if (pthread_condattr_init(&attr))
	{
		pthread_mutex_destroy(&_mutex);
		throw SystemException("cannot create semaphore (condition attribute)");
	}
	if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
    {
		pthread_condattr_destroy(&attr);
		pthread_mutex_destroy(&_mutex);
		throw SystemException("cannot create semaphore (condition attribute clock)");
    }
	if (pthread_cond_init(&_cond, &attr))
	{
		pthread_condattr_destroy(&attr);
		pthread_mutex_destroy(&_mutex);
		throw SystemException("cannot create semaphore (condition)");
	}
	pthread_condattr_destroy(&attr);
#else
	if (pthread_cond_init(&_cond, NULL))
	{
		pthread_mutex_destroy(&_mutex);
		throw SystemException("cannot create semaphore (condition)");
	}
#endif
}
Ejemplo n.º 9
0
struct OsCond * os_cond_create(void) {
    struct OsCond *cond = allocate_zero<OsCond>(1);

    if (!cond) {
        os_cond_destroy(cond);
        return NULL;
    }

#if defined(GENESIS_OS_WINDOWS)
    InitializeConditionVariable(&cond->id);
    InitializeCriticalSection(&cond->default_cs_id);
#elif defined(GENESIS_OS_KQUEUE)
    cond->kq_id = kqueue();
    if (cond->kq_id == -1)
        return NULL;
#else
    if (pthread_condattr_init(&cond->attr)) {
        os_cond_destroy(cond);
        return NULL;
    }
    cond->attr_init = true;

    if (pthread_condattr_setclock(&cond->attr, CLOCK_MONOTONIC)) {
        os_cond_destroy(cond);
        return NULL;
    }

    if (pthread_cond_init(&cond->id, &cond->attr)) {
        os_cond_destroy(cond);
        return NULL;
    }
    cond->id_init = true;

    if ((pthread_mutex_init(&cond->default_mutex_id, NULL))) {
        os_cond_destroy(cond);
        return NULL;
    }
    cond->default_mutex_init = true;
#endif

    return cond;
}
Ejemplo n.º 10
0
struct SoundIoOsCond * soundio_os_cond_create(void) {
    struct SoundIoOsCond *cond = ALLOCATE(struct SoundIoOsCond, 1);

    if (!cond) {
        soundio_os_cond_destroy(cond);
        return NULL;
    }

#if defined(SOUNDIO_OS_WINDOWS)
    InitializeConditionVariable(&cond->id);
    InitializeCriticalSection(&cond->default_cs_id);
#elif defined(SOUNDIO_OS_KQUEUE)
    cond->kq_id = kqueue();
    if (cond->kq_id == -1)
        return NULL;
#else
    if (pthread_condattr_init(&cond->attr)) {
        soundio_os_cond_destroy(cond);
        return NULL;
    }
    cond->attr_init = true;

    if (pthread_condattr_setclock(&cond->attr, CLOCK_MONOTONIC)) {
        soundio_os_cond_destroy(cond);
        return NULL;
    }

    if (pthread_cond_init(&cond->id, &cond->attr)) {
        soundio_os_cond_destroy(cond);
        return NULL;
    }
    cond->id_init = true;

    if ((pthread_mutex_init(&cond->default_mutex_id, NULL))) {
        soundio_os_cond_destroy(cond);
        return NULL;
    }
    cond->default_mutex_init = true;
#endif

    return cond;
}
Ejemplo n.º 11
0
/*
 * On first invocation, allocates a condition variable attributes
 * structure and initializes it with appropriate attributes. In
 * all cases, returns a pointer to the structure.
 */
pthread_condattr_t *
ipc_condattr(void)
{
	if (condattr == NULL) {
		if ((condattr = malloc(sizeof (pthread_condattr_t))) == NULL) {
			filebench_log(LOG_ERROR, "cannot alloc cond attr");
			filebench_shutdown(1);
		}
		(void) pthread_condattr_init(condattr);
#ifdef HAVE_PTHREAD_MUTEXATTR_SETPSHARED
		if (pthread_condattr_setpshared(condattr,
		    PTHREAD_PROCESS_SHARED) != 0) {
			filebench_log(LOG_ERROR,
			    "cannot set cond attr PROCESS_SHARED");
//			filebench_shutdown(1);
		}
#endif /* HAVE_PTHREAD_MUTEXATTR_SETPSHARED */
	}
	return (condattr);
}
Ejemplo n.º 12
0
int thread_pool_create(thread_pool *new_pool, long max_running_threads)
{
    thread_id i;
    if((new_pool->threads = (pthread_t *) calloc((size_t) max_running_threads,
                sizeof(pthread_t))) == NULL)
        return -1;
    if((new_pool->working = (bool *) calloc((size_t) max_running_threads,
                sizeof(bool))) == NULL)
        return -1;
    if(pthread_condattr_init(&(new_pool->cond_attr)) != 0)
        return -1;
    if(pthread_cond_init(&new_pool->sleeping, &(new_pool->cond_attr)) != 0)
        return -1;
    new_pool->running_threads = 0;
    new_pool->max_running_threads = max_running_threads;
    new_pool->unused = NULL;
    for(i = 0; i < max_running_threads; i ++)
        new_pool->unused = stack_push(new_pool->unused, i);
    new_pool->sleeping_quantity = 0;
    return 0;
}
Ejemplo n.º 13
0
OSCond::OSCond()
	: fWaitCount(0)
{
#ifdef __Win32__
	fCondition = ::CreateEvent(NULL, FALSE, FALSE, NULL);
	Assert(fCondition != NULL);
#elif __PTHREADS_MUTEXES__
#if __MacOSX__
	int ret = pthread_cond_init(&fCondition, NULL);
	Assert(ret == 0);
#else
	pthread_condattr_t cond_attr;
	pthread_condattr_init(&cond_attr);
	int ret = pthread_cond_init(&fCondition, &cond_attr);
	Assert(ret == 0);
#endif
#else
	fCondition = mycondition_alloc();
	Assert(fCondition != NULL);
#endif
}
Ejemplo n.º 14
0
int uv_cond_init(uv_cond_t* cond) {
    pthread_condattr_t attr;

    if (pthread_condattr_init(&attr)) return -1;

#if !(defined(__ANDROID__) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC))
    if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC)) goto error2;
#endif

    if (pthread_cond_init(cond, &attr)) goto error2;

    if (pthread_condattr_destroy(&attr)) goto error;

    return 0;

error:
    pthread_cond_destroy(cond);
error2:
    pthread_condattr_destroy(&attr);
    return -1;
}
void
xshmfence_init(int fd)
{
    struct xshmfence *f = xshmfence_map_shm(fd);
    pthread_mutexattr_t mutex_attr;
    pthread_condattr_t cond_attr;

    if (!f)
        return;

    pthread_mutexattr_init(&mutex_attr);
    pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_SHARED);
    pthread_mutex_init(&f->lock, &mutex_attr);

    pthread_condattr_init(&cond_attr);
    pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED);
    pthread_cond_init(&f->wakeup, &cond_attr);
    f->value = 0;
    f->waiting = 0;
    xshmfence_unmap_shm(f);
}
Ejemplo n.º 16
0
int sysv_barrier_create(sysv_barrier_t barrier, int num_procs)
{
  pthread_mutexattr_t mutex_shared_attr;
  PTHREAD_SAFE(pthread_mutexattr_init(&mutex_shared_attr));
  PTHREAD_SAFE(pthread_mutexattr_setpshared(&mutex_shared_attr, 
					    PTHREAD_PROCESS_SHARED));
  PTHREAD_SAFE(pthread_mutex_init(&(barrier->mutex), &mutex_shared_attr));
  PTHREAD_SAFE(pthread_mutexattr_destroy(&mutex_shared_attr));
  
  pthread_condattr_t cond_shared_attr;
  PTHREAD_SAFE(pthread_condattr_init(&cond_shared_attr));
  PTHREAD_SAFE(pthread_condattr_setpshared(&cond_shared_attr, 
					   PTHREAD_PROCESS_SHARED));
  PTHREAD_SAFE(pthread_cond_init(&(barrier->cond), &cond_shared_attr));
  PTHREAD_SAFE(pthread_condattr_destroy(&cond_shared_attr));
  
  barrier->num_procs = num_procs;
  barrier->num_waiting = 0;
  
  return 0;
}
Ejemplo n.º 17
0
Archivo: ipc.c Proyecto: alhazred/onarm
/*
 * On first invocation, allocates a condition variable attributes
 * structure and initializes it with appropriate attributes. In
 * all cases, returns a pointer to the structure.
 */
pthread_condattr_t *
ipc_condattr(void)
{
#ifdef USE_PROCESS_MODEL
	if (condattr == NULL) {
		if ((condattr = malloc(sizeof (pthread_condattr_t))) == NULL) {
			filebench_log(LOG_ERROR, "cannot alloc cond attr");
			filebench_shutdown(1);
		}
#ifdef HAVE_PROCSCOPE_PTHREADS
		(void) pthread_condattr_init(condattr);
		if (pthread_condattr_setpshared(condattr,
		    PTHREAD_PROCESS_SHARED) != 0) {
			filebench_log(LOG_ERROR,
			    "cannot set cond attr PROCESS_SHARED");
			filebench_shutdown(1);
		}
#endif /* HAVE_PROCSCOPE_PTHREADS */
	}
#endif /* USE_PROCESS_MODEL */
	return (condattr);
}
clsThread::clsThread()
{
	m_idThread = 0;

	m_chThread = ChannelCreate(0);
    m_coidThread = ConnectAttach(ND_LOCAL_NODE, 0, m_chThread, _NTO_SIDE_CHANNEL, 0);

	pthread_condattr_t attrCond;
	pthread_condattr_init(&attrCond);

	pthread_cond_init(&m_condThread, &attrCond);

	pthread_mutexattr_t attrMtx;
	pthread_mutexattr_init(&attrMtx);

	pthread_mutex_init(&m_mtxThread, &attrMtx);
	pthread_mutex_lock(&m_mtxThread);

	m_bReady = FALSE;

	m_nCount = 0;
}
Ejemplo n.º 19
0
ion_semaphore_t * IonImageSem::Create(const char *semaphore_name)
{
	int fd;
	ion_semaphore_t *semap;

    fd = open(semaphore_name, O_RDWR | O_CREAT /*| O_EXCL*/, 0666);
    if (fd < 0){
    	ISMLOG("%s: failed, %s\n",__FUNCTION__,strerror(errno));
        return (NULL);
    }
    if( ftruncate(fd, sizeof(ion_semaphore_t)))
    {}
#ifdef USE_ION_PTHREAD_SEM
    pthread_mutexattr_t psharedm;
    pthread_condattr_t psharedc;
    (void) pthread_mutexattr_init(&psharedm);
//    int robustness=0;
//    (void) pthread_mutexattr_getrobust_np(&psharedm,&robustness);
//	DTRACEP("%s: robust: %d\n",__FUNCTION__,robustness);
    (void) pthread_mutexattr_setpshared(&psharedm, PTHREAD_PROCESS_SHARED);
    (void)pthread_mutexattr_setrobust_np(&psharedm, PTHREAD_MUTEX_ROBUST_NP);
    (void) pthread_condattr_init(&psharedc);
    (void) pthread_condattr_setpshared(&psharedc,
        PTHREAD_PROCESS_SHARED);
#endif
    semap = (ion_semaphore_t *) mmap(NULL, sizeof(ion_semaphore_t),
            PROT_READ | PROT_WRITE, MAP_SHARED,
            fd, 0);
    close (fd);
    if(semap)
    {
    	memset(semap,0,sizeof(ion_semaphore_t));
#ifdef USE_ION_PTHREAD_SEM
    	(void) pthread_mutex_init(&semap->lock, &psharedm);
#endif
    //    (void) pthread_cond_init(&semap->nonzero, &psharedc);
    }
    return (semap);
}
Ejemplo n.º 20
0
Archivo: osa_flg.c Proyecto: 119/ipnc
int  OSA_flgCreate(OSA_FlgHndl *hndl, Uint32 initPattern)
{
  pthread_mutexattr_t mutex_attr;
  pthread_condattr_t cond_attr;
  int status=OSA_SOK;
 
  status |= pthread_mutexattr_init(&mutex_attr);
  status |= pthread_condattr_init(&cond_attr);  
  
  status |= pthread_mutex_init(&hndl->lock, &mutex_attr);
  status |= pthread_cond_init(&hndl->cond, &cond_attr);  

  hndl->pattern = initPattern;

  if(status!=OSA_SOK)
    OSA_ERROR("OSA_flgCreate() = %d \r\n", status);

  pthread_condattr_destroy(&cond_attr);
  pthread_mutexattr_destroy(&mutex_attr);
    
  return status;
}
Ejemplo n.º 21
0
int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
{
    pthread_mutexattr_t*  lock_attr = NULL;
    pthread_condattr_t*   cond_attr = NULL;
    pthread_mutexattr_t   lock_attr0;
    pthread_condattr_t    cond_attr0;
    int                   ret;

    if (rwlock == NULL)
        return EINVAL;

    if (attr && *attr == PTHREAD_PROCESS_SHARED) {
        lock_attr = &lock_attr0;
        pthread_mutexattr_init(lock_attr);
        pthread_mutexattr_setpshared(lock_attr, PTHREAD_PROCESS_SHARED);

        cond_attr = &cond_attr0;
        pthread_condattr_init(cond_attr);
        pthread_condattr_setpshared(cond_attr, PTHREAD_PROCESS_SHARED);
    }

    ret = pthread_mutex_init(&rwlock->lock, lock_attr);
    if (ret != 0)
        return ret;

    ret = pthread_cond_init(&rwlock->cond, cond_attr);
    if (ret != 0) {
        pthread_mutex_destroy(&rwlock->lock);
        return ret;
    }

    rwlock->numLocks = 0;
    rwlock->pendingReaders = 0;
    rwlock->pendingWriters = 0;
    rwlock->writerThreadId = 0;

    return 0;
}
Ejemplo n.º 22
0
Archivo: 3-1.c Proyecto: 8l/rose
int main()
{
	pthread_condattr_t condattr;

	/* Initialize a condition variable attributes object */
	if(pthread_condattr_init(&condattr) != 0)
	{
		fprintf(stderr,"Cannot initialize condition variable attributes object\n");
		return PTS_UNRESOLVED;
	}

	/* Destroy the condition variable attributes object */
	if(pthread_condattr_destroy(&condattr) != 0)
	{
		printf("Test FAILED\n");
		return PTS_FAIL;
	}
	else
	{
		printf("Test PASSED\n");
		return PTS_PASS;
	}
}
Ejemplo n.º 23
0
  BOOL InitializeConditionVariables ( void ) {
  
    int err;

    if ( (err = pthread_condattr_init( &(shmp->shmem_cv_attr) ) ) != 0 ) {
      DbgLog(DL0,"InitializeConditionVariables: pthread_condattr_init returned %s (%d; %#x)\n", SysConst(err), err, err);
      return FALSE;
    }


    if ( (err = pthread_cond_init( &(shmp->shmem_cv), &(shmp->shmem_cv_attr) ) ) != 0 ) {
      DbgLog(DL0,"InitializeConditionVariables: pthread_cond_init returned %s (%d; %#x)\n", SysConst(err), err, err);
      return FALSE;
    }

    if ( (err = pthread_mutex_init( &(shmp->shmem_cv_mutex), &mtxattr ) ) != 0 ) {
      DbgLog(DL0,"InitializeConditionVariables: pthread_mutex_init returned %s (%d; %#x)\n", SysConst(err), err, err);
      return FALSE;
    }

    return TRUE;

  }
Ejemplo n.º 24
0
void init_ring_buffer(struct ring_buffer* rbuff) {
  rbuff->request_writes = 0;
  rbuff->request_reads = 0;

  rbuff->response_writes = 0;
  rbuff->response_reads = 0;

  pthread_mutexattr_t mattr;
  pthread_mutexattr_init(&mattr);
  pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);  
  pthread_mutex_init(&rbuff->data_mutex, &mattr);
  
  pthread_condattr_t  cattr;
  pthread_condattr_init(&cattr);
  pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
  pthread_cond_init(&rbuff->nonempty, &cattr);

  int i;
  for(i = 0; i < MAXSIZE; i++) {
    pthread_cond_init(&rbuff->response_ready[i], &cattr);
    rbuff->request_buffer[i].response = i;
  }
}
Ejemplo n.º 25
0
int uv_cond_init(uv_cond_t* cond) {
  pthread_condattr_t attr;

  if (pthread_condattr_init(&attr))
    return -1;

  if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
    goto error2;

  if (pthread_cond_init(cond, &attr))
    goto error2;

  if (pthread_condattr_destroy(&attr))
    goto error;

  return 0;

error:
  pthread_cond_destroy(cond);
error2:
  pthread_condattr_destroy(&attr);
  return -1;
}
Ejemplo n.º 26
0
int main()
{
	pthread_condattr_t condattr;
	int rc;

	/* Initialize a cond attributes object */
	if ((rc=pthread_condattr_init(&condattr)) != 0)
	{
		fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc);
		printf("Test FAILED\n");
		return PTS_FAIL;
	}

	rc = pthread_condattr_setclock(&condattr, CLOCK_REALTIME);
	if (rc != 0)
	{
		printf("Test FAILED: Could not set clock to CLOCK_REALTIME\n");
		return PTS_FAIL;
	}

	printf("Test PASSED\n");
	return PTS_PASS;
}
Ejemplo n.º 27
0
Archivo: 1-1.c Proyecto: 8l/rose
int main()
{
	pthread_condattr_t condattr;
	int rc;

	/* Initialize a condition variable attributes object */
	if((rc=pthread_condattr_init(&condattr)) != 0)
	{
		fprintf(stderr,"Cannot initialize condition variable attributes object\n");
		return PTS_UNRESOLVED;
	}

	/* Destroy the condition variable attributes object */
	if(pthread_condattr_destroy(&condattr) != 0)
	{
		fprintf(stderr,"Error at pthread_condattr_destroy(), rc=%d\n", rc);
		printf("Test FAILED\n");
		return PTS_FAIL;
	}

	printf("Test PASSED\n");
	return PTS_PASS;	
}
Ejemplo n.º 28
0
int main()
{
	pthread_condattr_t condattr;
	int rc;

	/* Initialize a cond attributes object */
	if ((rc=pthread_condattr_init(&condattr)) != 0)
	{
		fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc);
		printf("Test FAILED\n");
		return PTS_FAIL;
	}

	rc = pthread_condattr_setclock(&condattr, INVALID_CLOCKID);
	if (rc != EINVAL)
	{
		printf("Test PASSED: *NOTE: Test passed while passing an invalid clockid, but the standard says 'may' fail\n");
		return PTS_PASS;
	}

	printf("Test PASSED\n");
	return PTS_PASS;
}
Ejemplo n.º 29
0
Archivo: 1-1.c Proyecto: 1587/ltp
int main(void)
{
	pthread_condattr_t condattr;
	clockid_t clockid;
	int rc;

	/* Initialize a cond attributes object */
	if ((rc = pthread_condattr_init(&condattr)) != 0) {
		fprintf(stderr, "Error at pthread_condattr_init(), rc=%d\n",
			rc);
		printf("Test FAILED\n");
		return PTS_FAIL;
	}

	rc = pthread_condattr_getclock(&condattr, &clockid);
	if (rc != 0) {
		printf("Test FAILED: Could not get the clock attribute\n");
		return PTS_FAIL;
	}

	printf("Test PASSED\n");
	return PTS_PASS;
}
Ejemplo n.º 30
0
Archivo: 3-1.c Proyecto: 1587/ltp
int main(void)
{
	pthread_condattr_t condattr;
	int rc;

	/* Initialize a condition variable attributes object */
	if ((rc = pthread_condattr_init(&condattr)) == 0) {
		printf("Test PASSED\n");
		return PTS_PASS;
	}

	/* Insufficient memory exists to initialize the condition variable attributes object */
	else if (rc == ENOMEM) {
		fprintf(stderr, "pthread_condattr_init() returns ENOMEM\n");
		return PTS_UNRESOLVED;
	}

	/* Any other returned value means the test failed */
	else {
		printf("Test FAILED\n");
		return PTS_FAIL;
	}
}