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

C++ pthread_mutexattr_settype函数代码示例

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

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



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

示例1: vcos_pthreads_timer_create

VCOS_STATUS_T vcos_pthreads_timer_create(VCOS_TIMER_T *timer,
                                const char *name,
                                void (*expiration_routine)(void *context),
                                void *context)
{
   pthread_mutexattr_t lock_attr;
   VCOS_STATUS_T result = VCOS_SUCCESS;
   int settings_changed_initialized = 0;
   int lock_attr_initialized = 0;
   int lock_initialized = 0;

   (void)name;

   vcos_assert(timer);
   vcos_assert(expiration_routine);

   memset(timer, 0, sizeof(VCOS_TIMER_T));

   timer->orig_expiration_routine = expiration_routine;
   timer->orig_context = context;

   /* Create conditional variable for notifying the timer's thread
    * when settings change.
    */
   if (result == VCOS_SUCCESS)
   {
      int rc = pthread_cond_init(&timer->settings_changed, NULL);
      if (rc == 0)
         settings_changed_initialized = 1;
      else
         result = vcos_pthreads_map_error(rc);
   }

   /* Create attributes for the lock (we want it to be recursive) */
   if (result == VCOS_SUCCESS)
   {
      int rc = pthread_mutexattr_init(&lock_attr);
      if (rc == 0)
      {
         pthread_mutexattr_settype(&lock_attr, PTHREAD_MUTEX_RECURSIVE);
         lock_attr_initialized = 1;
      }
      else
      {
         result = vcos_pthreads_map_error(rc);
      }
   }

   /* Create lock for the timer structure */
   if (result == VCOS_SUCCESS)
   {
      int rc = pthread_mutex_init(&timer->lock, &lock_attr);
      if (rc == 0)
         lock_initialized = 1;
      else
         result = vcos_pthreads_map_error(rc);
   }

   /* Lock attributes are no longer needed */
   if (lock_attr_initialized)
      pthread_mutexattr_destroy(&lock_attr);

   /* Create the underlying thread */
   if (result == VCOS_SUCCESS)
   {
      int rc = pthread_create(&timer->thread, NULL, _timer_thread, timer);
      if (rc != 0)
         result = vcos_pthreads_map_error(rc);
   }

   /* Clean up if anything went wrong */
   if (result != VCOS_SUCCESS)
   {
      if (lock_initialized)
         pthread_mutex_destroy(&timer->lock);

      if (settings_changed_initialized)
         pthread_cond_destroy(&timer->settings_changed);
   }

   return result;
}
开发者ID:SylvainGarrigues,项目名称:userland,代码行数:82,代码来源:vcos_pthreads.c


示例2: file


//.........这里部分代码省略.........
    //
    smControl->sharedMemorySegmentSize = sharedMemorySegmentSize;
    smControl->currentOffset           = smSize;
    smControl->currentSize             = sharedMemorySegmentSize - smSize;
    smControl->systemInitialized       = 0;

    //
    //  Create the mutex attribute initializer that we can use to initialize
    //  all of the mutexes in the B-trees.
    //
    pthread_mutexattr_t* mutexAttributes = &smControl->masterMutexAttributes;

    status =  pthread_mutexattr_init ( mutexAttributes );
    if ( status != 0 )
    {
        printf ( "Unable to initialize mutex attributes - errno: %u[%m].\n",
                 status );
        return 0;
    }
    //
    // Set this mutex to be a process shared mutex.
    //
    status = pthread_mutexattr_setpshared ( mutexAttributes,
                                            PTHREAD_PROCESS_SHARED );
    if ( status != 0 )
    {
        printf ( "Unable to set shared mutex attribute - errno: %u[%m].\n",
                 status );
        return 0;
    }
    //
    // Set this mutex to be a recursive mutex.
    //
    status = pthread_mutexattr_settype ( mutexAttributes,
                                         PTHREAD_MUTEX_RECURSIVE );
    if ( status != 0 )
    {
        printf ( "Unable to set recursive mutex attribute - errno: %u[%m].\n",
                 status );
        return 0;
    }
    //
    //  Create the condition variable initializer that we can use to
    //  initialize all of the condition variables in the shared memory
    //  segment.
    //
    pthread_condattr_t* conditionVariableAttributes =
        &smControl->masterCvAttributes;

    status = pthread_condattr_init ( conditionVariableAttributes );

    if ( status != 0 )
    {
        printf ( "Unable to initialize condition variable attributes - "
                 "errno: %u[%m].\n", status );
        return 0;
    }
    //
    //  Set this condition variable to be shared between processes.
    //
    status = pthread_condattr_setpshared ( conditionVariableAttributes,
                                           PTHREAD_PROCESS_SHARED );
    if ( status != 0 )
    {
        printf ( "Unable to set shared condition variable attributes - "
                 "errno: %u[%m].\n", status );
开发者ID:GENIVI,项目名称:vehicle_signal_interface,代码行数:67,代码来源:sharedMemory.c


示例3: open_app_log

void open_app_log() {
	pthread_mutexattr_t attr;
	pthread_mutexattr_init(&attr);
	pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
	pthread_mutex_init(&mutex, &attr);
}
开发者ID:crowm,项目名称:SATPI,代码行数:6,代码来源:Log.cpp


示例4: arenaAction

local void arenaAction(Arena *arena, int action)
{
	TurfStats *ts, **p_ts = P_ARENA_DATA(arena, tskey);

	if (action == AA_PRECREATE)
	{
		pthread_mutexattr_t attr;

		pthread_mutexattr_init(&attr);
		pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
		pthread_mutex_init((pthread_mutex_t*)P_ARENA_DATA(arena, mtxkey), &attr);
		pthread_mutexattr_destroy(&attr);
	}
	else if (action == AA_PRECREATE)
	{
		ts = amalloc(sizeof(TurfStats));
		*p_ts = ts;
	}

	ts = *p_ts;
	LOCK_STATUS(arena);

	if (action == AA_CREATE)
	{
		ConfigHandle c = arena->cfg;
		ts->maxHistory = config->GetInt(c, "TurfStats", "MaxHistory", 0);
		if (ts->maxHistory<0)
			ts->maxHistory = 0;
		ts->statsOnDing = config->GetInt(c, "TurfStats", "StatsOnDing", 1);
		if (ts->statsOnDing<1)
			ts->statsOnDing=1;

		ts->dingCount = 0;
		ts->numStats = 0;
		LLInit(&ts->stats); /* initalize list of stats */
	}
	else if (action == AA_DESTROY)
	{
		/* free history array */
		clearHistory(arena);

		/* might as well, just in case to be safe */
		ts->numStats = 0;
		ts->dingCount = 0;
	}
	else if (action == AA_CONFCHANGED)
	{
		int newMaxHistory;
		ConfigHandle c = arena->cfg;

		ts->statsOnDing = config->GetInt(c, "TurfStats", "StatsOnDing", 1);
		if (ts->statsOnDing<1)
			ts->statsOnDing=1;

		newMaxHistory = config->GetInt(c, "TurfStats", "MaxHistory", 0);
		if (newMaxHistory < 0)
			newMaxHistory = 0;  /* max history must be >= 0 */
		if (newMaxHistory != ts->maxHistory)
		{
			ts->maxHistory = newMaxHistory;

			/* erase history */
			clearHistory(arena);
		}
	}

	UNLOCK_STATUS(arena);

	if (action == AA_DESTROY)
	{
		afree(ts);
	}
	else if (action == AA_POSTDESTROY)
	{
		pthread_mutex_destroy((pthread_mutex_t*)P_ARENA_DATA(arena, mtxkey));
	}
}
开发者ID:Ceiu,项目名称:hyperspace-asss,代码行数:77,代码来源:turf_stats.c


示例5: main

int main (int argc, char *argv[])
{

#ifdef PTHREADS
  int ret;
  pthread_attr_t  attr;
  pthread_t       tid1, tid2, tid3;
  pthread_mutexattr_t Attr;
  pthread_mutexattr_init(&Attr);
  pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_ERRORCHECK);
  if (pthread_mutex_init(&mutexsum, &Attr)) {
    printf("Error while using pthread_mutex_init\n");
  }
#endif /* PTHREADS */

#ifdef TAU_MPI
  int rc = MPI_SUCCESS;
#if defined(PTHREADS)
  rc = MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
  printf("MPI_Init_thread: provided = %d, MPI_THREAD_MULTIPLE=%d\n", provided, MPI_THREAD_MULTIPLE);
#elif defined(TAU_OPENMP)
  rc = MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided);
  printf("MPI_Init_thread: provided = %d, MPI_THREAD_FUNNELED=%d\n", provided, MPI_THREAD_FUNNELED);
#else
  rc = MPI_Init(&argc, &argv);
#endif /* THREADS */
  if (rc != MPI_SUCCESS) {
    char *errorstring;
    int length = 0;
    MPI_Error_string(rc, errorstring, &length);
    printf("Error: MPI_Init failed, rc = %d\n%s\n", rc, errorstring);
    exit(1);
  }
#endif /* TAU_MPI */

#ifdef PTHREADS
  if (ret = pthread_create(&tid1, NULL, threaded_func, NULL) )
  {
    printf("Error: pthread_create (1) fails ret = %d\n", ret);
    exit(1);
  }

  if (ret = pthread_create(&tid2, NULL, threaded_func, NULL) )
  {
    printf("Error: pthread_create (2) fails ret = %d\n", ret);
    exit(1);
  }

  if (ret = pthread_create(&tid3, NULL, threaded_func, NULL) )
  {
    printf("Error: pthread_create (3) fails ret = %d\n", ret);
    exit(1);
  }

#endif /* PTHREADS */

  /* On thread 0: */
  int i;
  //for (i = 0 ; i < 100 ; i++) {
  do_work();
  //}

#ifdef PTHREADS
  if (ret = pthread_join(tid1, NULL) )
  {
    printf("Error: pthread_join (1) fails ret = %d\n", ret);
    exit(1);
  }

  if (ret = pthread_join(tid2, NULL) )
  {
    printf("Error: pthread_join (2) fails ret = %d\n", ret);
    exit(1);
  }

  if (ret = pthread_join(tid3, NULL) )
  {
    printf("Error: pthread_join (3) fails ret = %d\n", ret);
    exit(1);
  }

  pthread_mutex_destroy(&mutexsum);
#endif /* PTHREADS */

#ifdef TAU_MPI
  MPI_Finalize();
#endif /* TAU_MPI */
  printf ("Done.\n");

  return 0;
}
开发者ID:ParaToolsInc,项目名称:taucmdr,代码行数:91,代码来源:matmult.c


示例6: QMutex

GroupManager::GroupManager(NdnMediaProcess *pNdnMediaPro) {

	ruMutex = new QMutex(QMutex::Recursive);
	pthread_mutexattr_init(&attr);
	pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
	pthread_mutex_init(&gm_mutex, &attr);
    pGroupManager = this;

    this->pNdnMediaPro = pNdnMediaPro;

	QDomDocument settings;
	QString configFileName = QDir::homePath() + "/" + \
							".actd" + "/" + ".config";
	QFile config(configFileName);
	if (!config.exists()) 
		critical("Config file does not exist!");
	
	if (!config.open(QIODevice::ReadOnly))
		critical("Can not open config file!");
	
	if (!settings.setContent(&config)) {
		config.close();
		critical("can not parse config file!");
	}
	config.close();
	
	QDomElement docElem = settings.documentElement(); //<config>
	QDomNode n = docElem.firstChild();

	isPrivate = false;
	QString qsConfKey;
	QString qsSessionKey;
	QByteArray qbaSK;
	while(!n.isNull()) {
		if (n.nodeName() == "prefix") {
			prefix = n.toElement().text();
		} else if (n.nodeName() == "confName") {
			confName = n.toElement().text();
		} else if (n.nodeName() == "channelName") {
		} else if (n.nodeName() == "private") {
			QString p = n.toElement().text();
			if (p == "true")
				isPrivate = true;
			else
				isPrivate = false;
		} else if (n.nodeName() == "confKey" && isPrivate) {
			qsConfKey = n.toElement().text();
			QByteArray qbaCK = \
				QByteArray::fromBase64(qsConfKey.toLocal8Bit()); 
			memcpy(conferenceKey, qbaCK.data(), qbaCK.size());
		} else if (n.nodeName() == "sessionKey" && isPrivate) {
			qsSessionKey = n.toElement().text();
			qbaSK = \
				QByteArray::fromBase64(qsSessionKey.toLocal8Bit());

		} else {
			debug("unknown atrribute in config file!");
		}
		n = n.nextSibling();

	}

	if (confName.isEmpty())
		critical("no confName in config!");
	
	if (isPrivate && (qsConfKey.isEmpty() || qsSessionKey.isEmpty()))
		isPrivate = false;
	
	if (isPrivate) {
		pNdnMediaPro->setPrivate();
		pNdnMediaPro->setSK(qbaSK);
	}

	ndnContext();
	
    localUser = NULL;

    // ui_session id for remoteUsers
	// 5000 at maximum
    for (int i = 5001; i < 10000; ++i)
        qqRSesIds.enqueue(i);

}
开发者ID:FreshLeaf8865,项目名称:mumble,代码行数:83,代码来源:GroupManager.cpp


示例7: pthread_mutexattr_init

#include "OperateDiskProc.h"
#include "transfers_base.h"
#include "netManager.h"

#include "LOGCTRL.h"
//#define NO_POS_DEBUG
#include "pos_debug.h"

static	INT8 tmpBuff[MAX_SEND_BUF_LEN];


#if SKJ_PTHREAD_KPMUTEX_OPEN == 1
pthread_mutex_t *g_skjkpmutex = new pthread_mutex_t;
pthread_mutexattr_t skjmattr;
int skjret = pthread_mutexattr_init(&skjmattr);
int skjret1 = pthread_mutexattr_settype(&skjmattr, PTHREAD_MUTEX_RECURSIVE_NP);
int skjret2 = pthread_mutex_init(g_skjkpmutex, &skjmattr);
int skjret3 = pthread_mutexattr_destroy(&skjmattr);
//static pthread_mutex_t	g_skjkpmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
#endif


CYWXmlBase::CYWXmlBase(CYWXML_GY &ywxml_gy):m_ywxml_gy(ywxml_gy)
{
	m_ywlx = ywxml_gy.m_strID;
	m_servip = "";
	m_servport = "";
	m_servpath = "";
	m_pin = "";
	m_Err = "";
	m_nsrsbh = "";
开发者ID:xiongshaogang,项目名称:CJ_APE4000R_ZL_1.0000,代码行数:31,代码来源:YWXmlBase.cpp


示例8: mutex

 mutex(int type = PTHREAD_MUTEX_DEFAULT) {
   pthread_mutexattr_t attr;
   pthread_mutexattr_init(&attr);
   pthread_mutexattr_settype(&attr, type);
   pthread_mutex_init(&_mutex, &attr);
 }
开发者ID:AndyGreenwell,项目名称:Jellyfish,代码行数:6,代码来源:locks_pthread.hpp


示例9: pthread_sigmask

/* Test function -- This one calls pthread_mutex_trylock and check that no EINTR is returned. */
void *test(void *arg)
{
	int ret = 0;
	int i;
	long pshared;
	pthread_mutex_t mtx[NSCENAR + 2];
	pthread_mutexattr_t ma[NSCENAR + 1];

	/* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */
	ret = pthread_sigmask(SIG_UNBLOCK, &usersigs, NULL);
	if (ret != 0) {
		UNRESOLVED(ret,
			   "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread");
	}

	/* System abilities */
	pshared = sysconf(_SC_THREAD_PROCESS_SHARED);

	/* Initialize the mutex objects according to the scenarii */
	for (i = 0; i < NSCENAR; i++) {
		ret = pthread_mutexattr_init(&ma[i]);
		if (ret != 0) {
			UNRESOLVED(ret,
				   "[parent] Unable to initialize the mutex attribute object");
		}
#ifndef WITHOUT_XOPEN
		/* Set the mutex type */
		ret = pthread_mutexattr_settype(&ma[i], scenarii[i].m_type);
		if (ret != 0) {
			UNRESOLVED(ret, "[parent] Unable to set mutex type");
		}
#endif
		/* Set the pshared attributes, if supported */
		if ((pshared > 0) && (scenarii[i].m_pshared != 0)) {
			ret =
			    pthread_mutexattr_setpshared(&ma[i],
							 PTHREAD_PROCESS_SHARED);
			if (ret != 0) {
				UNRESOLVED(ret,
					   "[parent] Unable to set the mutex process-shared");
			}
		}

		/* Initialize the mutex */
		ret = pthread_mutex_init(&mtx[i], &ma[i]);
		if (ret != 0) {
			UNRESOLVED(ret, "[parent] Mutex init failed");
		}

	}
	/* Default mutexattr object */
	ret = pthread_mutexattr_init(&ma[i]);
	if (ret != 0) {
		UNRESOLVED(ret,
			   "[parent] Unable to initialize the mutex attribute object");
	}
	ret = pthread_mutex_init(&mtx[i], &ma[i]);
	if (ret != 0) {
		UNRESOLVED(ret, "[parent] Mutex init failed");
	}
	/* Default mutex */
	ret = pthread_mutex_init(&mtx[i + 1], NULL);
	if (ret != 0) {
		UNRESOLVED(ret, "[parent] Mutex init failed");
	}

	/* do the real testing */
	while (do_it) {
		count_ope++;

		ret = pthread_mutex_trylock(&mtx[count_ope % (NSCENAR + 2)]);
		if (ret == EINTR) {
			FAILED("EINTR was returned");
		}
		if (ret != 0) {
			UNRESOLVED(ret, "1st trylock failed");
		}

		ret = pthread_mutex_trylock(&mtx[count_ope % (NSCENAR + 2)]);
		if (ret == EINTR) {
			FAILED("EINTR was returned");
		}
		if (ret == 0) {
			ret =
			    pthread_mutex_unlock(&mtx
						 [count_ope % (NSCENAR + 2)]);
			if (ret != 0) {
				UNRESOLVED(ret, "Unlocking the mutex failed");
			}
			ret = EBUSY;
		}
		if (ret != EBUSY) {
			UNRESOLVED(ret, "Unexpected error was returned.");
		}

		ret = pthread_mutex_unlock(&mtx[count_ope % (NSCENAR + 2)]);
		if (ret != 0) {
			UNRESOLVED(ret, "Failed to unlock the mutex");
		}
//.........这里部分代码省略.........
开发者ID:1587,项目名称:ltp,代码行数:101,代码来源:4-3.c


示例10: recursive_mutex_test

void recursive_mutex_test(void)
{
  pthread_t thread[NTHREADS];
#ifdef SDCC
  pthread_addr_t result[NTHREADS];
  pthread_attr_t attr;
#endif
  pthread_mutexattr_t mattr;
  int type;
  int status;
  int i;

  /* Initialize the mutex attributes */

  pthread_mutexattr_init(&mattr);
  status = pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE);
  if (status != 0)
    {
      printf("recursive_mutex_test: ERROR pthread_mutexattr_settype failed, status=%d\n", status);
    }

  status = pthread_mutexattr_gettype(&mattr, &type);
  if (status != 0)
    {
      printf("recursive_mutex_test: ERROR pthread_mutexattr_gettype failed, status=%d\n", status);
    }
  if (type != PTHREAD_MUTEX_RECURSIVE)
    {
      printf("recursive_mutex_test: ERROR pthread_mutexattr_gettype return type=%d\n", type);
    }

  /* Initialize the mutex */

  printf("recursive_mutex_test: Initializing mutex\n");
  status = pthread_mutex_init(&mut, &mattr);
  if (status != 0)
    {
      printf("recursive_mutex_test: ERROR pthread_mutex_init failed, status=%d\n", status);
    }

  /* Start the threads -- all at the same, default priority */

  for (i = 0; i < NTHREADS; i++)
    {
      printf("recursive_mutex_test: Starting thread %d\n", i+1);
#ifdef SDCC
      (void)pthread_attr_init(&attr);
      status = pthread_create(&thread[i], &attr, thread_outer, (pthread_addr_t)i+1);
#else
      status = pthread_create(&thread[i], NULL, thread_outer, (pthread_addr_t)i+1);
#endif
      if (status != 0)
        {
          printf("recursive_mutex_test: ERROR thread#%d creation: %d\n", i+1, status);
        }
    }

  /* Wait for all; of the threads to complete */

  for (i = 0; i < NTHREADS; i++)
    {
      printf("recursive_mutex_test: Waiting for thread %d\n", i+1);
#ifdef SDCC
      pthread_join(thread[i], &result[i]);
#else
      pthread_join(thread[i], NULL);
#endif
    }

  printf("recursive_mutex_test: Complete\n");
}
开发者ID:JforGitHub,项目名称:thingsee-sdk,代码行数:71,代码来源:rmutex.c


示例11: pthread_mutexattr_init

TInt CTestSemtrywait::TestSem392( )
	{
	
	int errsum=0, err = 0;
	int retval = 0;
	ThreadData lThreadData;

	sem_t lSignalSemaphore;
	sem_t lSuspendSemaphore;

	sem_t           lTestSemaphore;
	pthread_mutex_t lTestMutex;
	pthread_cond_t  lTestCondVar;
	pthread_condattr_t  lCondAttr;
	pthread_mutexattr_t lTestMutexAttr;

	pthread_mutexattr_t defaultattr;
	pthread_mutexattr_t errorcheckattr;
	pthread_mutexattr_t recursiveattr;

	pthread_mutexattr_init(&defaultattr);
	pthread_mutexattr_init(&errorcheckattr);
	pthread_mutexattr_init(&recursiveattr);

	pthread_mutexattr_settype(&errorcheckattr,PTHREAD_MUTEX_ERRORCHECK);
	pthread_mutexattr_settype(&recursiveattr,PTHREAD_MUTEX_RECURSIVE);


	pthread_mutex_t l_staticmutex = PTHREAD_MUTEX_INITIALIZER;
	pthread_mutex_t l_errorcheckmutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
	pthread_mutex_t l_recursivemutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
    pthread_cond_t  l_staticcondvar = PTHREAD_COND_INITIALIZER;


    CommonData lCommonData;
    lCommonData.iStaticMutex = &l_staticmutex;
	lCommonData.iErrorCheckMutex = &l_errorcheckmutex;
	lCommonData.iRecursiveMutex = &l_recursivemutex;
	lCommonData.iStaticCondVar = &l_staticcondvar;

	retval = sem_init(&lSignalSemaphore,0,0);
	if(retval != 0)
		{
		return retval;
		}

	retval = sem_init(&lSuspendSemaphore,0,0);
	if(retval != 0)
		{
		return retval;
		}

	lThreadData.iSignalSemaphore = &lSignalSemaphore;
	lThreadData.iSuspendSemaphore = &lSuspendSemaphore;
	lThreadData.iTestSemaphore   = &lTestSemaphore;
	lThreadData.iTestMutex       = &lTestMutex;
	lThreadData.iTestMutexAttr   = &lTestMutexAttr;
	lThreadData.iTestCondVar     = &lTestCondVar;
	lThreadData.iDefaultAttr     = &defaultattr;
	lThreadData.iErrorcheckAttr = &errorcheckattr;
	lThreadData.iRecursiveAttr   = &recursiveattr;

	lThreadData.iCondAttr        = &lCondAttr;
	for (int loop = 0; loop < EThreadMain; loop++)
		{
	    g_spinFlag[loop] = true;
		}
	lThreadData.iSuspending      = false;
	lThreadData.iSpinCounter     = 0;
	lThreadData.iCurrentCommand  = -1;
	lThreadData.iSelf            = EThreadMain;
	lThreadData.iValue           = 0;
	lThreadData.iRetValue        = 0;
	lThreadData.ierrno           = 0;
	lThreadData.iExpectederrno   = 0;
	lThreadData.iTimes           = 0;
	lThreadData.iStopped         = false;
	lThreadData.iCommonData      = &lCommonData;

	retval = SemInit(&lThreadData);
	
	fp=func2;
	retval = ThreadCreate(&lThreadData, (void*) EThread1);
	
	fp=func4;
	retval = ThreadCreate(&lThreadData, (void*) EThread2);

	retval = SemPost(&lThreadData);
	retval = ThreadDestroy(&lThreadData, (void*) EThread1);
	retval = ThreadDestroy(&lThreadData, (void*) EThread2);
	retval = SemDestroy(&lThreadData);
	StopThread(&lThreadData);
	
	err = pthread_cond_destroy(&l_staticcondvar);
	if(err != EINVAL)
		{
		errsum += err;
		}
    err = pthread_mutex_destroy(&l_recursivemutex);
	if(err != EINVAL)
//.........这里部分代码省略.........
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:101,代码来源:tsemtrywaitcases.cpp


示例12: __taskInit

static STATUS __taskInit(struct wind_task *task,
			 struct WIND_TCB *tcb, const char *name,
			 int prio, int flags, FUNCPTR entry, int stacksize)
{
	struct threadobj_init_data idata;
	pthread_mutexattr_t mattr;
	struct sched_param param;
	pthread_attr_t thattr;
	int ret, cprio;

	ret = check_task_priority(prio, &cprio);
	if (ret) {
		errno = ret;
		return ERROR;
	}

	if (name == NULL || *name == '\0')
		sprintf(task->name, "t%lu", ++anon_tids);
	else {
		strncpy(task->name, name, sizeof(task->name));
		task->name[sizeof(task->name) - 1] = '\0';
	}

	__RT(pthread_mutexattr_init(&mattr));
	__RT(pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE));
	__RT(pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT));
	__RT(pthread_mutexattr_setpshared(&mattr, mutex_scope_attribute));
	__RT(pthread_mutex_init(&task->safelock, &mattr));
	__RT(pthread_mutexattr_destroy(&mattr));

	task->tcb = tcb;
	tcb->opaque = task;
	/*
	 * CAUTION: tcb->status in only modified by the owner task
	 * (see suspend/resume hooks), or when such task is guaranteed
	 * not to be running, e.g. in taskActivate(). So we do NOT
	 * take any lock specifically for updating it. However, we
	 * know that a memory barrier will be issued shortly after
	 * such updates because of other locking being in effect, so
	 * we don't explicitely have to provide for it.
	 */
	tcb->status = WIND_SUSPEND;
	tcb->safeCnt = 0;
	tcb->flags = flags;
	tcb->entry = entry;

	pthread_attr_init(&thattr);

	if (stacksize == 0)
		stacksize = PTHREAD_STACK_MIN * 4;
	else if (stacksize < PTHREAD_STACK_MIN)
		stacksize = PTHREAD_STACK_MIN;

	memset(&param, 0, sizeof(param));
	param.sched_priority = cprio;
	pthread_attr_setinheritsched(&thattr, PTHREAD_EXPLICIT_SCHED);
	pthread_attr_setschedpolicy(&thattr, SCHED_RT);
	pthread_attr_setschedparam(&thattr, &param);
	pthread_attr_setstacksize(&thattr, stacksize);
	pthread_attr_setscope(&thattr, thread_scope_attribute);
	pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);

	idata.magic = task_magic;
	idata.wait_hook = task_wait_hook;
	idata.suspend_hook = task_suspend_hook;
	idata.finalizer = task_finalizer;
	idata.priority = cprio;
	threadobj_init(&task->thobj, &idata);

	ret = __bt(cluster_addobj(&wind_task_table, task->name, &task->cobj));
	if (ret) {
		warning("duplicate task name: %s", task->name);
		threadobj_destroy(&task->thobj);
		__RT(pthread_mutex_destroy(&task->safelock));
		errno = S_objLib_OBJ_ID_ERROR;
		return ERROR;
	}

	registry_init_file(&task->fsobj, &registry_ops);

	ret = __bt(-__RT(pthread_create(&task->thobj.tid, &thattr,
					&task_trampoline, task)));
	pthread_attr_destroy(&thattr);
	if (ret) {
		registry_destroy_file(&task->fsobj);
		cluster_delobj(&wind_task_table, &task->cobj);
		threadobj_destroy(&task->thobj);
		__RT(pthread_mutex_destroy(&task->safelock));
		errno = ret == -EAGAIN ? S_memLib_NOT_ENOUGH_MEMORY : -ret;
		return ERROR;
	}

	return OK;
}
开发者ID:BhargavKola,项目名称:xenomai-forge,代码行数:94,代码来源:taskLib.c


示例13: init

 void init() {
   pthread_mutexattr_t attr;
   pthread_mutexattr_init(&attr);
   pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   assert(pthread_mutex_init(&native_, &attr) == 0);
 }
开发者ID:stormbrew,项目名称:rubinius,代码行数:6,代码来源:thread.hpp


示例14: log_init

int log_init()
{
	time_t t;
	struct tm tm;
	int result = 0;
	int log_thread_lock_init = 0, disk_thread_lock_init = 0, disk_thread_cond_init = 0;

	pthread_mutexattr_t mtxAttr;
	pthread_t disk_pthread_id;
	pthread_attr_t thread_attr;

	if (logger_init_flag) {
		fprintf(stderr, "logger module has already been init!!\n");
		return 1;
	}

	do {
		pContext = (LogContext *)malloc(sizeof(LogContext));

		if (pContext == NULL) {
			fprintf(stderr, "malloc %lu bytes fail, errno: %d, error info: %s", sizeof(LogContext), errno, STRERROR(errno));
			return (errno != 0) ? errno : ENOMEM;
		}

		log_level = LOG_INFO;

		pContext->log_fd = STDERR_FILENO;
		pContext->log_base_path = NULL;
		pContext->log_filename_prefix = NULL;
		pContext->log_to_cache = false;
		pContext->logrotate_cycle = ROTATE_CYCLE_DAY;

		/* 初始化日志buff */
		pContext->log_buff = (char *)malloc(LOG_BUFF_SIZE);

		if (pContext->log_buff == NULL) {
			fprintf(stderr, "malloc %d bytes fail, errno: %d, error info: %s", LOG_BUFF_SIZE, errno, STRERROR(errno));
			result = (errno != 0) ? errno : ENOMEM;
			break;
		}

		pContext->pcurrent_buff = pContext->log_buff;

		/* 设置锁为纠错锁, 同一线程不能重复加锁, 加上的锁只能由本线程解锁. 先等待锁的线程先获得锁 */
		pthread_mutexattr_init(&mtxAttr);
		pthread_mutexattr_settype(&mtxAttr, PTHREAD_MUTEX_ERRORCHECK_NP);

		if ((result = pthread_mutex_init(&(pContext->log_thread_lock), &mtxAttr)) != 0) {
			fprintf(stderr, "call pthread_mutex_init fail, errno: %d, error info: %s", result, STRERROR(result));
			break;
		}

		pthread_mutexattr_destroy(&mtxAttr);
		log_thread_lock_init = 1;

		/* 初始化写磁盘线程上下文 */
		if ((result = pthread_mutex_init(&(pContext->disk_thread_ctx.disk_thread_lock), NULL)) != 0) {
			fprintf(stderr, "call pthread_mutex_init fail, errno: %d, error info: %s", result, STRERROR(result));
			break;
		}

		disk_thread_lock_init = 1;

		if ((result = pthread_cond_init(&(pContext->disk_thread_ctx.disk_thread_cond), NULL)) != 0) {
			fprintf(stderr, "call pthread_cond_init fail, errno: %d, error info: %s", result, STRERROR(result));
			break;
		}

		disk_thread_cond_init = 1;

		pContext->disk_thread_ctx.disk_thread_stop = false;
		pContext->disk_thread_ctx.blocking_queue = new std::deque<std::string>;

		/* 启动磁盘线程 */
		pthread_attr_init(&thread_attr);
		pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);

		if ((result = pthread_create(&disk_pthread_id, &thread_attr, disk_write_thread, NULL)) != 0) {
			fprintf(stderr, "call pthread_create fail, errno: %d, error info: %s", result, STRERROR(result));
			break;
		}

		pContext->disk_thread_ctx.disk_pthread_id = disk_pthread_id;
		pthread_attr_destroy(&thread_attr);

		/* 等待磁盘线程运行成功 */
		pthread_mutex_init(&thread_init_lock, NULL);
		pthread_cond_init(&thread_init_cond, NULL);

		pthread_mutex_lock(&thread_init_lock);
		while (!thread_init_flag) {
			pthread_cond_wait(&thread_init_cond, &thread_init_lock);	
		}
		pthread_mutex_unlock(&thread_init_lock);

		/* 记录当前时间 */
		t = time(NULL);
		localtime_r(&t, &tm);

		switch (pContext->logrotate_cycle) {
//.........这里部分代码省略.........
开发者ID:KashingLee,项目名称:log-module,代码行数:101,代码来源:logger.cpp


示例15: pthread_mutexattr_init

void eMP3Decoder::init_eMP3Decoder(const char* filename)
{
	state=stateInit;

	pthread_mutexattr_t attr;
	pthread_mutexattr_init(&attr);
	pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
	pthread_mutex_init(&lock, &attr);
	pthread_mutexattr_destroy(&attr);

	http=0;

	seekbusy=0;

//	filename="http://205.188.209.193:80/stream/1003";

//	filename="http://sik1.oulu.fi:8002/";
//	filename="http://64.236.34.141:80/stream/1022";
//	filename="http://ios.h07.org:8006/";
//	filename="http://10.0.0.112/join.mp3";
	
	if (strstr(filename, "://")) // assume streaming
	{
		if (!strncmp(filename, "file://", 7))
			filename+=7;
		else
		{
			http=eHTTPConnection::doRequest(filename, this, &error);
			if (!http)
			{
				streamingDone(error);
			} else
			{
				CONNECT(http->transferDone, eMP3Decoder::streamingDone);
				CONNECT(http->createDataSource, eMP3Decoder::createStreamSink);
				http->local_header["User-Agent"]="enigma-mp3/1.0.0";
				http->local_header["Icy-MetaData"]="1"; // enable ICY metadata
				http->start();
				http_status=_("Connecting...");
				filelength=-1;
				handler->messages.send(eServiceHandlerMP3::eMP3DecoderMessage(eServiceHandlerMP3::eMP3DecoderMessage::status));
			}
			filename=0;
		}
	}
	
	if (filename) // not streaming
	{
		sourcefd=::open(filename, O_RDONLY|O_LARGEFILE);
		if (sourcefd<0)
		{
			error=errno;
			eDebug("error opening %s", filename);
			state=stateError;
		} else
		{
			filelength=lseek64(sourcefd, 0, SEEK_END);
			lseek(sourcefd, 0, SEEK_SET);
		}
	} else
		sourcefd=-1;
	
	length=-1;
	Decoder::Flush();
	if (type != codecMPG)
	{
		divisor=1;
		pcmsettings.reconfigure=1;
		dspfd[1]=-1;

		dspfd[0]=::open("/dev/dsp", O_WRONLY|O_NONBLOCK);
		if (dspfd[0]<0)
		{
			eDebug("output failed! (%m)");
			error=errno;
			state=stateError;
		}
	
		if (dspfd[0] >= 0)
		{
			outputsn[0]=new eSocketNotifier(this, dspfd[0], eSocketNotifier::Write, 0);
			CONNECT(outputsn[0]->activated, eMP3Decoder::outputReady);
		} else
			outputsn[0]=0;
		outputsn[1]=0;
	} else
	{
		divisor=1024;
		Decoder::parms.vpid=0x1FFF;
		Decoder::parms.apid=0x1FFF;
		Decoder::parms.pcrpid=-1;
		Decoder::parms.audio_type=DECODE_AUDIO_MPEG;
		Decoder::Set();

		dspfd[0]=::open("/dev/video0", O_WRONLY);
		dspfd[1]=::open("/dev/dsp", O_WRONLY);

		if ((dspfd[0]<0) || (dspfd[1]<0))
		{
			if (dspfd[0]>=0)
//.........这里部分代码省略.........
开发者ID:TitanNit,项目名称:tdt,代码行数:101,代码来源:servicemp3.cpp


示例16: main


//.........这里部分代码省略.........
		if (write (fd, tmp, sz) != (ssize_t) sz)
		{ UNRESOLVED(sz, "Writting to the file failed"); }

		free(tmp);

		/* Now we can map the file in memory */
		mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
		if (mmaped == MAP_FAILED)
		{ UNRESOLVED(errno, "mmap failed"); }

		td = (testdata_t *) mmaped;

		/* Our datatest structure is now in shared memory */
		#if VERBOSE > 1
		output("Testdata allocated in shared memory.\n");
		#endif
	}

/**********
 * For each test scenario, initialize the attributes and other variables.
 * Do the whole thing for each time to test.
 */
	for (sc=0; sc < NSCENAR ; sc++)
	{
		#if VERBOSE > 1
		output("[parent] Preparing attributes for: %s\n", scenarii[sc].descr);
		#endif
		/* set / reset everything */
		do_fork=0;
		ret = pthread_mutexattr_init(&ma);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object");  }

		/* Set the mutex type */
		ret = pthread_mutexattr_settype(&ma, scenarii[sc].m_type);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to set mutex type");  }
		#if VERBOSE > 1
		output("[parent] Mutex type : %i\n", scenarii[sc].m_type);
		#endif

		/* Set the pshared attributes, if supported */
		if ((pshared > 0) && (scenarii[sc].m_pshared != 0))
		{
			ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED);
			if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to set the mutex process-shared");  }
			#if VERBOSE > 1
			output("[parent] Mutex is process-shared\n");
			#endif
		}
		#if VERBOSE > 1
		else {
			output("[parent] Mutex is process-private\n");
		}
		#endif

		/* Tell whether the test will be across processes */
		if ((pshared > 0) && (scenarii[sc].fork != 0))
		{
			do_fork = 1;
			#if VERBOSE > 1
			output("[parent] Child will be a new process\n");
			#endif
		}
		#if VERBOSE > 1
		else {
			output("[parent] Child will be a new thread\n");
		}
开发者ID:barajas,项目名称:Intel-GLTP,代码行数:67,代码来源:2-1.c


示例17: pthread_mutexattr_setkind_np

int
pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr, int kind)
{
  return pthread_mutexattr_settype( attr, kind );
}
开发者ID:A-Massarella,项目名称:Botnet,代码行数:5,代码来源:pthread_mutexattr_setkind_np.c


示例18: do_threads_test

/**** do_threads_test
 * This function is responsible for all the testing with a given # of threads
 *  nthreads is the amount of threads to create.
 * the return value is:
 *  < 0 if function was not able to create enough threads.
 *  cumulated # of nanoseconds otherwise.
 */
long do_threads_test(int nthreads, mes_t * measure)
{
	int ret;

	int scal, i, j;

	pthread_t *th;

	int s;
	pthread_mutexattr_t ma;
	pthread_condattr_t ca;

	pthread_cond_t cnd;
	pthread_mutex_t mtx;
	int predicate;
	int tnum;

	test_t td;

	struct timespec ts, ts_cumul;

	td.mtx = &mtx;
	td.cnd = &cnd;
	td.predicate = &predicate;
	td.tnum = &tnum;

	/* Allocate space for the threads structures */
	th = (pthread_t *)calloc(nthreads, sizeof(pthread_t));
	if (th == NULL)  {  UNRESOLVED(errno, "Not enough memory for thread storage");  }

	#ifdef PLOT_OUTPUT
	output("%d", nthreads);
	#endif
	/* For each test scenario (mutex and cond attributes) */
	for (s=0; s < NSCENAR ; s++)
	{
		/* Initialize the attributes */
		ret = pthread_mutexattr_init(&ma);
		if (ret != 0)  {  UNRESOLVED(ret, "Unable to initialize mutex attribute object");  }

		ret = pthread_condattr_init(&ca);
		if (ret != 0)  {  UNRESOLVED(ret, "Unable to initialize cond attribute object");  }

		/* Set the attributes according to the scenar and the impl capabilities */
		ret = pthread_mutexattr_settype(&ma, test_scenar[s].mutex_type);
		if (ret != 0)  {  UNRESOLVED(ret, "Unable to set mutex type");  }

		if (pshared_ok > 0)
		{
			ret = pthread_mutexattr_setpshared(&ma, test_scenar[s].pshared);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to set mutex process-shared");  }

			ret = pthread_condattr_setpshared(&ca, test_scenar[s].pshared);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to set cond process-shared");  }
		}

		#ifdef USE_ALTCLK
		if (altclk_ok > 0)
		{
			ret = pthread_condattr_setclock(&ca, test_scenar[s].cid);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to set clock for cond");  }
		}
		#endif

		ts_cumul.tv_sec= 0;
		ts_cumul.tv_nsec=0;

		#if VERBOSE > 1
		output("Starting case %s\n", test_scenar[s].desc);
		#endif

		for (scal=0; scal <  5 * SCALABILITY_FACTOR; scal ++)
		{
			/* Initialize the mutex, the cond, and other data */
			ret = pthread_mutex_init(&mtx, &ma);
			if (ret != 0)  {  UNRESOLVED(ret, "Mutex init failed");  }

			ret = pthread_cond_init(&cnd, &ca);
			if (ret != 0)  {  UNRESOLVED(ret, "Cond init failed");  }

			predicate = 0;
			tnum = 0;

			/* Create the waiter threads */
			for (i=0; i< nthreads; i++)
			{
				ret = pthread_create(&th[i], &ta, waiter, (void *)&td);
				if (ret != 0) /* We reached the limits */
				{
					#if VERBOSE > 1
					output("Limit reached with %i threads\n", i);
					#endif
					#ifdef USE_CANCEL
//.........这里部分代码省略.........
开发者ID:andreimironenko,项目名称:ltp-full,代码行数:101,代码来源:s-c.c


示例19: main

/** parent thread function **/
int main(int argc, char * argv[])
{
	int ret;
	int i;
	pthread_mutexattr_t ma;
	pthread_t  child;

	output_init();

	#if VERBOSE >1
	output("Initialize the PTHREAD_MUTEX_RECURSIVE mutex\n");
	#endif
	
	/* Initialize the semaphore */
	if ((ret = sem_init(&sem, 0, 0)))
	{  UNRESOLVED(ret, "Sem init failed");  }
	
	/* We initialize the recursive mutex */
	if ((ret = pthread_mutexattr_init(&ma)))
	{  UNRESOLVED(ret, "Mutex attribute init failed");  }
	
	if ((ret = pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_RECURSIVE)))
	{  UNRESOLVED(ret, "Set type RECURSIVE failed");  }
	
	if ((ret = pthread_mutex_init(&mtx, &ma)))
	{  UNRESOLVED(ret, "Recursive mutex init failed");  }
	
	if ((ret = pthread_mutexattr_destroy(&ma)))
	{  UNRESOLVED(ret, "Mutex attribute destroy failed");  }
	
	/* -- The mutex is now ready for testing -- */
	
	/* First, we lock it twice and unlock once */
	if ((ret = pthread_mutex_lock(&mtx)))
	{ UNRESOLVED(ret, "First lock failed");  }
	
	if ((ret = pthread_mutex_lock(&mtx)))
	{ FAILED("Second lock failed");  }


	
	if ((ret = pthread_mutex_unlock(&mtx)))
	{ FAILED("First unlock failed");  }

	#if VERBOSE >1
	output("The mutex has been locked twice and unlocked once, start the thread now.\n");
	#endif
	
	/* Here this thread owns the mutex and the internal count is "1" */
	
	/* We create the child thread */
	if ((ret = pthread_create(&child, NULL, threaded, NULL)))
	{  UNRESOLVED(ret, "Unable to create child thread");  }
	
	/* then wait for child to be ready */
	if ((ret = sem_wait(&sem)))
	{  UNRESOLVED(errno, "Wait sem in child failed");  }

	#if VERBOSE >1
	output("[main] unlock the mutex.\n");
	#endif
	
	/* We can now unlock the mutex */
	if ((ret = pthread_mutex_unlock(&mtx)))
	{ FAILED("Second unlock failed");  }

	/* We wait for the child to lock the mutex */
	if ((ret = sem_wait(&sem)))
	{  UNRESOLVED(errno, "Wait sem in child failed");  }

	/* Then, try to unlock the mutex (owned by the child or unlocked) */
	ret = pthread_mutex_unlock(&mtx);
	if (ret == 0)
	{ FAILED("Unlock of unowned mutex succeeds");  }
	
	/* Everything seems OK here */
	if ((ret = pthread_join(child, NULL)))
	{  UNRESOLVED(ret, "Child join failed");  }
	
	/* Simple loop to double-check */
	#if VERBOSE >1
	output("[main] joined the thread.\n");
	output("Lock & unlock the mutex 50 times.\n");
	#endif

	for (i=0; i<50; i++)
	{
		if ((ret = pthread_mutex_lock(&mtx)))
		{  FAILED("Lock fa 

鲜花

握手

雷人

路过

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

请发表评论

全部评论

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