本文整理汇总了C++中UNLOCK_MUTEX函数的典型用法代码示例。如果您正苦于以下问题:C++ UNLOCK_MUTEX函数的具体用法?C++ UNLOCK_MUTEX怎么用?C++ UNLOCK_MUTEX使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UNLOCK_MUTEX函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tilecache_get
tile_t* tilecache_get(tilecache_t *cache, int zoom, int x, int y)
{
LOCK_MUTEX(&cache->lock);
tilecache_slot_t *slot = cache->head;
tile_t *tile = NULL;
gboolean found = FALSE;
for (; slot; slot=slot->next) {
tile = slot->tile;
if (tile->zoom == zoom && tile->x == x && tile->y == y) {
found = TRUE;
//log_debug("tilecache_get: x=%d, y=%d, zoom=%d, found", x, y, zoom);
break;
}
}
UNLOCK_MUTEX(&cache->lock);
if (found)
return tile;
else
return NULL;
}
示例2: _is_job_running
static int _is_job_running(struct workqueue_ctx* ctx, int job_id)
{
int i;
int ret = 0;
int rc;
for (i = 0; i < ctx->num_worker_threads && !ret; i++) {
if (ctx->thread[i]) {
TRY_LOCK_MUTEX(&ctx->thread[i]->mutex, rc);
#ifdef WINDOWS
if (rc)
return -EBUSY;
#else
if (rc == EBUSY)
return -EBUSY;
#endif
if (ctx->thread[i]->job && ctx->thread[i]->job->job_id == job_id) {
ret = 1;
}
UNLOCK_MUTEX(&ctx->thread[i]->mutex);
}
}
return ret;
}
示例3: workqueue_show_status
int workqueue_show_status(struct workqueue_ctx* ctx, FILE *fp)
{
int i;
long long time_ms;
struct TIME_STRUCT_TYPE now_time;
GET_TIME(now_time);
LOCK_MUTEX(&ctx->mutex);
fprintf(fp, "Number of worker threads=%d \n", ctx->num_worker_threads);
fprintf(fp, "Total jobs added=%d queue_size=%d waiting_jobs=%d \n", ctx->job_count, ctx->queue_size, ctx->waiting_jobs);
fprintf(fp, "\n");
fprintf(fp, "%3s | %8s | %4s | %6s ms\n", "Qi", "JobID", "Pri", "Time" );
fprintf(fp, "---------------------------------\n");
for (i = 0; i < ctx->queue_size; i++) {
if (!ctx->queue[i])
continue; /* unused location */
if (TIME_SEC(ctx->queue[i]->start_time) ||
TIME_MSEC(ctx->queue[i]->start_time)) {
// has been scheduled for a time in the future.
time_ms = time_diff_ms(&ctx->queue[i]->start_time, &now_time);
} else {
// will run ASAP
time_ms = 0;
}
fprintf(fp,"%3d | %8d | %4d | %6lld ms\n", i,
ctx->queue[i]->job_id,
ctx->queue[i]->priority, time_ms);
}
UNLOCK_MUTEX(&ctx->mutex);
fflush(fp);
return 0;
}
示例4: io_sched_stop_scheduler
/**
* Tells the specified scheduler it should stop processing its tasks.
**/
void
io_sched_stop_scheduler ( p_io_scheduler_t scheduler )
{
p_io_scheduler_task_t task;
LOGSVC_DEBUG( "io_sched_stop_scheduler()" );
if ( scheduler ) {
// Clear out the scheduled tasks.
LOCK_MUTEX( scheduler->task_list_mutex );
task = scheduler->scheduled_tasks;
while ( task ) {
task->opts |= IO_SCHEDULER_REMOVE;
task = task->next;
}
scheduler->stop_scheduler = CMNUTIL_TRUE;
UNLOCK_MUTEX( scheduler->task_list_mutex );
if ( scheduler->scheduler_thread ) {
//LOGSVC_DEBUG( "Killing scheduler thread" );
//pthread_kill ( scheduler->scheduler_thread, SIGKILL );
//LOGSVC_DEBUG( "Detaching scheduler thread" );
//pthread_detach ( scheduler->scheduler_thread );
LOGSVC_DEBUG( "Cancelling scheduler thread" );
if ( pthread_cancel ( scheduler->scheduler_thread ) == 0 ) {
LOGSVC_DEBUG( "Scheduler thread cancelled" );
pthread_join ( scheduler->scheduler_thread, NULL );
LOGSVC_DEBUG( "Scheduler thread joined" );
}
}
//else {
// LOGSVC_DEBUG( "Setting scheduler stop flag" );
// scheduler->stop_scheduler = CMNUTIL_TRUE;
//}
}
}
示例5: tilecache_cleanup
void tilecache_cleanup(tilecache_t *cache, gboolean free_cache)
{
if (! cache)
return;
LOCK_MUTEX(&cache->lock);
tilecache_slot_t *slot = cache->head, *next;
while(slot) {
next = slot->next;
free_slot_tile(slot->tile);
free(slot);
slot = next;
}
cache->head = cache->tail = NULL;
cache->count = 0;
UNLOCK_MUTEX(&cache->lock);
if (free_cache) {
pthread_mutex_destroy(&(cache->lock));
free(cache);
}
}
示例6: LOCK_MUTEX
/*!
\fn void Posix_QextSerialPort::setParity(ParityType parity)
Sets the parity associated with the serial port. The possible values of parity are:
\verbatim
PAR_SPACE Space Parity
PAR_MARK Mark Parity
PAR_NONE No Parity
PAR_EVEN Even Parity
PAR_ODD Odd Parity
\endverbatim
\note
This function is subject to the following limitations:
\par
POSIX systems do not support mark parity.
\par
POSIX systems support space parity only if tricked into doing so, and only with
fewer than 8 data bits. Use space parity very carefully with POSIX systems.
*/
void Posix_QextSerialPort::setParity(ParityType parity)
{
LOCK_MUTEX();
if (Settings.Parity!=parity) {
if (parity==PAR_MARK || (parity==PAR_SPACE && Settings.DataBits==DATA_8)) {
}
else {
Settings.Parity=parity;
}
}
if (isOpen()) {
switch (parity) {
/*space parity*/
case PAR_SPACE:
if (Settings.DataBits==DATA_8) {
TTY_PORTABILITY_WARNING("Posix_QextSerialPort: Space parity is only supported in POSIX with 7 or fewer data bits");
}
else {
/*space parity not directly supported - add an extra data bit to simulate it*/
Posix_CommConfig.c_cflag&=~(PARENB|CSIZE);
switch(Settings.DataBits) {
case DATA_5:
Settings.DataBits=DATA_6;
Posix_CommConfig.c_cflag|=CS6;
break;
case DATA_6:
Settings.DataBits=DATA_7;
Posix_CommConfig.c_cflag|=CS7;
break;
case DATA_7:
Settings.DataBits=DATA_8;
Posix_CommConfig.c_cflag|=CS8;
break;
case DATA_8:
break;
}
tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
}
break;
/*mark parity - WINDOWS ONLY*/
case PAR_MARK:
TTY_WARNING("Posix_QextSerialPort: Mark parity is not supported by POSIX.");
break;
/*no parity*/
case PAR_NONE:
Posix_CommConfig.c_cflag&=(~PARENB);
tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
break;
/*even parity*/
case PAR_EVEN:
Posix_CommConfig.c_cflag&=(~PARODD);
Posix_CommConfig.c_cflag|=PARENB;
tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
break;
/*odd parity*/
case PAR_ODD:
Posix_CommConfig.c_cflag|=(PARENB|PARODD);
tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
break;
}
}
UNLOCK_MUTEX();
}
示例7: Windows
//.........这里部分代码省略.........
#endif
break;
/*38400 baud*/
case BAUD38400:
#ifdef CBAUD
Posix_CommConfig.c_cflag&=(~CBAUD);
Posix_CommConfig.c_cflag|=B38400;
#else
cfsetispeed(&Posix_CommConfig, B38400);
cfsetospeed(&Posix_CommConfig, B38400);
#endif
break;
/*56000 baud*/
case BAUD56000:
TTY_WARNING("Posix_QextSerialPort: POSIX does not support 56000 baud operation. Switching to 38400 baud.");
#ifdef CBAUD
Posix_CommConfig.c_cflag&=(~CBAUD);
Posix_CommConfig.c_cflag|=B38400;
#else
cfsetispeed(&Posix_CommConfig, B38400);
cfsetospeed(&Posix_CommConfig, B38400);
#endif
break;
/*57600 baud*/
case BAUD57600:
#ifdef CBAUD
Posix_CommConfig.c_cflag&=(~CBAUD);
Posix_CommConfig.c_cflag|=B57600;
#else
cfsetispeed(&Posix_CommConfig, B57600);
cfsetospeed(&Posix_CommConfig, B57600);
#endif
break;
/*76800 baud*/
case BAUD76800:
TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows and some POSIX systems do not support 76800 baud operation.");
#ifdef CBAUD
Posix_CommConfig.c_cflag&=(~CBAUD);
#ifdef B76800
Posix_CommConfig.c_cflag|=B76800;
#else
TTY_WARNING("Posix_QextSerialPort: Posix_QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud.");
Posix_CommConfig.c_cflag|=B57600;
#endif //B76800
#else //CBAUD
#ifdef B76800
cfsetispeed(&Posix_CommConfig, B76800);
cfsetospeed(&Posix_CommConfig, B76800);
#else
TTY_WARNING("Posix_QextSerialPort: Posix_QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud.");
cfsetispeed(&Posix_CommConfig, B57600);
cfsetospeed(&Posix_CommConfig, B57600);
#endif //B76800
#endif //CBAUD
break;
/*115200 baud*/
case BAUD115200:
#ifdef CBAUD
Posix_CommConfig.c_cflag&=(~CBAUD);
Posix_CommConfig.c_cflag|=B115200;
#else
cfsetispeed(&Posix_CommConfig, B115200);
cfsetospeed(&Posix_CommConfig, B115200);
#endif
break;
/*128000 baud*/
case BAUD128000:
TTY_WARNING("Posix_QextSerialPort: POSIX does not support 128000 baud operation. Switching to 115200 baud.");
#ifdef CBAUD
Posix_CommConfig.c_cflag&=(~CBAUD);
Posix_CommConfig.c_cflag|=B115200;
#else
cfsetispeed(&Posix_CommConfig, B115200);
cfsetospeed(&Posix_CommConfig, B115200);
#endif
break;
/*256000 baud*/
case BAUD256000:
TTY_WARNING("Posix_QextSerialPort: POSIX does not support 256000 baud operation. Switching to 115200 baud.");
#ifdef CBAUD
Posix_CommConfig.c_cflag&=(~CBAUD);
Posix_CommConfig.c_cflag|=B115200;
#else
cfsetispeed(&Posix_CommConfig, B115200);
cfsetospeed(&Posix_CommConfig, B115200);
#endif
break;
}
tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
}
UNLOCK_MUTEX();
}
示例8: submit_data_chunk
int submit_data_chunk (buf_t *buf, char *data, size_t size)
{
long buf_write_pos; /* offset of first available write location */
size_t write_size;
DEBUG1("Enter submit_data_chunk, size %d", size);
pthread_cleanup_push(buffer_mutex_unlock, buf);
/* Put the data into the buffer as space is made available */
while (size > 0 && !buf->abort_write) {
/* Section 1: Write a chunk of data */
DEBUG("Obtaining lock on buffer");
LOCK_MUTEX(buf->mutex);
if (buf->size - buf->curfill > 0) {
/* Figure how much we can write into the buffer. Requirements:
1. Don't write more data than we have.
2. Don't write more data than we have room for.
3. Don't write past the end of the buffer. */
buf_write_pos = (buf->start + buf->curfill) % buf->size;
write_size = MIN3(size, buf->size - buf->curfill,
buf->size - buf_write_pos);
memcpy(buf->buffer + buf_write_pos, data, write_size);
buf->curfill += write_size;
data += write_size;
size -= write_size;
buf->position_end += write_size;
DEBUG1("writing chunk into buffer, curfill = %ld", buf->curfill);
}
else {
if (buf->cancel_flag || sig_request.cancel) {
UNLOCK_MUTEX(buf->mutex);
break;
}
/* No room for more data, wait until there is */
DEBUG("No room for data in buffer. Waiting.");
COND_WAIT(buf->write_cond, buf->mutex);
}
/* Section 2: signal if we are not prebuffering, done
prebuffering, or paused */
if (buf->prebuffering && (buf->prebuffer_size <= buf->curfill)) {
DEBUG("prebuffering done")
buf->prebuffering = 0; /* done prebuffering */
}
if (!buf->prebuffering && !buf->paused) {
DEBUG("Signalling playback thread that more data is available.");
COND_SIGNAL(buf->playback_cond);
} else
DEBUG("Not signalling playback thread since prebuffering or paused.");
UNLOCK_MUTEX(buf->mutex);
}
pthread_cleanup_pop(0);
DEBUG("Exit submit_data_chunk");
return !buf->abort_write;
}
示例9: buffer_mutex_unlock
void buffer_mutex_unlock (void *arg)
{
buf_t *buf = (buf_t *)arg;
UNLOCK_MUTEX(buf->mutex);
}
示例10: LOCK_MUTEX
/*!
\fn void Win_QextSerialPort::close()
Closes a serial port. This function has no effect if the serial port associated with the class
is not currently open.
*/
void Win_QextSerialPort::close() {
LOCK_MUTEX();
CloseHandle(Win_Handle);
QIODevice::close();
UNLOCK_MUTEX();
}
示例11: playMusic
int playMusic( sp_session *session , char *uri , char *name , playqueue_fifo_t *playqueue )
{
TRACE_2( PLAYERMANAGER , "playMusic().");
static int firstTime = 0;
int status = PC_SUCCESS;
char response[255] = { 0 };
sp_error error;
LOCK_MUTEX( PLAYERMANAGER , &mutexSession );
TRACE_3( PLAYERMANAGER , "Test if a music is playing or not");
if( currentTrack == NULL )
{
TRACE_WARNING( PLAYERMANAGER , "Cannot play track because no track has been loaded.");
status = PC_ERROR;
snprintf( response , 255 , "NOK: Cannot play track because no track has been loaded.");
sendVoid( ( void * )response , strlen( response ) );
}
else
{
TRACE_1( PLAYERMANAGER , "Getting the track.");
currentTrack = getNextTrackToPlayqueue( playqueue );
loadTrack( session , currentTrack );
error = sp_session_player_play( session , 1 );
if( error != SP_ERROR_OK )
{
TRACE_ERROR( PLAYERMANAGER , "Cannot play track, reason: %s" , sp_error_message( error ) );
status = PC_ERROR;
}
else
{
TRACE_1( PLAYERMANAGER , "Success to play track.");
if( firstTime++ != 0 )
playStream( name );
playing = TRUE;
snprintf( response , 255 , "OK");
sendVoid( ( void * )response , strlen( response ) );
}
if( currentStreamName[0] == 0 )
{
strncpy( currentStreamName , name , strlen( name ) );
}
else if( strcmp( currentStreamName , name ) != 0 )
{
memset( currentStreamName , 0 , 255 );
strncpy( currentStreamName , name , strlen( name ) );
}
else if( !strcmp( currentStreamName , name ) )
{
//Do nothing
}
}
UNLOCK_MUTEX( PLAYERMANAGER , &mutexSession );
return status;
}
示例12: ExitThread
void *workThreadReceive( void *pObject )
#endif
{
#ifdef WIN32
DWORD errorCode = 0;
#else
int rv = 0;
#endif
CPeakObj * pobj = ( CPeakObj *)pObject;
if ( NULL == pobj ) {
#ifdef WIN32
ExitThread( errorCode ); // Fail
#else
pthread_exit( &rv );
#endif
}
PeakCanMsg peakMsg;
while ( pobj->m_bRun ) {
// Noting to do if we should end...
if ( !pobj->m_bRun ) continue;
LOCK_MUTEX( pobj->m_peakMutex );
while ( 0 == ( pobj->m_procRead( &peakMsg ) & PEAK_CAN_ERR_QRCVEMPTY ) ) {
// Check if this is a status message
if ( PCAN_MSGTYPE_STATUS & peakMsg.msgType ) {
continue; // TODO
}
// Write to the receive buffer
if ( pobj->m_receiveList.nCount < PEAKDRV_MAX_RCVMSG ) {
PCANALMSG pMsg = new canalMsg;
pMsg->flags = 0;
if ( NULL != pMsg ) {
dllnode *pNode = new dllnode;
if ( NULL != pNode ) {
pMsg->timestamp = GetTickCount() * 1000;
pMsg->id = peakMsg.id;
pMsg->sizeData = peakMsg.len;
memcpy( pMsg->data, peakMsg.data, pMsg->sizeData );
// If extended set extended flag
if ( PCAN_MSGTYPE_EXTENDED & peakMsg.msgType ) {
pMsg->flags |= CANAL_IDFLAG_EXTENDED;
}
// Check for RTS package
if ( PCAN_MSGTYPE_RTR & peakMsg.msgType ) {
pMsg->flags |= CANAL_IDFLAG_RTR;
}
pNode->pObject = pMsg;
LOCK_MUTEX( pobj->m_receiveMutex );
dll_addNode( &pobj->m_receiveList, pNode );
UNLOCK_MUTEX( pobj->m_receiveMutex );
// Update statistics
pobj->m_stat.cntReceiveData += pMsg->sizeData;
pobj->m_stat.cntReceiveFrames += 1;
}
else {
delete pMsg;
}
}
}
else {
// Full buffer
pobj->m_stat.cntOverruns++;
}
} // while rcv msg
UNLOCK_MUTEX( pobj->m_peakMutex );
SLEEP( 1 );
} // while
#ifdef WIN32
ExitThread( errorCode );
#else
pthread_exit( &rv );
#endif
}
示例13: Q_ASSERT
//.........这里部分代码省略.........
Win_CommConfig.dcb.BaudRate = 614400;
break;
case BAUD750000:
Win_CommConfig.dcb.BaudRate = 750000;
break;
case BAUD921600:
Win_CommConfig.dcb.BaudRate = 921600;
break;
case BAUD1000000:
Win_CommConfig.dcb.BaudRate = 1000000;
break;
case BAUD1228800:
Win_CommConfig.dcb.BaudRate = 1228800;
break;
case BAUD2457600:
Win_CommConfig.dcb.BaudRate = 2457600;
break;
case BAUD3000000:
Win_CommConfig.dcb.BaudRate = 3000000;
break;
case BAUD6000000:
Win_CommConfig.dcb.BaudRate = 6000000;
break;
default:
Win_CommConfig.dcb.BaudRate = (unsigned int)Settings.BaudRate;
break;
}
// STOP bits
switch (Settings.StopBits) {
case STOP_1:/*one stop bit*/
Win_CommConfig.dcb.StopBits=ONESTOPBIT;
break;
case STOP_1_5:/*1.5 stop bits*/
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;
}
break;
case STOP_2:/*two stop bits*/
if (Settings.DataBits==DATA_5) {// BUG this assumes, that DATA was set first
TTY_WARNING("Win_QextSerialPort: 2 stop bits cannot be used with 5 data bits");
} else {
Win_CommConfig.dcb.StopBits=TWOSTOPBITS;
}
break;
default:
Q_ASSERT(0); // This should never happen BUG replace by a error message
}
switch (Settings.FlowControl) {
case FLOW_OFF:/*no flow control*/
Win_CommConfig.dcb.fOutxCtsFlow = FALSE;
Win_CommConfig.dcb.fOutxDsrFlow = FALSE;
Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE;
Win_CommConfig.dcb.fInX=FALSE;
Win_CommConfig.dcb.fOutX=FALSE;
break;
case FLOW_XONXOFF:/*software (XON/XOFF) flow control*/
Win_CommConfig.dcb.fOutxCtsFlow = FALSE;
Win_CommConfig.dcb.fOutxDsrFlow = FALSE;
Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE;
Win_CommConfig.dcb.fInX=TRUE;
Win_CommConfig.dcb.fOutX=TRUE;
break;
case FLOW_HARDWARE:
Win_CommConfig.dcb.fOutxCtsFlow=TRUE;
Win_CommConfig.dcb.fOutxDsrFlow = FALSE; // guess?
Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_HANDSHAKE;
Win_CommConfig.dcb.fInX=FALSE;
Win_CommConfig.dcb.fOutX=FALSE;
break;
default:
Q_ASSERT(0); // This should never happen BUG replace by a error message
}
// write configuration back
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
// read current settings
GetCommConfig(Win_Handle, &readCommConfig, &confSize);
UNLOCK_MUTEX();
if(Win_CommConfig.dcb.BaudRate != readCommConfig.dcb.BaudRate)
{
Settings.BaudRate = readCommConfig.dcb.BaudRate;
}
return true;
}
示例14: read
/*!
\fn void Win_QextSerialPort::setTimeout(ulong millisec);
Sets the read and write timeouts for the port to millisec milliseconds.
Setting 0 indicates that timeouts are not used for read nor write operations;
however read() and write() functions will still block. Set -1 to provide
non-blocking behaviour (read() and write() will return immediately).
*/
void Win_QextSerialPort::setTimeout(long millisec) {
LOCK_MUTEX();
Settings.Timeout_Millisec = millisec;
// BUG it might be necessary to change the timeout while the port is open
UNLOCK_MUTEX();
}
示例15: LOCK_MUTEX
/*!
\fn void Win_QextSerialPort::setParity(ParityType parity)
Sets the parity associated with the serial port. The possible values of parity are:
\verbatim
PAR_SPACE Space Parity
PAR_MARK Mark Parity
PAR_NONE No Parity
PAR_EVEN Even Parity
PAR_ODD Odd Parity
\endverbatim
*/
void Win_QextSerialPort::setParity(ParityType parity)
{
LOCK_MUTEX();
Settings.Parity=parity;
UNLOCK_MUTEX();
}