本文整理汇总了C++中pthread_rwlockattr_init函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_rwlockattr_init函数的具体用法?C++ pthread_rwlockattr_init怎么用?C++ pthread_rwlockattr_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_rwlockattr_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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
}