本文整理汇总了C++中LOCK_MUTEX函数的典型用法代码示例。如果您正苦于以下问题:C++ LOCK_MUTEX函数的具体用法?C++ LOCK_MUTEX怎么用?C++ LOCK_MUTEX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LOCK_MUTEX函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LOCK_MUTEX
/*!
\fn void Win_QextSerialPort::setStopBits(StopBitsType stopBits)
Sets the number of stop bits used by the serial port. Possible values of stopBits are:
\verbatim
STOP_1 1 stop bit
STOP_1_5 1.5 stop bits
STOP_2 2 stop bits
\endverbatim
\note
This function is subject to the following restrictions:
\par
2 stop bits cannot be used with 5 data bits.
\par
1.5 stop bits cannot be used with 6 or more data bits.
\par
POSIX does not support 1.5 stop bits.
*/
void Win_QextSerialPort::setStopBits(StopBitsType stopBits) {
LOCK_MUTEX();
if (Settings.StopBits!=stopBits) {
if ((Settings.DataBits==DATA_5 && stopBits==STOP_2) ||
(stopBits==STOP_1_5 && Settings.DataBits!=DATA_5)) {
}
else {
Settings.StopBits=stopBits;
}
}
if (isOpen()) {
switch (stopBits) {
/*one stop bit*/
case STOP_1:
Win_CommConfig.dcb.StopBits=ONESTOPBIT;
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
break;
/*1.5 stop bits*/
case STOP_1_5:
TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: 1.5 stop bit operation is not supported by POSIX.");
if (Settings.DataBits!=DATA_5) {
TTY_WARNING("Win_QextSerialPort: 1.5 stop bits can only be used with 5 data bits");
}
else {
Win_CommConfig.dcb.StopBits=ONE5STOPBITS;
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
}
break;
/*two stop bits*/
case STOP_2:
if (Settings.DataBits==DATA_5) {
TTY_WARNING("Win_QextSerialPort: 2 stop bits cannot be used with 5 data bits");
}
else {
Win_CommConfig.dcb.StopBits=TWOSTOPBITS;
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
}
break;
}
}
UNLOCK_MUTEX();
}
示例2: LOCK_MUTEX
//suscribe to topic Id. Receive a callback when a message is received
ps_result_enum ps_pubsub_class::subscribe(ps_topic_id_t topicId, message_handler_t *msgHandler)
{
LOCK_MUTEX(pubsubMtx);
//find the client
for (psClient_t *client : clientList)
{
if (client->messageHandler == msgHandler)
{
client->topicList.insert(topicId); //add new subscription
if (topicId >= topic_count)
{
PS_DEBUG("pub: subscribe to topic %i", topicId);
}
else
{
PS_DEBUG("pub: subscribe to topic %s", topic_names[topicId]);
}
UNLOCK_MUTEX(pubsubMtx);
return PS_OK;
}
}
//add new client
{
psClient_t *newClient = new psClient_t();
newClient->messageHandler = msgHandler;
newClient->topicList.insert(topicId); //add new subscription
clientList.insert(newClient);
if (topicId >= topic_count)
{
PS_DEBUG("pub: new client subscribed to topic %i", topicId);
}
else
{
PS_DEBUG("pub: new client subscribed to topic %s", topic_names[topicId]);
}
}
UNLOCK_MUTEX(pubsubMtx);
return PS_OK;
}
示例3: loadMusic
int loadMusic( sp_session *session, char *uri , char *name , playqueue_fifo_t *playqueue )
{
TRACE_2( PLAYERMANAGER , "loadMusic().");
int status = PC_SUCCESS;
char response[255] = { 0 };
/* If it's the first time we load a track, we have to init the audio driver and the playqueue */
// if( firstTime++ == 0 )
// initPlayerEnv();
LOCK_MUTEX( PLAYERMANAGER , &mutexSession );
sp_track *track = NULL;
currentTrack = track;
if( createTrackFromUri( uri , name ) == PC_ERROR )
status = PC_ERROR;
if( currentTrack != NULL)
{
TRACE_1( PLAYERMANAGER , "Adding track to the playlist.");
addTracksToPlayqueue( playqueue , currentTrack );
snprintf( response , 255 , "OK");
sendVoid( ( void * )response , strlen( response ) );
}
else
{
TRACE_ERROR( PLAYERMANAGER , "Cannot add track to the playlist because track is NULL.");
status = PC_ERROR;
snprintf( response , 255 , "NOK: Cannot add the track to the playlist because the URI might be invalid.");
sendVoid( ( void * )response , strlen( response ) );
}
UNLOCK_MUTEX( PLAYERMANAGER , &mutexSession );
return status;
}
示例4: LOCK_MUTEX
/*!
\fn qint64 Win_QextSerialPort::bytesAvailable()
Returns the number of bytes waiting in the port's receive queue. This function will return 0 if
the port is not currently open, or -1 on error. Error information can be retrieved by calling
Win_QextSerialPort::getLastError().
*/
qint64 Win_QextSerialPort::bytesAvailable() {
LOCK_MUTEX();
if (isOpen()) {
DWORD Errors;
COMSTAT Status;
bool success=ClearCommError(Win_Handle, &Errors, &Status);
translateError(Errors);
if (success) {
lastErr=E_NO_ERROR;
UNLOCK_MUTEX();
return Status.cbInQue + QIODevice::bytesAvailable();
}
UNLOCK_MUTEX();
return (unsigned int)-1;
}
UNLOCK_MUTEX();
return 0;
}
示例5: workqueue_job_running
int workqueue_job_running(struct workqueue_ctx* ctx, int job_id)
{
int ret = 0;
if (!ctx)
return -1;
do {
LOCK_MUTEX(&ctx->mutex);
ret = _is_job_running(ctx, job_id);
UNLOCK_MUTEX(&ctx->mutex);
} while (ret == -EBUSY);
return ret;
}
示例6: LOCK_MUTEX
bool CCAN232Obj::setMask(unsigned long mask)
{
char buf[ 20 ];
char szCmd[ 80 ];
LOCK_MUTEX(m_can232ObjMutex);
// Acceptance Mask
sprintf(buf, "m%8.8lX\r", mask);
m_can232obj.m_comm.comm_puts(buf, strlen(buf), true);
*szCmd = 0;
m_can232obj.m_comm.comm_gets(szCmd, sizeof( szCmd), 100000);
printf("Open: Response: setFilter: [%s]\n", szCmd);
UNLOCK_MUTEX(m_can232ObjMutex);
return true;
}
示例7: ncdClosePort
bool CVectorObj::close( void )
{
// Do nothing if already terminated
if ( !m_bRun ) return false;
m_bRun = false;
ncdClosePort( m_portHandle );
m_portHandle = INVALID_PORTHANDLE;
ncdCloseDriver();
UNLOCK_MUTEX( m_vectorMutex );
LOCK_MUTEX( m_vectorMutex );
// terminate the worker thread
#ifdef WIN32
DWORD rv;
// Wait for transmit thread to terminate
while ( true ) {
GetExitCodeThread( m_hTreadTransmit, &rv );
if ( STILL_ACTIVE != rv ) break;
}
// Wait for receive thread to terminate
while ( true ) {
GetExitCodeThread( m_hTreadReceive, &rv );
if ( STILL_ACTIVE != rv ) break;
}
#else
int *trv;
pthread_join( m_threadIdReceive, (void **)&trv );
pthread_join( m_threadIdTransmit, (void **)&trv );
pthread_mutex_destroy( &m_vectorMutex );
#endif
return true;
}
示例8: end_of_track
void end_of_track( sp_session *session )
{
TRACE_2( PLAYERMANAGER , "end_of_track().");
TRACE_3( PLAYERMANAGER , "End of track...");
// LOCK_MUTEX( PLAYERMANAGER , &mutexSession );
TRACE_3( PLAYERMANAGER , "Removing the track which have been played.");
sp_track_release( currentTrack );
// UNLOCK_MUTEX( PLAYERMANAGER , &mutexSession );
// if( hasNextTrack() == TRUE )
// {
// TRACE_1( PLAYERMANAGER , "Load next music !");
// playMusic( session , "" , currentStreamName );
// }
if( nextTrackInStream( currentStreamName ) == PC_SUCCESS )
{
TRACE_1( PLAYERMANAGER , "Load next music !");
}
else
{
TRACE_WARNING( PLAYERMANAGER , "No more music in the mainplaylist");
audio_fifo_flush( &g_audiofifo );
LOCK_MUTEX( PLAYERMANAGER , &mutexSession );
sp_session_player_play( session , 0 );
sp_session_player_unload( session );
UNLOCK_MUTEX( PLAYERMANAGER , &mutexSession );
playing = FALSE;
}
}
示例9: bytesWaiting
/*!
\fn void Posix_QextSerialPort::setTimeout(ulong sec);
Sets the read and write timeouts for the port to millisec milliseconds.
Note that this is a per-character timeout, i.e. the port will wait this long for each
individual character, not for the whole read operation. This timeout also applies to the
bytesWaiting() function.
\note
POSIX does not support millisecond-level control for I/O timeout values. Any
timeout set using this function will be set to the next lowest tenth of a second for
the purposes of detecting read or write timeouts. For example a timeout of 550 milliseconds
will be seen by the class as a timeout of 500 milliseconds for the purposes of reading and
writing the port. However millisecond-level control is allowed by the select() system call,
so for example a 550-millisecond timeout will be seen as 550 milliseconds on POSIX systems for
the purpose of detecting available bytes in the read buffer.
*/
void Posix_QextSerialPort::setTimeout(long millisec)
{
LOCK_MUTEX();
Settings.Timeout_Millisec = millisec;
Posix_Copy_Timeout.tv_sec = millisec / 1000;
Posix_Copy_Timeout.tv_usec = millisec % 1000;
if (isOpen()) {
if (millisec == -1)
fcntl(fd, F_SETFL, O_NDELAY);
else
//O_SYNC should enable blocking ::write()
//however this seems not working on Linux 2.6.21 (works on OpenBSD 4.2)
fcntl(fd, F_SETFL, O_SYNC);
tcgetattr(fd, & Posix_CommConfig);
Posix_CommConfig.c_cc[VTIME] = millisec/100;
tcsetattr(fd, TCSAFLUSH, & Posix_CommConfig);
}
UNLOCK_MUTEX();
}
示例10: PS_DEBUG
//suscribe to topic Id. Transport version.
ps_result_enum ps_pubsub_class::subscribe(ps_topic_id_t topicId, ps_transport_class *pst)
{
if (topicId >= topic_count)
{
PS_DEBUG("pub: subscribe to %i from %s", topicId, pst->name.c_str());
}
else
{
PS_DEBUG("pub: subscribe to %s from %s", topic_names[ topicId], pst->name.c_str());
}
LOCK_MUTEX(pubsubMtx);
//insert the topic
pst->topicList.insert(topicId); //add new subscription
UNLOCK_MUTEX(pubsubMtx);
return PS_OK;
}
示例11: LOCK_MUTEX
BOOL CDllDrvObj::removeAllObjects()
{
LOCK_MUTEX( m_objMutex );
for ( int i=0; i<CANAL_USB2CAN_DRIVER_MAX_OPEN; i++ )
{
if ( NULL != m_drvObjArray[ i ] )
{
m_drvObjArray[ i ]->close();
delete m_drvObjArray[ i ];
m_drvObjArray[ i ] = NULL;
lpvMem[i] = 0;//inform global space driver on position i closed
}
}
UNLOCK_MUTEX( m_objMutex );
return TRUE;
}
示例12: buffer_append_action_at
void buffer_append_action_at (buf_t *buf, action_func_t action_func,
void *action_arg, ogg_int64_t position)
{
action_t *action;
action = malloc_action(action_func, action_arg);
pthread_cleanup_push(buffer_mutex_unlock, buf);
LOCK_MUTEX(buf->mutex);
action->position = position;
in_order_add_action(&buf->actions, action, APPEND);
UNLOCK_MUTEX(buf->mutex);
pthread_cleanup_pop(0);
}
示例13: setAdapterRunMode
bool CApoxObj::close( void )
{
// Do nothing if already terminated
if ( !m_bRun ) return false;
m_bRun = false;
// Switch to boot mode
setAdapterRunMode( RUNMODE_BOOT );
FT_Close( m_ftHandle );
UNLOCK_MUTEX( m_apoxMutex );
LOCK_MUTEX( m_apoxMutex );
// terminate the worker thread
#ifdef WIN32
DWORD rv;
// Wait for transmit thread to terminate
while ( true ) {
GetExitCodeThread( m_hTreadTransmit, &rv );
if ( STILL_ACTIVE != rv ) break;
}
// Wait for receive thread to terminate
while ( true ) {
GetExitCodeThread( m_hTreadReceive, &rv );
if ( STILL_ACTIVE != rv ) break;
}
#else
int *trv;
pthread_join( m_threadIdReceive, (void **)&trv );
pthread_join( m_threadIdTransmit, (void **)&trv );
pthread_mutex_destroy( &m_apoxMutex );
#endif
return true;
}
示例14: open
/*!
\fn qint64 Win_QextSerialPort::readData(char *data, qint64 maxSize)
Reads a block of data from the serial port. This function will read at most maxlen bytes from
the serial port and place them in the buffer pointed to by data. Return value is the number of
bytes actually read, or -1 on error.
\warning before calling this function ensure that serial port associated with this class
is currently open (use isOpen() function to check if port is open).
*/
qint64 Win_QextSerialPort::readData(char *data, qint64 maxSize)
{
DWORD retVal;
LOCK_MUTEX();
retVal = 0;
if (queryMode() == QextSerialBase::EventDriven)
{
OVERLAPPED overlapRead;
overlapRead.Internal = 0;
overlapRead.InternalHigh = 0;
overlapRead.Offset = 0;
overlapRead.OffsetHigh = 0;
overlapRead.hEvent = CreateEvent(NULL, true, false, NULL);
if (!ReadFile(m_WinHandle, (void*)data, (DWORD)maxSize, & retVal, & overlapRead))
{
if (GetLastError() == ERROR_IO_PENDING)
{
GetOverlappedResult(m_WinHandle, & overlapRead, & retVal, true);
}
else
{
lastErr = E_READ_FAILED;
retVal = (DWORD)-1;
}
}
CloseHandle(overlapRead.hEvent);
}
else if (!ReadFile(m_WinHandle, (void*)data, (DWORD)maxSize, & retVal, NULL))
{
lastErr = E_READ_FAILED;
retVal = (DWORD)-1;
}
UNLOCK_MUTEX();
return (qint64)retVal;
}
示例15: LOCK_MUTEX
long
CSocketcanApp::addDriverObject(CSocketcanObj *plog)
{
long h = 0;
LOCK_MUTEX(m_objMutex);
for (int i = 0; i < CANAL_SOCKETCAN_DRIVER_MAX_OPEN; i++) {
if (NULL == m_socketcanArray[ i ]) {
m_socketcanArray[ i ] = plog;
h = i + 1681;
break;
}
}
UNLOCK_MUTEX(m_objMutex);
return h;
}