void* XMLPlatformUtils::makeMutex(MemoryManager* manager)
{
    MutexHolderType* const  holder = new (manager) MutexHolderType;

    pthread_mutexattr_t     attr;

#if defined(XML_USE_DCE)
    pthread_mutexattr_create(&attr);
    pthread_mutexattr_setkind_np(&attr, MUTEX_RECURSIVE_NP);
    if (pthread_mutex_init(&holder->fInstance, attr))
    {
        delete holder;

        panic(PanicHandler::Panic_MutexErr);
    }
    pthread_mutexattr_delete(&attr);
#else
    pthread_mutexattr_init(&attr);
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
    if (pthread_mutex_init(&holder->fInstance, &attr))
    {
        delete holder;

        panic(PanicHandler::Panic_MutexErr);
    }
    pthread_mutexattr_destroy(&attr);
#endif

    return holder;
}
Example #2
0
void* XMLPlatformUtils::makeMutex()
{
    pthread_mutex_t* mutex = new pthread_mutex_t;
    pthread_mutexattr_t*  attr = new pthread_mutexattr_t;

#if defined(XML_USE_DCE)
    pthread_mutexattr_create(attr);
    pthread_mutexattr_setkind_np(attr, MUTEX_RECURSIVE_NP);
    if (pthread_mutex_init(mutex, *attr))
    {
        ThrowXMLwithMemMgr(XMLPlatformUtilsException,
                 XMLExcepts::Mutex_CouldNotCreate, fgMemoryManager);
    }
    pthread_mutexattr_delete(attr);
#else
    pthread_mutexattr_init(attr);
    pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE);
    if (pthread_mutex_init(mutex, attr))
    {
        ThrowXMLwithMemMgr(XMLPlatformUtilsException,
                 XMLExcepts::Mutex_CouldNotCreate, fgMemoryManager);
    }
    pthread_mutexattr_destroy(attr);
#endif
    delete attr;

    return (void*) mutex;
}
Example #3
0
void plc_inittimer (
  plc_sThread *tp
)
{

#if 0
  /* Create the timer mutex */
#ifdef OS_ELN
  {
    int	sts;
    ELN$CREATE_MUTEX(tp->timer_mutex, &sts);
    if (EVEN(sts))
      pwr_Bugcheck(sts, "Cannot create timer_mutex");
  }
#elif defined OS_POSIX
  {
    pthread_mutexattr_t attr;

    pthread_mutexattr_create(&attr);
    if (pthread_mutex_init(&tp->timer_mutex, attr) == -1) 
      pwr_Bugcheck(errno, "Cannot create timer_mutex");
    pthread_mutexattr_delete(&attr);
  }
#endif
#endif
}
Example #4
0
int
createMutex(Mutex_t& handle)
{
	pthread_mutexattr_t attr;
	int res = pthread_mutexattr_create(&attr);
	assert(res == 0);
	if (res != 0)
	{
		return -1;
	}

#if defined(BLOCXX_HAVE_PTHREAD_MUTEXATTR_SETTYPE)
	res = pthread_mutexattr_setkind_np(&attr, MUTEX_RECURSIVE_NP);
	assert(res == 0);
	if (res != 0)
	{
		pthread_mutexattr_delete(&attr);
		return -1;
	}
#endif

	res = pthread_mutex_init(&handle.mutex, attr);

	pthread_mutexattr_delete(&attr);
	if (res != 0)
	{
		return -1;
	}

#if !defined(BLOCXX_HAVE_PTHREAD_MUTEXATTR_SETTYPE)
	res = pthread_cond_init(&handle.unlocked, PTHREAD_COND_ATTR_DEFAULT);
	if (res != 0)
	{
		pthread_mutex_destroy(&handle.mutex);
		return -1;
	}

	handle.valid_id = false;
	handle.count = 0;
#endif
	return 0;
}