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

C++ MutexLock函数代码示例

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

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



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

示例1: UserContains

////////////////////////////////////////////////////////////
/// Check if the user is on the list
////////////////////////////////////////////////////////////
bool UserContains(struct UserData * User)
{
	if (User != NULL)
	{
		struct UserData * Iterator;

		Iterator = UserList.First;

		MutexLock(&User->MutexData);

		while (Iterator != NULL)
		{
			MutexLock(&Iterator->MutexData);

			if (Iterator == User)
			{
				MutexUnlock(&Iterator->MutexData);
				MutexUnlock(&User->MutexData);
				return true;
			}

			MutexUnlock(&Iterator->MutexData);

			Iterator = Iterator->Next;
		}
	
		MutexUnlock(&User->MutexData);
	}

	return false;
}
开发者ID:jordanfin,项目名称:aoc,代码行数:34,代码来源:Users.c


示例2: mpThread

void* mpThread(void* _args)
{
    char *p = NULL;
    char buf[1024];
    char* args = _args ? strdup(_args) : 0;
    int n;
    int offset;
    void* data;
    for (;;)
    {
        if (data = plGetEntry(&playlist))
        {
            n = mpOpen(data, args);
        }
        else
        {
            if (!loopclip) break;
            n = mpOpen(loopclip, 0);
        }
        free(data);
        if (n) break;

        mpState = MP_PLAYING;
        MutexLock(&mpConsoleMutex);
        while (mpCommand("get_time_pos") <= 0) msleep(500);
        do
        {
            offset = 0;
            while (offset < sizeof(buf) - 1)
            {
                n = mpRead(buf + offset, sizeof(buf) - 1 - offset);
                if (n <= 0) break;
                offset += n;
                buf[offset] = 0;
                if (p = strstr(buf, "ANS_TIME_POSITION="))
                {
                    mpPos = atoi(p + 18);
                    break;
                }
            }
            // stop here when paused
            MutexUnlock(&mpConsoleMutex);
            do
            {
                msleep(500);
            }
            while (mpState == MP_PAUSED);
            MutexLock(&mpConsoleMutex);
        }
        while (mpCommand("get_time_pos") > 0);
        MutexUnlock(&mpConsoleMutex);
        ShellTerminate(&mpx);
        ShellClean(&mpx);
    }
    free(args);
    mpState = MP_IDLE;
    mpThreadHandle = 0;
    return 0;
}
开发者ID:as2120,项目名称:ZAchieve,代码行数:59,代码来源:mpd.c


示例3: UserRemove

////////////////////////////////////////////////////////////
/// Remove user from the list
////////////////////////////////////////////////////////////
void UserRemove(struct UserData * User)
{
	if (UserContains(User))
	{
		struct UserData * UserPtr;

		// Remove from the list
		MutexLock(&User->MutexData);

		// Update the previous node
		if (User->Previous == NULL)
		{
			MutexLock(&UserList.First->MutexData);
			UserPtr = UserList.First;
			UserList.First = User->Next;
		}
		else
		{
			MutexLock(&User->Previous->Next->MutexData);
			UserPtr = User->Previous->Next;
			User->Previous->Next = User->Next;
		}

		MutexUnlock(&UserPtr->MutexData);

		// Update the next node
		if (User->Next == NULL)
		{
			MutexLock(&UserList.Last->MutexData);
			UserPtr = UserList.Last;
			UserList.Last = User->Previous;
		}
		else
		{
			MutexLock(&User->Next->Previous->MutexData);
			UserPtr = User->Next->Previous;
			User->Next->Previous = User->Previous;
		}

		MutexUnlock(&UserPtr->MutexData);

		// Close the socket
		SocketClose(&User->Connection.Socket);

		// Unlock the mutex
		MutexUnlock(&User->MutexData);

		// Destroy the mutex
		MutexDestroy(&User->MutexData);

		// Delete it
		free(User);

		User = NULL;
	}
}
开发者ID:jordanfin,项目名称:aoc,代码行数:59,代码来源:Users.c


示例4: HeapAllocate

void* HeapAllocate(MemAllocHeap* heap, size_t size)
{
  bool thread_safe = 0 != (heap->m_Flags & HeapFlags::kThreadSafe);

  if (thread_safe)
  {
    MutexLock(&heap->m_Lock);
  }

  void* ptr = nullptr;
#if ENABLED(USE_DLMALLOC)
  ptr = mspace_malloc(heap->m_MemSpace, size);
#else
  ptr = malloc(size);
#endif
  if (!ptr)
  {
    Croak("out of memory allocating %d bytes", (int) size);
  }

  if (thread_safe)
  {
    MutexUnlock(&heap->m_Lock);
  }

  return ptr;
}
开发者ID:MadFishTheOne,项目名称:tundra,代码行数:27,代码来源:MemAllocHeap.cpp


示例5: MQTTDisconnect

int MQTTDisconnect(MQTTClient *c)
{
    int rc = FAILURE;
    Timer timer;     // we might wait for incomplete incoming publishes to complete
    int len = 0;

#if defined(MQTT_TASK)
    MutexLock(&c->mutex);
#endif
    TimerInit(&timer);
    TimerCountdownMS(&timer, c->command_timeout_ms);

    len = MQTTSerialize_disconnect(c->buf, c->buf_size);

    if (len > 0) {
        rc = sendPacket(c, len, &timer);    // send the disconnect packet
    }

    MQTTCloseSession(c);

#if defined(MQTT_TASK)
    MutexUnlock(&c->mutex);
#endif
    return rc;
}
开发者ID:espressif,项目名称:ESP8266_RTOS_SDK,代码行数:25,代码来源:MQTTClient.c


示例6: MQTTRun

void MQTTRun(void *parm)
{
    Timer timer;
    MQTTClient *c = (MQTTClient *)parm;

    TimerInit(&timer);

    while (1) {
        TimerCountdownMS(&timer, CONFIG_MQTT_RECV_CYCLE); /* Don't wait too long if no traffic is incoming */

#if CONFIG_MQTT_RECV_CYCLE == 0     /* The smaller cycle, the greater throughput */
        esp_task_wdt_reset();
#endif

#if defined(MQTT_TASK)
        MutexLock(&c->mutex);
#endif

        int rc = cycle(c, &timer);

        if (rc == FAILURE) {
            ESP_LOGE(TAG, "MQTTRun cycle failed");
#if defined(MQTT_TASK)
            MutexUnlock(&c->mutex);
#endif
            vTaskDelete(NULL);
        }

#if defined(MQTT_TASK)
        MutexUnlock(&c->mutex);
#endif
    }
}
开发者ID:espressif,项目名称:ESP8266_RTOS_SDK,代码行数:33,代码来源:MQTTClient.c


示例7: dsyslog

bool cRemote::PutMacro(eKeys Key)
// returns true it opens a menu
// returns false if it is a command that has no menu
{
  const cKeyMacro *km = KeyMacros.Get(Key);
  if (km) {
     keyMacroPlugin = km->Plugin();
     if(km->Command()) {
         dsyslog("Executing keymacros.conf-command: \"%s\"\n", km->Command());
         SystemExec(km->Command());
         return false;
     } else {
         cMutexLock MutexLock(&mutex);
         for (int i = km->NumKeys(); --i > 0; ) {
            if (!Put(km->Macro()[i], true))
               return true;
            }
         }
     }
  else if (Key == kTT)
      Skins.Message(mtError, tr("Teletext not available!"));
  else if (Key == kPiP)
      Skins.Message(mtError, tr("PiP not available!"));
  return true;
}
开发者ID:suborb,项目名称:reelvdr,代码行数:25,代码来源:remote.c


示例8: _audioThread

static THREAD_ENTRY _audioThread(void* context) {
	struct mPSP2AudioContext* audio = (struct mPSP2AudioContext*) context;
	uint32_t zeroBuffer[PSP2_SAMPLES] = {0};
	void* buffer = zeroBuffer;
	int audioPort = sceAudioOutOpenPort(SCE_AUDIO_OUT_PORT_TYPE_MAIN, PSP2_SAMPLES, 48000, SCE_AUDIO_OUT_MODE_STEREO);
	while (audio->running) {
		MutexLock(&audio->mutex);
		if (buffer != zeroBuffer) {
			// Can only happen in successive iterations
			audio->samples -= PSP2_SAMPLES;
			ConditionWake(&audio->cond);
		}
		if (audio->samples >= PSP2_SAMPLES) {
			buffer = &audio->buffer[audio->readOffset];
			audio->readOffset += PSP2_SAMPLES;
			if (audio->readOffset >= PSP2_AUDIO_BUFFER_SIZE) {
				audio->readOffset = 0;
			}
			// Don't mark samples as read until the next loop iteration to prevent
			// writing to the buffer while being read (see above)
		} else {
			buffer = zeroBuffer;
		}
		MutexUnlock(&audio->mutex);

		sceAudioOutOutput(audioPort, buffer);
	}
	sceAudioOutReleasePort(audioPort);
	return 0;
}
开发者ID:leiradel,项目名称:mgba,代码行数:30,代码来源:psp2-context.c


示例9: BuildQueueDestroy

  void BuildQueueDestroy(BuildQueue* queue)
  {
    Log(kDebug, "destroying build queue");
    const BuildQueueConfig* config = &queue->m_Config;

    MutexLock(&queue->m_Lock);
    queue->m_QuitSignalled = true;
    MutexUnlock(&queue->m_Lock);

    CondBroadcast(&queue->m_WorkAvailable);

    for (int i = 0, thread_count = config->m_ThreadCount; i < thread_count; ++i)
    {
      if (i > 0)
      {
        Log(kDebug, "joining with build thread %d", i);
        ThreadJoin(queue->m_Threads[i]);
      }

      ThreadStateDestroy(&queue->m_ThreadState[i]);
    }

    // Deallocate storage.
    MemAllocHeap* heap = queue->m_Config.m_Heap;
    HeapFree(heap, queue->m_ExpensiveWaitList);
    HeapFree(heap, queue->m_Queue);

    CondDestroy(&queue->m_WorkAvailable);
    MutexDestroy(&queue->m_Lock);

    // Unblock all signals on the main thread.
    SignalHandlerSetCondition(nullptr);
    SignalBlockThread(false);
  }
开发者ID:MadFishTheOne,项目名称:tundra,代码行数:34,代码来源:BuildQueue.cpp


示例10: while

void cDvbTuner::Action(void)
{
  cTimeMs Timer;
  bool LostLock = false;
  fe_status_t Status = (fe_status_t)0;
  while (Running()) {
        fe_status_t NewStatus;
        if (GetFrontendStatus(NewStatus, 10))
           Status = NewStatus;
        cMutexLock MutexLock(&mutex);
        switch (tunerStatus) {
          case tsIdle:
               break;
          case tsSet:
               tunerStatus = SetFrontend() ? tsTuned : tsIdle;
               Timer.Set(tuneTimeout);
               continue;
          case tsTuned:
               if (Timer.TimedOut()) {
                  tunerStatus = tsSet;
                  diseqcCommands = NULL;
                  if (time(NULL) - lastTimeoutReport > 60) { // let's not get too many of these
                     isyslog("frontend %d timed out while tuning to channel %d, tp %d", cardIndex, channel.Number(), channel.Transponder());
                     lastTimeoutReport = time(NULL);
                     }
                  continue;
                  }
          case tsLocked:
               if (Status & FE_REINIT) {
                  tunerStatus = tsSet;
                  diseqcCommands = NULL;
                  isyslog("frontend %d was reinitialized", cardIndex);
                  lastTimeoutReport = 0;
                  continue;
                  }
               else if (Status & FE_HAS_LOCK) {
                  if (LostLock) {
                     isyslog("frontend %d regained lock on channel %d, tp %d", cardIndex, channel.Number(), channel.Transponder());
                     LostLock = false;
                     }
                  tunerStatus = tsLocked;
                  locked.Broadcast();
                  lastTimeoutReport = 0;
                  }
               else if (tunerStatus == tsLocked) {
                  LostLock = true;
                  isyslog("frontend %d lost lock on channel %d, tp %d", cardIndex, channel.Number(), channel.Transponder());
                  tunerStatus = tsTuned;
                  Timer.Set(lockTimeout);
                  lastTimeoutReport = 0;
                  continue;
                  }
          }

        if (ciHandler)
           ciHandler->Process();
        if (tunerStatus != tsTuned)
           newSet.TimedWait(mutex, 1000);
        }
}
开发者ID:BackupTheBerlios,项目名称:macvdr-svn,代码行数:60,代码来源:dvbdevice.c


示例11: HeapReallocate

void* HeapReallocate(MemAllocHeap *heap, void *ptr, size_t size)
{
  bool thread_safe = 0 != (heap->m_Flags & HeapFlags::kThreadSafe);

  if (thread_safe)
  {
    MutexLock(&heap->m_Lock);
  }

  void *new_ptr;
#if ENABLED(USE_DLMALLOC)
  new_ptr = mspace_realloc(heap->m_MemSpace, ptr, size);
#else
  new_ptr = realloc(ptr, size);
#endif
  if (!new_ptr && size > 0)
  {
    Croak("out of memory reallocating %d bytes at %p", (int) size, ptr);
  }

  if (thread_safe)
  {
    MutexUnlock(&heap->m_Lock);
  }

  return new_ptr;
}
开发者ID:MadFishTheOne,项目名称:tundra,代码行数:27,代码来源:MemAllocHeap.cpp


示例12: MutexLock

bool cRemote::Put(eKeys Key, bool AtFront)
{
  if (Key != kNone) {
     cMutexLock MutexLock(&mutex);
     if (in != out && (keys[out] & k_Repeat) && (Key & k_Release))
        Clear();
     int d = out - in;
     if (d <= 0)
        d = MaxKeys + d;
     if (d - 1 > 0) {
        if (AtFront) {
           if (--out < 0)
              out = MaxKeys - 1;
           keys[out] = Key;
           }
        else {
           keys[in] = Key;
           if (++in >= MaxKeys)
              in = 0;
           }
        keyPressed.Broadcast();
        return true;
        }
     return false;
     }
  return true; // only a real key shall report an overflow!
}
开发者ID:Moorviper,项目名称:zen2vdr,代码行数:27,代码来源:remote.c


示例13: MutexLock

void UvdState::lock()
{
    if (m_isRealtimeMode)
    {
        MutexLock(&m_lock);
    }
}
开发者ID:rcg17,项目名称:uvdg-cocoa,代码行数:7,代码来源:UvdState.cpp


示例14: UsersDestroy

////////////////////////////////////////////////////////////
/// Destroy all users
////////////////////////////////////////////////////////////
bool UsersDestroy()
{
	struct UserData * Iterator = UserList.First;

	// Remove all users
	while (Iterator != NULL)
	{
		struct UserData * TempUser = Iterator;
		
		Iterator = Iterator->Next;

		// Close the socket
		MutexLock(&TempUser->MutexData);
		
		SocketClose(&TempUser->Connection.Socket);

		MutexUnlock(&TempUser->MutexData);

		// Destroy the mutex
		MutexDestroy(&TempUser->MutexData);

		// Free it
		free(TempUser);

		TempUser = NULL;
	}

	return true;
}
开发者ID:jordanfin,项目名称:aoc,代码行数:32,代码来源:Users.c


示例15: rwl_writer_start

/**
 *	Call this function when a writer task needs access to the data
 *	protected by the given rwlock.
 */
UInt32
rwl_writer_start( TRWLock *rwlock )
{
	/*
         *	First we check if destroy has not been called.
         *	In a propper design this test should never fail.
         */
	if ( rwlock->delflag ) return 0;

	rwlock->wcount++;

        /*
	 *	We will wait for all readers to finish.
         *	A writer must have exclusive access.
         */
        while ( rwlock->rcount )
        {
                ThreadDelay( 10 );
        }

        /*
         *	Lock mutex for exclusive access and set the writer in progress
         *	flag.
         */
        rwlock->wflag = 1;
        MutexLock( rwlock->datalock );

        /*
         *	Start writing
         */
        return 1;
}
开发者ID:LiberatorUSA,项目名称:GUCEF,代码行数:36,代码来源:gucefMT_DVRWLOCK.c


示例16: MutexLock

void cControl::Shutdown(void)
{
  cMutexLock MutexLock(&mutex);
  cControl *c = control; // avoids recursions
  control = NULL;
  delete c;
}
开发者ID:flensrocker,项目名称:vdr,代码行数:7,代码来源:player.c


示例17: debug16

void cSatipSectionStatistics::AddSectionStatistic(long bytesP, long callsP)
{
  debug16("%s (%ld, %ld)", __PRETTY_FUNCTION__, bytesP, callsP);
  cMutexLock MutexLock(&mutexM);
  filteredDataM += bytesP;
  numberOfCallsM += callsP;
}
开发者ID:nafets227,项目名称:vdr-plugin-satip,代码行数:7,代码来源:statistics.c


示例18: GBASyncLockAudio

void GBASyncLockAudio(struct GBASync* sync) {
	if (!sync) {
		return;
	}

	MutexLock(&sync->audioBufferMutex);
}
开发者ID:netux79,项目名称:mgba,代码行数:7,代码来源:sync.c


示例19: MutexLock

MUTEX * avtExecutionManager::FindMutex( const MUTEX_ID id )
{
    if (tPool == NULL)
        return NULL;

    std::map<MUTEX_ID, MUTEX *>::iterator it;
    MUTEX *lock;

    MutexLock( &mutexMapLock );

    it = mutexMap.find( id );
    if( it == mutexMap.end() )
    {
        // Not found, create it.
        lock = new MUTEX;
        MutexInit( lock );

        mutexMap.insert( std::pair<MUTEX_ID, MUTEX *>(id, lock) );
    }
    else
    {
        lock = it->second;
    }

    MutexUnlock( &mutexMapLock );

    return( lock );
}
开发者ID:burlen,项目名称:visit_vtk_7_src,代码行数:28,代码来源:avtExecutionManager.C


示例20: GBASIOLockstepNodeUnload

bool GBASIOLockstepNodeUnload(struct GBASIODriver* driver) {
    struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver;
    MutexLock(&node->p->mutex);
    --node->p->loaded;
    ConditionWake(&node->p->barrier);
    MutexUnlock(&node->p->mutex);
    return true;
}
开发者ID:joolswills,项目名称:mgba,代码行数:8,代码来源:lockstep.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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