本文整理汇总了C++中pthread_rwlock_rdlock函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_rwlock_rdlock函数的具体用法?C++ pthread_rwlock_rdlock怎么用?C++ pthread_rwlock_rdlock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_rwlock_rdlock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _dessert_cli_cmd_logging
/** command "show logging" */
int _dessert_cli_cmd_logging(struct cli_def* cli, char* command, char* argv[], int argc) {
pthread_rwlock_rdlock(&_dessert_logrbuf_len_lock);
int i = 0;
int max = _dessert_logrbuf_len - 1;
char* line;
if(_dessert_logrbuf_len < 1) {
cli_print(
cli,
"logging to ringbuffer is disabled - use \"logging ringbuffer [int]\" in config-mode first");
pthread_rwlock_unlock(&_dessert_logrbuf_len_lock);
return CLI_ERROR;
}
if(argc == 1) {
int max2 = (int) strtol(argv[0], NULL, 10);
if(max2 > 0) {
max = max2;
}
}
/* where to start and print? */
if(max > _dessert_logrbuf_used) {
max = _dessert_logrbuf_used;
}
i = _dessert_logrbuf_cur - max - 1;
if(i < 0) {
i += _dessert_logrbuf_len;
}
while(max > 0) {
i++;
max--;
if(i == _dessert_logrbuf_len) {
i = 0;
}
line = _dessert_logrbuf + (DESSERT_LOGLINE_MAX * i);
cli_print(cli, "%s", line);
}
pthread_rwlock_unlock(&_dessert_logrbuf_len_lock);
return CLI_OK;
}
示例2: rw_lock_read_lock
void rw_lock_read_lock(rw_lock_t* lock)
{
#ifdef __MINGW32__
EnterCriticalSection(&lock->readlock);
EnterCriticalSection(&lock->lock);
lock->readers++;
ResetEvent(lock->writelock);
LeaveCriticalSection(&lock->lock);
LeaveCriticalSection(&lock->readlock);
#else
pthread_rwlock_rdlock(lock);
#endif
}
示例3: writer
void * writer() {
for (int i = 0; i < 5; i++) {
pthread_rwlock_rdlock(&rwlock);
pthread_rwlock_trywrlock(&rwlock);
value += 1;
pthread_rwlock_unlock(&rwlock);
sleep(i);
}
pthread_exit(NULL);
}
示例4: list_lookup
struct list * list_lookup(int lookup_id)
{
struct list *curr;
int rv;
rv=pthread_rwlock_rdlock(&rw); // 只讀表,因此以讀模式申請讀寫鎖
check_error(rv, "lookup: read lock");
for (curr=list_head; curr !=NULL; curr=curr->next) // 查詢記錄位置
if (curr->id >= lookup_id)
break;
if (curr != NULL && curr->id != lookup_id)
curr = (struct list *)NULL; // 沒有找到
rv = pthread_rwlock_unlock(&rw); // 釋放讀寫鎖
check_error(rv, "add: write unlock");
return (curr);
}
示例5: cache_get
static int cache_get(lua_State * L) {
size_t len1,len2;
const char * key_l=lua_tolstring(L,1,&len1);
char * val=NULL;
pthread_rwlock_rdlock(&rwlock);
val=hashtable_get(ht,key_l,&len2);
//printf("%p %s %u\n",val,val,len2);
if(val==NULL) {
pthread_rwlock_unlock(&rwlock);
return 0;
}
lua_pushlstring(L,val,len2);
pthread_rwlock_unlock(&rwlock);
return 1;
}
示例6: pthread_rwlock_rdlock
struct gate_info *gate_info_manager_t::get_best_gate_incref(uint64_t uid)
{
struct gate_info *info = NULL;
pthread_rwlock_rdlock(&rwlock);
size_t sz = gate_infos.size();
if (sz > 0) {
int idx = (int)(uid % (uint64_t)sz);
info = gate_infos[idx];
gate_info_incref(info);
}
pthread_rwlock_unlock(&rwlock);
return info;
}
示例7: runpath_list_fprintf
void runpath_list_fprintf(runpath_list_type * list ) {
pthread_rwlock_rdlock( &list->lock );
{
FILE * stream = util_mkdir_fopen( list->export_file , "w");
const char * line_fmt = runpath_list_get_line_fmt( list );
int index;
vector_sort( list->list , runpath_node_cmp );
for (index =0; index < vector_get_size( list->list ); index++) {
const runpath_node_type * node = runpath_list_iget_node__( list , index );
runpath_node_fprintf( node , line_fmt , stream );
}
fclose( stream );
}
pthread_rwlock_unlock( &list->lock );
}
示例8: job_find
/*
* Find a job for the given thread ID.
*/
struct job *
job_find(struct queue *qp, pthread_t id)
{
struct job *jp;
if (pthread_rwlock_rdlock(&qp->q_lock) != 0)
return NULL;
for (jp = qp->q_head; jp != NULL; jp = jp->j_next)
if (pthread_equal(jp->j_id, id))
break;
pthread_rwlock_unlock(&qp->q_lock);
return jp;
}
示例9: pmip_cache_iterate
//---------------------------------------------------------------------------------------------------------------------
int pmip_cache_iterate(int (*func) (void *, void *), void *arg)
{
int err;
int mutex_return_code;
mutex_return_code = pthread_rwlock_rdlock(&pmip_lock);
if (mutex_return_code != 0) {
dbg("pthread_rwlock_rdlock(&pmip_lock) %s\n", strerror(mutex_return_code));
}
err = pmip_hash_iterate(&g_pmip_hash, func, arg);
mutex_return_code = pthread_rwlock_unlock(&pmip_lock);
if (mutex_return_code != 0) {
dbg("pthread_rwlock_unlock(&pmip_lock) %s\n", strerror(mutex_return_code));
}
return err;
}
示例10: TSReleaseAssert
void RateLimiter::Release(int counter_index, const char * key, uint64_t amount) {
TSReleaseAssert(!pthread_rwlock_rdlock(&rwlock_keymap_));
std::map<const char *,LimiterState *>::iterator it = keymap_.find(key);
TSReleaseAssert(!pthread_rwlock_unlock(&rwlock_keymap_));
TSReleaseAssert( it != keymap_.end() );
LimiterState * state = it->second;
TSMutexLock(update_mutex_);
state->set_taken(counter_index, state->taken(counter_index) - amount);
dbg("released amount, currently taken %f", state->taken(counter_index));
TSMutexUnlock(update_mutex_);
}
示例11: assert
//---------------------------------------------------------------------------------------------------------------------
pmip_entry_t *pmip_cache_get(const struct in6_addr * our_addr, const struct in6_addr * peer_addr)
{
pmip_entry_t *bce;
assert(peer_addr && our_addr);
pthread_rwlock_rdlock(&pmip_lock);
bce = hash_get(&g_pmip_hash, our_addr, peer_addr);
if (bce) {
pthread_rwlock_wrlock(&bce->lock);
//dbg("PMIP cache entry is found for: %x:%x:%x:%x:%x:%x:%x:%x with type %d\n", NIP6ADDR(&bce->mn_hw_address), (bce->type));
} else {
pthread_rwlock_unlock(&pmip_lock);
//dbg("PMIP cache entry is NOT found for %x:%x:%x:%x:%x:%x:%x:%x <-> %x:%x:%x:%x:%x:%x:%x:%x\n", NIP6ADDR(our_addr), NIP6ADDR(peer_addr));
}
return bce;
}
示例12: pthread_rwlock_rdlock
/* Looks for the photoset specified in the argument.
* Returns pointer to the stored cached_information
* or 0 if not found.
*/
cached_information *photoset_lookup(const char *photoset) {
cached_photoset *cps;
cached_information *ci_copy = NULL;
pthread_rwlock_rdlock(&cache_lock);
if(check_cache())
goto fail;
cps = g_hash_table_lookup(photoset_ht, photoset);
if(cps)
ci_copy = copy_cached_info(&(cps->ci));
fail: pthread_rwlock_unlock(&cache_lock);
return ci_copy;
}
示例13: Var_bind
/**
* \brief Bind to a variable
*
* Subscribe to the give variable and automatically populate its value in the float whose reference is passed
*
* \param name Name of the variable to subscribe to
* \param store_to Pointer to a float to store the value of the variable when it is updated
* \return 0 on success
*/
int Var_bind(char* name, float* store_to) {
Subscription* s;
Var_subscribe(name);
pthread_rwlock_rdlock(&subscriptions_lock); {
s = Dictionary_get(subscriptions, name);
s->writeback = store_to;
}
pthread_rwlock_unlock(&subscriptions_lock);
(*s->writeback) = s->current;
return 0;
}
示例14: __dcethread_child_fork
static void
__dcethread_child_fork(void)
{
unsigned int i;
pthread_rwlock_rdlock(&atfork_lock);
for (i = 0; i < atfork_handlers_len; i++)
{
if (atfork_handlers[i].child_fork)
atfork_handlers[i].child_fork(atfork_handlers[i].user_state);
}
pthread_rwlock_unlock(&atfork_lock);
}
示例15: rpmlogCtxAcquire
/* Force log context acquisition through a function */
static rpmlogCtx rpmlogCtxAcquire(int write)
{
static struct rpmlogCtx_s _globalCtx = { PTHREAD_RWLOCK_INITIALIZER,
RPMLOG_UPTO(RPMLOG_NOTICE),
0, NULL, NULL, NULL, NULL };
rpmlogCtx ctx = &_globalCtx;
/* XXX: errors should be handled */
if (write)
pthread_rwlock_wrlock(&ctx->lock);
else
pthread_rwlock_rdlock(&ctx->lock);
return ctx;
}