本文整理汇总了C++中pthread_rwlockattr_init函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_rwlockattr_init函数的具体用法?C++ pthread_rwlockattr_init怎么用?C++ pthread_rwlockattr_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_rwlockattr_init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: rwlock_attr_init
/**
* @brief Initialize a pthread read/write lock attributes object with default values.
* @see pthread_rwlockattr_init()
* @param attr a pointer to the read/write lock attributes object to be initialized.
* @return 0 on success or an error number on failure.
*/
int rwlock_attr_init(pthread_rwlockattr_t *attr) {
#ifdef MAGMA_PEDANTIC
int result = pthread_rwlockattr_init(attr);
if (result) log_pedantic("Could not initialize the read/write lock attribute object. {pthread_rwlockattr_init = %i}", result);
return result;
#else
return pthread_rwlockattr_init(attr);
#endif
}
开发者ID:503serviceunavailable,项目名称:magma,代码行数:15,代码来源:rwlock.c
示例2: os_rwlockInit
/** \brief Initialize the rwlock taking the rwlock attributes into account
*
* \b os_rwlockInit calls \b pthread_rwlock_init to intialize the posix
* \b rwlock.
*
* In case the scope attribute is \b OS_SCOPE_SHARED, the posix
* \b rwlock "pshared" attribute is set to \b PTHREAD_PROCESS_SHARED
* otherwise it is set to \b PTHREAD_PROCESS_PRIVATE.
*/
os_result
os_rwlockInit (
os_rwlock *rwlock,
const os_rwlockAttr *rwlockAttr)
{
pthread_rwlockattr_t rwattr;
int result;
os_result rv;
assert (rwlock != NULL);
assert (rwlockAttr != NULL);
pthread_rwlockattr_init (&rwattr);
if (rwlockAttr->scopeAttr == OS_SCOPE_SHARED) {
result = pthread_rwlockattr_setpshared (&rwattr, PTHREAD_PROCESS_SHARED);
} else {
result = pthread_rwlockattr_setpshared (&rwattr, PTHREAD_PROCESS_PRIVATE);
}
if (result == 0) {
pthread_rwlock_init (rwlock, &rwattr);
}
pthread_rwlockattr_destroy (&rwattr);
if (result == 0) {
rv = os_resultSuccess;
} else {
rv = os_resultFail;
}
return rv;
}
开发者ID:diorahman,项目名称:opensplice,代码行数:37,代码来源:os_rwlock.c
示例3: heap_new
/* The 'offset' parameter is optional, but must be provided to be able to use heap_remove().
* If heap_remove() will not be used, then a negative value can be provided.
*/
heap_t heap_new(int height, ssize_t offset, int cmp(const void *x, const void *y)) {
heap_t heap;
pthread_mutexattr_t attr;
pthread_rwlockattr_t rwattr;
if (height <= 0)
height = 8;
if (cmp == NULL)
return NULL;
if (NEW(heap) == NULL)
return NULL;
heap->avail = (height << 1) - 1;
heap->curr = 0;
if ((heap->h = CALLOC(1, heap->avail * sizeof *heap->h)) == NULL) {
FREE(heap);
return NULL;
}
heap->offset = offset;
heap->cmp = cmp;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
pthread_mutex_init(&heap->lock, &attr);
pthread_mutexattr_destroy(&attr);
pthread_rwlockattr_init(&rwattr);
pthread_rwlockattr_setkind_np(&rwattr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
pthread_rwlock_init(&heap->rwlock, &rwattr);
pthread_rwlockattr_destroy(&rwattr);
return heap;
}
开发者ID:kcyeu,项目名称:xcb,代码行数:32,代码来源:heap.c
示例4: calloc
vp_lock_t *vp_lock_new(pthread_mutexattr_t *ma, pthread_condattr_t *ca)
{
vp_lock_t *l;
#ifdef HAVE_PTHREAD_RWLOCKS
pthread_rwlockattr_t attr;
#endif
l = calloc(1,sizeof(*l));
AN(l);
l->magic = VP_LOCK_MAGIC;
#ifndef HAVE_PTHREAD_RWLOCKS
l->r = l->w = l->nw = 0;
l->t = vp_lock_unset;
AZ(pthread_mutex_init(&l->m,ma));
AZ(pthread_cond_init(&l->c,ca));
#else
AZ(pthread_rwlockattr_init(&attr));
#ifdef HAVE_PTHREAD_RWLOCKATTR_SETPSHARED
AZ(pthread_rwlockattr_setpshared(&attr,PTHREAD_PROCESS_PRIVATE));
#endif
AZ(pthread_rwlock_init(&l->l,&attr));
AZ(pthread_rwlockattr_destroy(&attr));
#endif
return l;
}
开发者ID:jsipprell,项目名称:libvmod-peer,代码行数:25,代码来源:locks.c
示例5: producer_create
celix_status_t producer_create(char* name, producer_pt* producer)
{
celix_status_t status = CELIX_SUCCESS;
producer_pt lclProducer = calloc(1, sizeof(*lclProducer));
if (lclProducer != NULL) {
lclProducer->name = strdup(name);
lclProducer->utilizationStatsName = calloc(1, strlen(name) + strlen(THROUGHPUT_NAME_POSTFIX) + 1);
if (lclProducer->name != NULL && lclProducer->utilizationStatsName != NULL) {
pthread_rwlockattr_t queueLockAttr;
sprintf(lclProducer->utilizationStatsName, "%s%s", lclProducer->name, (char*) THROUGHPUT_NAME_POSTFIX);
pthread_rwlockattr_init(&queueLockAttr);
pthread_rwlockattr_setkind_np(&queueLockAttr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
pthread_rwlock_init(&lclProducer->queueLock, &queueLockAttr);
lclProducer->queueServices = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
(*producer) = lclProducer;
}
else {
status = CELIX_ENOMEM;
}
} else {
status = CELIX_ENOMEM;
}
return status;
}
开发者ID:NausJessy,项目名称:demonstrator,代码行数:33,代码来源:producer_impl.c
示例6: diameter_create_lock
static uint32_t diameter_create_lock(diameter_lock_handle *lock)
{
pthread_rwlockattr_t rwlock_attr;
pthread_rwlock_t *rwlock;
int ret;
ret = pthread_rwlockattr_init(&rwlock_attr);
if (ret)
return DIAMETER_CB_ERROR;
ret = pthread_rwlockattr_setkind_np(&rwlock_attr,
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
if (ret)
return DIAMETER_CB_ERROR;
rwlock = nkn_malloc_type(sizeof(pthread_rwlock_t), mod_diameter_t);
if (rwlock == NULL)
return DIAMETER_CB_ERROR;
ret = pthread_rwlock_init(rwlock, &rwlock_attr);
if (ret) {
free(rwlock);
return DIAMETER_CB_ERROR;
}
*lock = rwlock;
return DIAMETER_CB_OK;
}
开发者ID:skizhak,项目名称:open-media-flow-controller,代码行数:30,代码来源:diameter_system.c
示例7: main
int main()
{
pthread_rwlockattr_t rwla;
int pshared;
int rc = 0;
#ifndef PTHREAD_PROCESS_SHARED
printf("process-shared attribute is not available for testing\n");
return PTS_UNSUPPORTED;
#endif
/* Initialize a rwlock attributes object */
if (pthread_rwlockattr_init(&rwla) != 0)
{
printf("Error at pthread_rwlockattr_init()\n");
return PTS_UNRESOLVED;
}
/* The default 'pshared' attribute should be PTHREAD_PROCESS_PRIVATE */
rc = pthread_rwlockattr_getpshared(&rwla, &pshared);
if (rc != 0)
{
printf("Test FAILED: Error at pthread_rwlockattr_getpshared(): %d\n", rc);
return PTS_FAIL;
}
if (pshared != PTHREAD_PROCESS_PRIVATE)
{
printf("Test FAILED: Incorrect default pshared value: %d\n", pshared);
return PTS_FAIL;
}
printf("Test PASSED\n");
return PTS_PASS;
}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:35,代码来源:1-1.c
示例8: main
int main(void)
{
pthread_rwlockattr_t rwla;
int rc;
/* Initialize a rwlock attributes object */
rc = pthread_rwlockattr_init(&rwla);
if (rc != 0) {
printf("Error at pthread_rwlockattr_init(), error code: %d\n",
rc);
return PTS_UNRESOLVED;
}
/* Destroy the rwlock attributes object */
rc = pthread_rwlockattr_destroy(&rwla);
if (rc != 0) {
printf
("Error at pthread_rwlockattr_destroy(), error code: %d\n",
rc);
printf("Test FAILED\n");
return PTS_FAIL;
}
printf("Test PASSED\n");
return PTS_PASS;
}
开发者ID:kraj,项目名称:ltp,代码行数:27,代码来源:1-1.c
示例9: rw_init_flags
void
rw_init_flags(struct rwlock *rw, const char *name, int opts)
{
pthread_rwlockattr_t attr;
int flags;
MPASS((opts & ~(RW_DUPOK | RW_NOPROFILE | RW_NOWITNESS | RW_QUIET |
RW_RECURSE)) == 0);
ASSERT_ATOMIC_LOAD_PTR(rw->rw_lock,
("%s: rw_lock not aligned for %s: %p", __func__, name,
&rw->rw_lock));
flags = LO_UPGRADABLE;
if (opts & RW_DUPOK)
flags |= LO_DUPOK;
if (opts & RW_NOPROFILE)
flags |= LO_NOPROFILE;
if (!(opts & RW_NOWITNESS))
flags |= LO_WITNESS;
if (opts & RW_RECURSE)
flags |= LO_RECURSABLE;
if (opts & RW_QUIET)
flags |= LO_QUIET;
lock_init(&rw->lock_object, &lock_class_rw, name, NULL, flags);
pthread_rwlockattr_init(&attr);
pthread_rwlock_init(&rw->rw_lock, &attr);
}
开发者ID:diegows,项目名称:wanproxy,代码行数:28,代码来源:uinet_kern_rwlock.c
示例10: __ast_rwlock_init
int __ast_rwlock_init(int tracking, const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
{
int res;
pthread_rwlockattr_t attr;
#ifdef DEBUG_THREADS
#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
int canlog = strcmp(filename, "logger.c") & t->tracking;
if (t->lock != ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
__ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is already initialized.\n",
filename, lineno, func, rwlock_name);
return 0;
}
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
if ((t->tracking = tracking)) {
ast_reentrancy_init(&t->track);
}
#endif /* DEBUG_THREADS */
pthread_rwlockattr_init(&attr);
#ifdef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NP);
#endif
res = pthread_rwlock_init(&t->lock, &attr);
pthread_rwlockattr_destroy(&attr);
return res;
}
开发者ID:akodakim,项目名称:Asterisk-Call-Center,代码行数:32,代码来源:lock.c
示例11: main
int main()
{
pthread_rwlockattr_t rwa;
pthread_rwlock_t rwl1, rwl2;
int rc;
/* Initialize a read-write lock attributes object */
rc = pthread_rwlockattr_init(&rwa);
if (rc != 0)
{
printf("Error at pthread_rwlockattr_init(), returns %d\n", rc);
return PTS_UNRESOLVED;
}
if ((rc = pthread_rwlock_init(&rwl1, &rwa)) != 0)
{
printf("Error at 1st pthread_rwlock_init()\n");
return PTS_UNRESOLVED;
}
if ((rc = pthread_rwlock_init(&rwl2, &rwa)) != 0)
{
printf("Error at 2nd pthread_rwlock_init()\n");
return PTS_UNRESOLVED;
}
if ((rc = pthread_rwlock_rdlock(&rwl1)) != 0)
{
printf("Error at pthread_rwlock_rdlock(): rwl1\n");
return PTS_UNRESOLVED;
}
if ((rc = pthread_rwlockattr_destroy(&rwa)) != 0)
{
printf("Error at pthread_rwlockattr_destory()\n");
return PTS_UNRESOLVED;
}
if ((rc = pthread_rwlock_unlock(&rwl1)) != 0)
{
printf("Error at pthread_rwlock_unlock: rwl1\n");
printf("Test Failed.\n");
return PTS_FAIL;
}
if ((rc = pthread_rwlock_rdlock(&rwl2)) != 0)
{
printf("Error at pthread_rwlock_rdlock():rwl2\n");
printf("Test Failed.\n");
return PTS_FAIL;
}
if ((rc = pthread_rwlock_unlock(&rwl2)) != 0)
{
printf("Error at pthread_rwlock_unlock:rwl2\n");
printf("Test Failed.\n");
return PTS_FAIL;
}
printf("Test PASSED\n");
return PTS_PASS;
}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:60,代码来源:2-1.c
示例12: pthread_rwlockattr_init
cRwLock::cRwLock(bool PreferWriter)
{
pthread_rwlockattr_t attr;
pthread_rwlockattr_init(&attr);
pthread_rwlockattr_setkind_np(&attr, PreferWriter ? PTHREAD_RWLOCK_PREFER_WRITER_NP : PTHREAD_RWLOCK_PREFER_READER_NP);
pthread_rwlock_init(&rwlock, &attr);
}
开发者ID:flensrocker,项目名称:vdr,代码行数:7,代码来源:thread.c
示例13: noit_log_init_rwlock
static void
noit_log_init_rwlock(noit_log_stream_t ls) {
pthread_rwlockattr_t attr;
pthread_rwlockattr_init(&attr);
pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
pthread_rwlock_init(ls->lock, &attr);
}
开发者ID:russellhaering,项目名称:reconnoiter,代码行数:7,代码来源:noit_log.c
示例14: get_thread_attr
int get_thread_attr()
{
pthread_attr_t attr;
pthread_attr_init(&attr);
print_thread_attr(&attr);
pthread_attr_destroy(&attr);
printf("\n");
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
print_mutexattr(&mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
printf("\n");
pthread_rwlockattr_t rwlock_attr;
pthread_rwlockattr_init(&rwlock_attr);
print_rwlockattr(&rwlock_attr);
pthread_rwlockattr_destroy(&rwlock_attr);
printf("\n");
pthread_condattr_t cond_attr;
pthread_condattr_init(&cond_attr);
print_condattr(&cond_attr);
pthread_condattr_destroy(&cond_attr);
printf("\n");
return THREAD_ATTR_OK;
}
开发者ID:haveTryTwo,项目名称:utils,代码行数:28,代码来源:thread_attr.c
示例15: uwsgi_lock_fast_init
struct uwsgi_lock_item *uwsgi_rwlock_fast_init(char *id) {
#ifdef OBSOLETE_LINUX_KERNEL
return uwsgi_lock_fast_init(id);
#else
pthread_rwlockattr_t attr;
struct uwsgi_lock_item *uli = uwsgi_register_lock(id, 1);
if (pthread_rwlockattr_init(&attr)) {
uwsgi_log("unable to allocate rwlock structure\n");
exit(1);
}
if (pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED)) {
uwsgi_log("unable to share rwlock\n");
exit(1);
}
if (pthread_rwlock_init((pthread_rwlock_t *) uli->lock_ptr, &attr)) {
uwsgi_log("unable to initialize rwlock\n");
exit(1);
}
pthread_rwlockattr_destroy(&attr);
uli->can_deadlock = 1;
return uli;
#endif
}
开发者ID:thrashaholic,项目名称:uwsgi,代码行数:35,代码来源:lock.c
示例16: printf
CRWLock::CRWLock()
{
pthread_rwlockattr_t rwlock_attr;
int res;
if((res = pthread_rwlockattr_init(&rwlock_attr)) != 0)
{
printf("file: "__FILE__", line: %d, " \
"call pthread_rwlockattr_init failed, err: %s\n", \
__LINE__, strerror(res));
throw res;
}
if((res = pthread_rwlockattr_setpshared(&rwlock_attr, \
PTHREAD_PROCESS_SHARED)) != 0)
{
printf("file: "__FILE__", line: %d, " \
"set rwlock attr to PTHREAD_PROCESS_SHARED failed, err: %s\n", \
__LINE__, strerror(res));
throw res;
}
if((res = pthread_rwlock_init(&m_rwlock, &rwlock_attr)) != 0)
{
printf("file: "__FILE__", line: %d, " \
"call pthread_rwlock_init failed, err: %s\n", \
__LINE__, strerror(res));
throw res;
}
pthread_rwlockattr_destroy(&rwlock_attr);
}
开发者ID:leslieyuchen,项目名称:kunlun,代码行数:31,代码来源:rwlock.cpp
示例17: test_rwlock_init
void test_rwlock_init(void) {
int rc;
pthread_rwlockattr_t attrs;
rc = pthread_rwlockattr_init(&attrs);
ASSERT_EQ(rc, 0);
int shared = -1;
rc = pthread_rwlockattr_getpshared(&attrs, &shared);
ASSERT_EQ(rc, 0);
ASSERT_EQ(shared, PTHREAD_PROCESS_PRIVATE);
rc = pthread_rwlockattr_setpshared(&attrs, PTHREAD_PROCESS_SHARED);
#ifndef __GLIBC__
/*
* glibc's pthread_rwlockattr_setpshared doesn't currently fail
* with PTHREAD_PROCESS_SHARED. TODO(sbc): remove this once
* we fix the glibc bug:
* https://code.google.com/p/nativeclient/issues/detail?id=4142
*/
ASSERT_EQ(rc, EINVAL);
#endif
rc = pthread_rwlockattr_setpshared(&attrs, PTHREAD_PROCESS_PRIVATE);
ASSERT_EQ(rc, 0);
rc = pthread_rwlock_init(&g_rwlock, &attrs);
ASSERT_EQ(rc, 0);
rc = pthread_rwlockattr_destroy(&attrs);
ASSERT_EQ(rc, 0);
}
开发者ID:dsagal,项目名称:native_client,代码行数:26,代码来源:rwlock_test.c
示例18: main
int main() {
{
pthread_mutexattr_t attr;
if (pthread_mutexattr_init(&attr) != 0) {
abort();
}
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL) != 0) {
abort();
}
if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE) != 0) {
abort();
}
}
{
pthread_rwlockattr_t attr;
if (pthread_rwlockattr_init(&attr) != 0) {
abort();
}
if (pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE) != 0) {
abort();
}
}
// TODO(hamaji): PTHREAD_MUTEX_INITIALIZER has a different implementation...
#if 0
if (pthread_mutex_lock(&g_mutex) != 0) {
abort();
}
#endif
}
开发者ID:stonestrong,项目名称:maloader,代码行数:31,代码来源:pthread.c
示例19: cih_pkginit
/**
* @brief Initialize the package.
*/
void cih_pkginit(void)
{
pthread_rwlockattr_t rwlock_attr;
cih_partition_t *cp;
uint32_t npart;
uint32_t cache_sz = 32767; /* XXX */
int ix;
/* avoid writer starvation */
pthread_rwlockattr_init(&rwlock_attr);
#ifdef GLIBC
pthread_rwlockattr_setkind_np(
&rwlock_attr,
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
#endif
npart = nfs_param.cache_param.nparts;
cih_fhcache.npart = npart;
cih_fhcache.partition = gsh_calloc(npart, sizeof(cih_partition_t));
for (ix = 0; ix < npart; ++ix) {
cp = &cih_fhcache.partition[ix];
cp->part_ix = ix;
pthread_rwlock_init(&cp->lock, &rwlock_attr);
avltree_init(&cp->t, cih_fh_cmpf, 0 /* must be 0 */);
cih_fhcache.cache_sz = cache_sz;
cp->cache = gsh_calloc(cache_sz, sizeof(struct avltree_node *));
}
initialized = true;
}
开发者ID:tsunamiwang,项目名称:nfs-ganesha-anand,代码行数:31,代码来源:cache_inode_hash.c
示例20: main
int main()
{
int cnt = 0;
pthread_rwlockattr_t rwlockattr;
if(pthread_rwlockattr_init(&rwlockattr) != 0)
{
printf("Error at pthread_rwlockattr_init()\n");
return PTS_UNRESOLVED;
}
if(pthread_rwlock_init(&rwlock, &rwlockattr) != 0)
{
printf("Test FAILED: Error in pthread_rwlock_init()\n");
return PTS_FAIL;
}
while(cnt++ < COUNT)
{
if(pthread_rwlock_rdlock(&rwlock) != 0)
{
printf("Test FAILED: cannot get read lock on %dth loop\n", cnt);
return PTS_FAIL;
}
if(pthread_rwlock_unlock(&rwlock) != 0)
{
printf("Test FAILED: cannot release read lock on %dth loop\n", cnt);
return PTS_FAIL;
}
if(pthread_rwlock_wrlock(&rwlock) != 0)
{
printf("Test FAILED: cannot get write lock on %dth loop\n", cnt);
return PTS_FAIL;
}
if(pthread_rwlock_unlock(&rwlock) != 0)
{
printf("Test FAILED: cannot release write lock on %dth loop\n", cnt);
return PTS_FAIL;
}
}
if(pthread_rwlock_destroy(&rwlock) != 0)
{
printf("Error at pthread_rwlockattr_destroy()\n");
return PTS_UNRESOLVED;
}
if(pthread_rwlockattr_destroy(&rwlockattr) != 0)
{
printf("Error at pthread_rwlockattr_destroy()\n");
return PTS_UNRESOLVED;
}
printf("Test PASSED\n");
return PTS_PASS;
}
开发者ID:8l,项目名称:rose,代码行数:59,代码来源:3-1.c
注:本文中的pthread_rwlockattr_init函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论