本文整理汇总了C++中MUTEX_LOCK函数的典型用法代码示例。如果您正苦于以下问题:C++ MUTEX_LOCK函数的具体用法?C++ MUTEX_LOCK怎么用?C++ MUTEX_LOCK使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MUTEX_LOCK函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: arc_balance
/* Balance the lists so that we can fit an object with the given size into
* the cache. */
static inline void
arc_balance(arc_t *cache)
{
if (!ATOMIC_READ(cache->needs_balance))
return;
MUTEX_LOCK(&cache->lock);
/* First move objects from MRU/MFU to their respective ghost lists. */
while (cache->mru.size + cache->mfu.size > cache->c) {
if (cache->mru.size > cache->p) {
arc_object_t *obj = arc_state_lru(&cache->mru);
arc_move(cache, obj, &cache->mrug);
} else if (cache->mfu.size > cache->c - cache->p) {
arc_object_t *obj = arc_state_lru(&cache->mfu);
arc_move(cache, obj, &cache->mfug);
} else {
break;
}
}
/* Then start removing objects from the ghost lists. */
while (cache->mrug.size + cache->mfug.size > cache->c) {
if (cache->mfug.size > cache->p) {
arc_object_t *obj = arc_state_lru(&cache->mfug);
arc_move(cache, obj, NULL);
} else if (cache->mrug.size > cache->c - cache->p) {
arc_object_t *obj = arc_state_lru(&cache->mrug);
arc_move(cache, obj, NULL);
} else {
break;
}
}
ATOMIC_SET(cache->needs_balance, 0);
MUTEX_UNLOCK(&cache->lock);
}
开发者ID:theseusyang,项目名称:libshardcache,代码行数:38,代码来源:arc.c
示例2: ASSERT
bool VDAgent::write_clipboard(VDAgentMessage* msg, uint32_t size)
{
uint32_t pos = 0;
bool ret = true;
ASSERT(msg && size);
//FIXME: do it smarter - no loop, no memcopy
MUTEX_LOCK(_message_mutex);
while (pos < size) {
DWORD n = MIN(sizeof(VDIChunk) + size - pos, VD_AGENT_MAX_DATA_SIZE);
VDIChunk* chunk = new_chunk(n);
if (!chunk) {
ret = false;
break;
}
chunk->hdr.port = VDP_CLIENT_PORT;
chunk->hdr.size = n - sizeof(VDIChunk);
memcpy(chunk->data, (char*)msg + pos, n - sizeof(VDIChunk));
enqueue_chunk(chunk);
pos += (n - sizeof(VDIChunk));
}
MUTEX_UNLOCK(_message_mutex);
return ret;
}
开发者ID:freedesktop-unofficial-mirror,项目名称:spice__win32__vd_agent,代码行数:24,代码来源:vdagent.cpp
示例3: xmap_check_meta
/* check meta */
int xmap_check_meta(XMAP *xmap, int qid, int *status, XMSETS *xsets)
{
int ret = -1, n = 0, k = 0;
if(xmap && xsets && qid > 0)
{
MUTEX_LOCK(xmap->mutex);
if(qid <= xmap->state->id_max && (ret = n = xmap->metas[qid].count) > 0)
{
*status = xmap->metas[qid].status;
while(--n >= 0)
{
if((k = xmap->metas[qid].disks[n]) > 0 && k <= xmap->state->disk_id_max)
{
xsets->lists[n].ip = xmap->disks[k].ip;
xsets->lists[n].port = xmap->disks[k].port;
xsets->lists[n].gid = xmap->disks[k].groupid;
}
}
}
MUTEX_UNLOCK(xmap->mutex);
}
return ret;
}
开发者ID:sounos,项目名称:hidbase,代码行数:25,代码来源:xmap.c
示例4: peer_info
static BOOL peer_info(RTP *rtp)
{
int addrlen;
struct sockaddr_in cli_addr, *cli_addrp;
struct hostent *hp;
static CHAR *fid = "peer_info";
addrlen = sizeof(cli_addr);
cli_addrp = &cli_addr;
if (getpeername(rtp->sd, (struct sockaddr *)cli_addrp, &addrlen) != 0) {
rtp_log(RTP_ERR, "%s: getpeername: %s", fid, strerror(errno));
return FALSE;
}
rtp->addr = (CHAR *) strdup(inet_ntoa(cli_addrp->sin_addr));
MUTEX_LOCK(&mutex);
hp = gethostbyaddr(
(char *) &cli_addrp->sin_addr,
sizeof(struct in_addr),
cli_addrp->sin_family
);
if (hp != NULL) {
rtp->peer = (CHAR *) strdup(hp->h_name);
} else {
rtp->peer = (CHAR *) strdup(rtp->addr);
}
MUTEX_UNLOCK(&mutex);
if (rtp->peer == (CHAR *) NULL) {
rtp_log(RTP_ERR, "%s: strdup: %s", fid, strerror(errno));
return FALSE;
}
rtp->port = (UINT16) ntohs(cli_addr.sin_port);
return TRUE;
}
开发者ID:Fran89,项目名称:seiscomp3,代码行数:36,代码来源:accept.c
示例5: mgcfifo_out
int
mgcfifo_out(struct mgcfifo *pfifo, char *destbuff) //拷贝长度为一�?elements
{
int ret = 0;
static UINT16 i = 0;
if (pfifo->fifo_size == 0)
{
while (1)
mprintf("err fifosize == 0!\r\n");
}
MUTEX_LOCK ( pfifo->mutex );
if (pfifo->nvalid == 0)
{
ret = -1;
goto out;
}
DEBUG_FIFO("fifo out %d:", i++);
(void) DEBUG_FIFO_ARRAY(pfifo->tail + pfifo->buff, pfifo->element_size);
DEBUG_FIFO("\r\n");
(void) memcpy(destbuff, pfifo->tail + pfifo->buff, pfifo->element_size);
// if( pfifo->nvalid > 1)
if (pfifo->tail != pfifo->head)
{
mgcfifo_tailinc(pfifo);
}
pfifo->nvalid--;
ret = pfifo->nvalid;
out: MUTEX_UNLOCK ( pfifo->mutex );
return ret;
}
开发者ID:mildrock,项目名称:Master,代码行数:36,代码来源:mgcfifo.c
示例6: run
void run( void *arg )
{
char *name = (char *)arg;
char debug[20];
while(1)
{
MUTEX_LOCK();
if( g_tickets <= 0 ){
MUTEX_UNLOCK();
goto exit;
}
g_tickets--;
sprintf( debug, "Thread %s, %d\r\n", name, g_tickets );
MicoUartSend(STDIO_UART, debug, strlen(debug) );
MUTEX_UNLOCK();
}
exit:
os_mutex_log( "thread: %s exit now", name );
mico_rtos_delete_thread(NULL);
}
开发者ID:HargicStudio,项目名称:smartCup_micokit_V2.3.0.2,代码行数:24,代码来源:os_mutex.c
示例7: keeper_acquire
struct s_Keeper* keeper_acquire( void const* ptr)
{
// can be 0 if this happens during main state shutdown (lanes is being GC'ed -> no keepers)
if( GNbKeepers == 0)
{
return NULL;
}
else
{
/*
* Any hashing will do that maps pointers to 0..GNbKeepers-1
* consistently.
*
* Pointers are often aligned by 8 or so - ignore the low order bits
* have to cast to unsigned long to avoid compilation warnings about loss of data when converting pointer-to-integer
*/
unsigned int i = (unsigned int)(((unsigned long)(ptr) >> 3) % GNbKeepers);
struct s_Keeper* K= &GKeepers[i];
MUTEX_LOCK( &K->lock_);
//++ K->count;
return K;
}
}
开发者ID:AlexKordic,项目名称:lanes,代码行数:24,代码来源:keeper.c
示例8: mailstream_ssl_init
static inline void mailstream_ssl_init(void)
{
#ifdef USE_SSL
mailstream_ssl_init_lock();
MUTEX_LOCK(&ssl_lock);
#ifndef USE_GNUTLS
if (!openssl_init_done) {
#if defined (HAVE_PTHREAD_H) && !defined (WIN32) && defined (USE_SSL) && defined (LIBETPAN_REENTRANT)
mailstream_openssl_reentrant_setup();
#endif
SSL_load_error_strings();
SSL_library_init();
OpenSSL_add_all_algorithms();
openssl_init_done = 1;
}
#else
if (!gnutls_init_not_required)
gnutls_global_init();
#endif
MUTEX_UNLOCK(&ssl_lock);
#endif
}
开发者ID:bvanosten,项目名称:libetpan,代码行数:24,代码来源:mailstream_ssl.c
示例9: advance_tx_buffer
/* Assumes buffer lock is held */
static int advance_tx_buffer(struct bladerf_sync *s, struct buffer_mgmt *b)
{
int status;
log_verbose("%s: Marking buf[%u] full\n", __FUNCTION__, b->prod_i);
b->status[b->prod_i] = SYNC_BUFFER_IN_FLIGHT;
/* This call may block and it results in a per-stream lock being held, so
* the buffer lock must be dropped.
*
* A callback may occur in the meantime, but this will not touch the status
* for this this buffer, or the producer index.
*/
MUTEX_UNLOCK(&b->lock);
status = async_submit_stream_buffer(s->worker->stream,
b->buffers[b->prod_i],
s->stream_config.timeout_ms);
MUTEX_LOCK(&b->lock);
if (status == 0) {
b->prod_i = (b->prod_i + 1) % b->num_buffers;
/* Go handle the next buffer, if we have one available. Otherwise,
* check up on the worker's state and restart it if needed. */
if (b->status[b->prod_i] == SYNC_BUFFER_EMPTY) {
s->state = SYNC_STATE_BUFFER_READY;
} else {
s->state = SYNC_STATE_CHECK_WORKER;
}
} else {
log_debug("%s: Failed to advance buffer: %s\n",
__FUNCTION__, bladerf_strerror(status));
}
return status;
}
开发者ID:khoikool,项目名称:bladeRF,代码行数:37,代码来源:sync.c
示例10: MikMod_InfoDriver
CHAR* MikMod_InfoDriver(void)
{
int t,len=0;
MDRIVER *l;
CHAR *list=NULL;
MUTEX_LOCK(lists);
/* compute size of buffer */
for(l=firstdriver;l;l=l->next)
if(l->Version)
len+=4+(l->next?1:0)+strlen(l->Version);
if(len)
if((list=_mm_malloc(len*sizeof(CHAR)))) {
list[0]=0;
/* list all registered device drivers : */
for(t=1,l=firstdriver;l;l=l->next,t++)
if(l->Version)
sprintf(list,(l->next)?"%s%2d %s\n":"%s%2d %s",
list,t,l->Version);
}
MUTEX_UNLOCK(lists);
return list;
}
开发者ID:LibXenonProject,项目名称:SDL_Mixer,代码行数:24,代码来源:mdriver.c
示例11: mmtree64_new_tree
/* insert new root */
int mmtree64_new_tree(void *x)
{
int id = 0, i = 0;
if(x)
{
MUTEX_LOCK(MMT(x)->mutex);
if(MMT(x)->state->nroots == 0) MMT(x)->state->nroots = 1;
if(MMT(x)->state && MMT(x)->state->nroots < MMTREE64_ROOT_MAX)
{
for(i = 1; i < MMTREE64_ROOT_MAX; i++)
{
if(MMT(x)->state->roots[i].status == 0)
{
MMT(x)->state->roots[i].status = 1;
MMT(x)->state->nroots++;
id = i;
break;
}
}
}
MUTEX_UNLOCK(MMT(x)->mutex);
}
return id;
}
开发者ID:cnangel,项目名称:hidbase,代码行数:25,代码来源:mmtree64.c
示例12: _stage_2_
void
_stage_2_ ()
{
MUTEX_DECL (_stage_2_series_block_stmt_28_c_mutex_);
MUTEX_LOCK (_stage_2_series_block_stmt_28_c_mutex_);
_stage_2_inner_inarg_prep_macro__;
_stage_2_branch_block_stmt_29_c_export_decl_macro_;
{
// merge file ShiftRegister.aa, line 41
_stage_2_merge_stmt_30_c_preamble_macro_;
_stage_2_merge_stmt_30_c_postamble_macro_;
// tval := ($bitcast ($uint<16>) midpipe )// bits of buffering = 16
_stage_2_assign_stmt_34_c_macro_;
// outpipe := tval// bits of buffering = 16
_stage_2_assign_stmt_37_c_macro_;
// $report (stage_2 sent output tval )
_stage_2_stmt_39_c_macro_;
/* $place[loopback]
*/ goto loopback_29;
_stage_2_branch_block_stmt_29_c_export_apply_macro_;
}
_stage_2_inner_outarg_prep_macro__;
MUTEX_UNLOCK (_stage_2_series_block_stmt_28_c_mutex_);
}
开发者ID:madhavPdesai,项目名称:ahir,代码行数:24,代码来源:aa_c_model.c
示例13: _stage_1_
void
_stage_1_ ()
{
MUTEX_DECL (_stage_1_series_block_stmt_13_c_mutex_);
MUTEX_LOCK (_stage_1_series_block_stmt_13_c_mutex_);
_stage_1_inner_inarg_prep_macro__;
_stage_1_branch_block_stmt_14_c_export_decl_macro_;
{
// merge file ShiftRegister.aa, line 27
_stage_1_merge_stmt_15_c_preamble_macro_;
_stage_1_merge_stmt_15_c_postamble_macro_;
// tval := ($bitcast ($uint<20>) inpipe )// bits of buffering = 20
_stage_1_assign_stmt_19_c_macro_;
// midpipe := tval// bits of buffering = 20
_stage_1_assign_stmt_22_c_macro_;
// $report (stage_1 sent midpipe tval )
_stage_1_stmt_24_c_macro_;
/* $place[loopback]
*/ goto loopback_14;
_stage_1_branch_block_stmt_14_c_export_apply_macro_;
}
_stage_1_inner_outarg_prep_macro__;
MUTEX_UNLOCK (_stage_1_series_block_stmt_13_c_mutex_);
}
开发者ID:madhavPdesai,项目名称:ahir,代码行数:24,代码来源:aa_c_model.c
示例14: MUTEX_LOCK
bool String::EndsWith(const String &strNeedle) const
{
MUTEX_LOCK(str_mutex);
MUTEX_LOCK_NAMED(wait2, strNeedle.str_mutex);
// Get the offset
#ifdef SCRATCH_NO_UTF8
const char* szTemp = this->str_szBuffer + strlen(this->str_szBuffer) - strlen(strNeedle);
#else
const char* szTemp = this->str_szBuffer + (utf8size(this->str_szBuffer) - 1) - (utf8size(strNeedle) - 1);
#endif
// Make sure the needle is found
if (szTemp == nullptr) {
return false;
}
// Then compare the offset with our needle
#ifdef SCRATCH_NO_UTF8
return !strcmp(strNeedle, szTemp);
#else
return !utf8cmp(strNeedle, szTemp);
#endif
}
开发者ID:angelog,项目名称:Scratch,代码行数:24,代码来源:String.hpp
示例15: push_entry
/*
* Pushs a list_entry_t at the end of a list
*/
static inline int
push_entry(linked_list_t *list, list_entry_t *entry)
{
list_entry_t *p;
if(!entry)
return -1;
MUTEX_LOCK(list->lock);
if(list->length == 0)
{
list->head = list->tail = entry;
}
else
{
p = list->tail;
p->next = entry;
entry->prev = p;
entry->next = NULL;
list->tail = entry;
}
list->length++;
entry->list = list;
MUTEX_UNLOCK(list->lock);
return 0;
}
开发者ID:chixsh,项目名称:libhl,代码行数:27,代码来源:linklist.c
示例16: tcs_wrap_Extend
TSS_RESULT
tcs_wrap_Extend(struct tcsd_thread_data *data)
{
TCS_CONTEXT_HANDLE hContext;
UINT32 pcrIndex;
TCPA_DIGEST inDigest;
TSS_RESULT result;
TCPA_DIGEST outDigest;
if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
return TCSERR(TSS_E_INTERNAL_ERROR);
LogDebugFn("thread %ld context %x", THREAD_ID, hContext);
if (getData(TCSD_PACKET_TYPE_UINT32, 1, &pcrIndex, 0, &data->comm))
return TCSERR(TSS_E_INTERNAL_ERROR);
if (getData(TCSD_PACKET_TYPE_DIGEST, 2, &inDigest, 0, &data->comm))
return TCSERR(TSS_E_INTERNAL_ERROR);
MUTEX_LOCK(tcsp_lock);
result = TCSP_Extend_Internal(hContext, pcrIndex, inDigest, &outDigest);
MUTEX_UNLOCK(tcsp_lock);
if (result == TSS_SUCCESS) {
initData(&data->comm, 1);
if (setData(TCSD_PACKET_TYPE_DIGEST, 0, &outDigest, 0, &data->comm)) {
return TCSERR(TSS_E_INTERNAL_ERROR);
}
} else
initData(&data->comm, 0);
data->comm.hdr.u.result = result;
return TSS_SUCCESS;
}
开发者ID:ajinkya93,项目名称:netbsd-src,代码行数:36,代码来源:rpc_pcr_extend.c
示例17: mmqueue_new
/* new queue */
int mmqueue_new(MMQUEUE *mmq)
{
int rootid = -1, i = 0;
if(mmq)
{
MUTEX_LOCK(mmq->mutex);
if(mmq->state && mmq->map && mmq->state->nroots < MMQ_ROOT_MAX)
{
i = 1;
while(mmq->state->roots[i].status && i < MMQ_ROOT_MAX) ++i;
if(i < MMQ_ROOT_MAX && mmq->state->roots[i].status == 0)
{
mmq->state->roots[i].status = 1;
mmq->state->nroots++;
mmq->state->roots[i].total = 0;
mmq->state->roots[i].first = mmq->state->roots[i].last = 0;
rootid = i;
}
}
MUTEX_UNLOCK(mmq->mutex);
}
return rootid;
}
开发者ID:cnangel,项目名称:ithunder,代码行数:25,代码来源:mmqueue64.c
示例18: freerdp_chanman_find_by_open_handle
/* returns the chan_man for the open handle passed in */
static rdpChanMan *
freerdp_chanman_find_by_open_handle(int open_handle, int * pindex)
{
rdpChanManList * list;
rdpChanMan * chan_man;
int lindex;
MUTEX_LOCK(g_mutex_list);
for (list = g_chan_man_list; list; list = list->next)
{
chan_man = list->chan_man;
for (lindex = 0; lindex < chan_man->num_chans; lindex++)
{
if (chan_man->chans[lindex].open_handle == open_handle)
{
MUTEX_UNLOCK(g_mutex_list);
*pindex = lindex;
return chan_man;
}
}
}
MUTEX_UNLOCK(g_mutex_list);
return NULL;
}
开发者ID:g-reno,项目名称:FreeRDP-old,代码行数:25,代码来源:libchanman.c
示例19: bdata_oem_rapi_client_start_work
static void bdata_oem_rapi_client_start_work(struct work_struct *work)
{
struct delayed_work *dwork = container_of(work, struct delayed_work,
work);
struct data_info *di = container_of(dwork, struct data_info,
oem_rapi_client_start_work);
if (!di->rpc_client) {
MUTEX_LOCK(&di->lock);
di->rpc_client = oem_rapi_client_init();
if (!di->rpc_client || IS_ERR(di->rpc_client)) {
pr_err("%s: Failed initialize oem rapi client\n",
SEMC_BDATA_NAME);
di->rpc_client = NULL;
MUTEX_UNLOCK(&di->lock);
schedule_delayed_work(&di->oem_rapi_client_start_work,
OEM_RAPI_RECONNECT_S * HZ);
return;
}
MUTEX_UNLOCK(&di->lock);
set_platform_callbacks(di);
}
}
开发者ID:felixpegero,项目名称:R800x-2.3.3-Kernel,代码行数:24,代码来源:semc_battery_data.c
示例20: tcs_wrap_OIAP
TSS_RESULT
tcs_wrap_OIAP(struct tcsd_thread_data *data)
{
TCS_CONTEXT_HANDLE hContext;
TCS_AUTHHANDLE authHandle;
TCPA_NONCE n0;
TSS_RESULT result;
if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
return TCSERR(TSS_E_INTERNAL_ERROR);
if ((result = ctx_verify_context(hContext)))
goto done;
LogDebugFn("thread %ld context %x", THREAD_ID, hContext);
MUTEX_LOCK(tcsp_lock);
result = auth_mgr_oiap(hContext, &authHandle, &n0);
MUTEX_UNLOCK(tcsp_lock);
if (result == TSS_SUCCESS) {
initData(&data->comm, 2);
if (setData(TCSD_PACKET_TYPE_UINT32, 0, &authHandle, 0, &data->comm)) {
return TCSERR(TSS_E_INTERNAL_ERROR);
}
if (setData(TCSD_PACKET_TYPE_NONCE, 1, &n0, 0, &data->comm)) {
return TCSERR(TSS_E_INTERNAL_ERROR);
}
} else
done: initData(&data->comm, 0);
data->comm.hdr.u.result = result;
return TSS_SUCCESS;
}
开发者ID:IIJ-NetBSD,项目名称:netbsd-src,代码行数:36,代码来源:rpc_auth.c
注:本文中的MUTEX_LOCK函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论