本文整理汇总了C++中pthread_rwlock_wrlock函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_rwlock_wrlock函数的具体用法?C++ pthread_rwlock_wrlock怎么用?C++ pthread_rwlock_wrlock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_rwlock_wrlock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: time
/**
* @short Generates a new response object
* @memberof onion_response_t
*
* This response is generated from a request, and gets from there the writer and writer data.
*
* Also fills some important data, as server Id, License type, and the default content type.
*
* Default content type is HTML, as normally this is what is needed. This is nontheless just
* the default, and can be changed to any other with a call to:
*
* onion_response_set_header(res, "Content-Type", my_type);
*
* The response object must be freed with onion_response_free, which also returns the keep alive
* status.
*
* onion_response objects are passed by onion internally to process the request, and should not be
* created by user normally. Nontheless the option exist.
*
* @returns An onion_response object for that request.
*/
onion_response *onion_response_new(onion_request *req){
onion_response *res=onion_low_malloc(sizeof(onion_response));
res->request=req;
res->headers=onion_dict_new();
res->code=200; // The most normal code, so no need to overwrite it in other codes.
res->flags=0;
res->sent_bytes_total=res->length=res->sent_bytes=0;
res->buffer_pos=0;
#ifndef DONT_USE_DATE_HEADER
{
time_t t;
struct tm *tmp;
t = time(NULL);
// onion_response_last_date_header is set to t later. It should be more or less atomic.
// If not no big deal, as we will just use slightly more CPU on those "ephemeral" moments.
if (t!=onion_response_last_time){
ONION_DEBUG("Recalculating date header");
char current_datetime[200];
tmp = localtime(&t);
if (tmp == NULL) {
perror("localtime");
exit(EXIT_FAILURE);
}
if (strftime(current_datetime, sizeof(current_datetime), "%a, %d %b %Y %H:%M:%S %Z", tmp) == 0) {
fprintf(stderr, "strftime returned 0");
exit(EXIT_FAILURE);
}
// Risky, not using mutex...
#ifdef HAVE_PTHREAD
pthread_rwlock_wrlock(&onion_response_date_lock);
#endif
onion_response_last_time=t;
if (onion_response_last_date_header)
onion_low_free(onion_response_last_date_header);
onion_response_last_date_header=onion_low_strdup(current_datetime);
#ifdef HAVE_PTHREAD
pthread_rwlock_unlock(&onion_response_date_lock);
#endif
}
}
#ifdef HAVE_PTHREAD
pthread_rwlock_rdlock(&onion_response_date_lock);
#endif
assert(onion_response_last_date_header);
onion_dict_add(res->headers, "Date", onion_response_last_date_header, OD_DUP_VALUE);
#ifdef HAVE_PTHREAD
pthread_rwlock_unlock(&onion_response_date_lock);
#endif
#endif // USE_DATE_HEADER
// Sorry for the advertisment.
onion_dict_add(res->headers, "Server", "libonion v" ONION_VERSION " - coralbits.com", 0);
onion_dict_add(res->headers, "Content-Type", "text/html", 0); // Maybe not the best guess, but really useful.
//time_t t=time(NULL);
//onion_dict_add(res->headers, "Date", asctime(localtime(&t)), OD_DUP_VALUE);
return res;
}
开发者ID:keqingyuan,项目名称:onion,代码行数:85,代码来源:response.c
示例2: pfring_mod_recv
int pfring_mod_recv(pfring *ring, u_char** buffer, u_int buffer_len,
struct pfring_pkthdr *hdr,
u_int8_t wait_for_incoming_packet) {
int rc = 0;
if(ring->is_shutting_down || (ring->buffer == NULL))
return(-1);
ring->break_recv_loop = 0;
do_pfring_recv:
if(ring->break_recv_loop)
return(0);
if(unlikely(ring->reentrant))
pthread_rwlock_wrlock(&ring->rx_lock);
//rmb();
if(pfring_there_is_pkt_available(ring)) {
char *bucket = &ring->slots[ring->slots_info->remove_off];
u_int32_t next_off, real_slot_len, bktLen;
/* Keep it for packet sending */
ring->tx.last_received_hdr = (struct pfring_pkthdr*)bucket;
memcpy(hdr, bucket, ring->slot_header_len);
//if((hdr->caplen > 1518) || (hdr->len > 1518))
// fprintf(stderr, "%s:%d-----> Invalid packet length [caplen: %u][len: %u]"
// "[hdr len: %u][slot len: %u][real slot len: %u]"
// "[insert_off: %u][remove_off: %u][tot_insert: %lu][tot_read: %lu]\n",
// __FUNCTION__, __LINE__, hdr->caplen, hdr->len, ring->slot_header_len,
// ring->slots_info->slot_len, ring->slot_header_len+hdr->caplen,
// ring->slots_info->insert_off, ring->slots_info->remove_off,
// ring->slots_info->tot_insert, ring->slots_info->tot_read);
if(ring->slot_header_len != sizeof(struct pfring_pkthdr)) /* using short_pkt_header, parsed_header_len is not available */
bktLen = hdr->caplen;
else
bktLen = hdr->caplen + hdr->extended_hdr.parsed_header_len;
real_slot_len = ring->slot_header_len + bktLen;
if(bktLen > buffer_len) bktLen = buffer_len;
if(buffer_len == 0)
*buffer = (u_char*)&bucket[ring->slot_header_len];
else
memcpy(*buffer, &bucket[ring->slot_header_len], bktLen);
next_off = ring->slots_info->remove_off + real_slot_len;
if((next_off + ring->slots_info->slot_len) > (ring->slots_info->tot_mem - sizeof(FlowSlotInfo)))
next_off = 0;
#ifdef USE_MB
/* This prevents the compiler from reordering instructions.
* http://en.wikipedia.org/wiki/Memory_ordering#Compiler_memory_barrier */
gcc_mb();
#endif
ring->slots_info->tot_read++, ring->slots_info->remove_off = next_off;
/* Ugly safety check */
if(unlikely((ring->slots_info->tot_insert == ring->slots_info->tot_read)
&& (ring->slots_info->remove_off > ring->slots_info->insert_off))) {
ring->slots_info->remove_off = ring->slots_info->insert_off;
fprintf(stderr, " *** corrupted ring buffer indexes (recovered) ***\n");
}
if(unlikely(ring->reentrant)) pthread_rwlock_unlock(&ring->rx_lock);
return(1);
}
/* Nothing to do: we need to wait */
if(unlikely(ring->reentrant)) pthread_rwlock_unlock(&ring->rx_lock);
if(wait_for_incoming_packet) {
rc = pfring_poll(ring, ring->poll_duration);
if((rc == -1) && (errno != EINTR))
return(-1);
else
goto do_pfring_recv;
}
return(0); /* non-blocking, no packet */
}
开发者ID:a5216652166,项目名称:ss,代码行数:87,代码来源:pfring_mod.c
示例3: generate_config
void generate_config(BUFFER *wb, int only_changed)
{
int i, pri;
struct config *co;
struct config_value *cv;
for(i = 0; i < 3 ;i++) {
switch(i) {
case 0:
buffer_strcat(wb,
"# NetData Configuration\n"
"# You can uncomment and change any of the options below.\n"
"# The value shown in the commented settings, is the default value.\n"
"\n# global netdata configuration\n");
break;
case 1:
buffer_strcat(wb, "\n\n# per plugin configuration\n");
break;
case 2:
buffer_strcat(wb, "\n\n# per chart configuration\n");
break;
}
pthread_rwlock_wrlock(&config_rwlock);
for(co = config_root; co ; co = co->next) {
if(strcmp(co->name, "global") == 0 || strcmp(co->name, "plugins") == 0) pri = 0;
else if(strncmp(co->name, "plugin:", 7) == 0) pri = 1;
else pri = 2;
if(i == pri) {
int used = 0;
int changed = 0;
int count = 0;
pthread_rwlock_wrlock(&co->rwlock);
for(cv = co->values; cv ; cv = cv->next) {
used += (cv->flags && CONFIG_VALUE_USED)?1:0;
changed += (cv->flags & CONFIG_VALUE_CHANGED)?1:0;
count++;
}
pthread_rwlock_unlock(&co->rwlock);
if(!count) continue;
if(only_changed && !changed) continue;
if(!used) {
buffer_sprintf(wb, "\n# node '%s' is not used.", co->name);
}
buffer_sprintf(wb, "\n[%s]\n", co->name);
pthread_rwlock_wrlock(&co->rwlock);
for(cv = co->values; cv ; cv = cv->next) {
if(used && !(cv->flags & CONFIG_VALUE_USED)) {
buffer_sprintf(wb, "\n\t# option '%s' is not used.\n", cv->name);
}
buffer_sprintf(wb, "\t%s%s = %s\n", ((!(cv->flags & CONFIG_VALUE_CHANGED)) && (cv->flags & CONFIG_VALUE_USED))?"# ":"", cv->name, cv->value);
}
pthread_rwlock_unlock(&co->rwlock);
}
}
pthread_rwlock_unlock(&config_rwlock);
}
}
开发者ID:MulticsYin,项目名称:netdata,代码行数:69,代码来源:appconfig.c
示例4: onion_dict_lock_write
/**
* @short Do a read lock. Several can lock for reading, but only can be writing.
* @memberof onion_dict_t
*/
void onion_dict_lock_write(onion_dict *dict){
#ifdef HAVE_PTHREADS
pthread_rwlock_wrlock(&dict->lock);
#endif
}
开发者ID:jlsandell,项目名称:onion,代码行数:9,代码来源:dict.c
示例5: xsltp_rwlock_wrlock
void xsltp_rwlock_wrlock(xsltp_rwlock_t *rwlock) {
if (pthread_rwlock_wrlock(&rwlock->rwlock) != 0) {
perror("Write lock failed");
}
}
开发者ID:gitpan,项目名称:XML-LibXSLT-Processor,代码行数:5,代码来源:xsltp_pthread_thread.c
示例6: main
int main()
{
int cnt = 0;
pthread_t rd_thread1, rd_thread2;
if(pthread_rwlock_init(&rwlock, NULL) != 0)
{
printf("main: Error at pthread_rwlock_init()\n");
return PTS_UNRESOLVED;
}
printf("main: attempt read lock\n");
if(pthread_rwlock_rdlock(&rwlock) != 0)
{
printf("main: Error at pthread_rwlock_rdlock()\n");
return PTS_UNRESOLVED;
}
printf("main: acquired read lock\n");
thread_state = NOT_CREATED_THREAD;
printf("main: create rd_thread1\n");
if(pthread_create(&rd_thread1, NULL, fn_rd, NULL) != 0)
{
printf("main: Error when creating rd_thread1\n");
return PTS_UNRESOLVED;
}
/* If the shared data is not altered by child after 5 seconds,
we regard it as blocked */
/* we expect the thread not to block */
cnt = 0;
do{
sleep(1);
}while (thread_state !=EXITING_THREAD && cnt++ < 5);
if(thread_state == ENTERED_THREAD)
{
/* the child thread started but blocked */
printf("Test FAILED: rd_thread1 blocked on pthread_rwlock_timedrdlock()\n");
exit(PTS_FAIL);
}
else if(thread_state != EXITING_THREAD)
{
printf("Unexpected thread state %d\n", thread_state);
exit(PTS_UNRESOLVED);
}
if(pthread_join(rd_thread1, NULL) != 0)
{
printf("main: Error when join rd_thread1\n");
exit(PTS_UNRESOLVED);
}
printf("main: unlock read lock\n");
if(pthread_rwlock_unlock(&rwlock) != 0)
{
printf("main: Error when release read lock\n");
return PTS_UNRESOLVED;
}
printf("main: attempt write lock\n");
if(pthread_rwlock_wrlock(&rwlock) != 0)
{
printf("main: Failed to get write lock\n");
return PTS_UNRESOLVED;
}
printf("main: acquired write lock\n");
thread_state = NOT_CREATED_THREAD;
printf("main: create rd_thread2\n");
if(pthread_create(&rd_thread2, NULL, fn_rd, NULL) != 0)
{
printf("main: Failed to create rd_thread2\n");
return PTS_UNRESOLVED;
}
/* we expect rd_thread2 to block and timeout. */
cnt = 0;
do{
sleep(1);
}while (thread_state !=EXITING_THREAD && cnt++ < 5);
if(thread_state == EXITING_THREAD)
{
/* the child thread does not block, check the time interval */
struct timeval time_diff;
time_diff.tv_sec = currsec2.tv_sec - currsec1.tv_sec;
time_diff.tv_usec = currsec2.tv_usec - currsec1.tv_usec;
if (time_diff.tv_usec < 0)
{
--time_diff.tv_sec;
time_diff.tv_usec += 1000000;
}
if(time_diff.tv_sec < TIMEOUT)
{
printf("Test FAILED: the timer expired and thread terminated, "
"but the timeout is not correct: "
"start time %ld.%06ld, end time %ld.%06ld\n",
//.........这里部分代码省略.........
开发者ID:crystax,项目名称:android-vendor-openpts,代码行数:101,代码来源:3-1.c
示例7: vdir_wrlock
void
vdir_wrlock(struct vdir *vd)
{
CHECK_OBJ_NOTNULL(vd, VDIR_MAGIC);
AZ(pthread_rwlock_wrlock(&vd->mtx));
}
开发者ID:nigoroll,项目名称:varnish-cache,代码行数:6,代码来源:vdir.c
示例8: wrlock
int wrlock()
{
return pthread_rwlock_wrlock(&rwlock_);
}
开发者ID:Ribtoks,项目名称:xpiks,代码行数:4,代码来源:rwlock.hpp
示例9: main
int main(int argc, char *argv[]){
logging_init();
logmsg(LOG_INFO, "Server started and logging started.");
int xsize = DEFAULT_X_SIZE;
int zsize = DEFAULT_Z_SIZE;
char *filename = NULL;
char *out_name = NULL;
for(int i=0; i < argc; i++){
if (strcmp("-s", argv[i])== 0){
xsize = atoi(argv[i+1]);
zsize = atoi(argv[i+2]);
i += 2;
} else if (strcmp("-f", argv[i]) == 0){
filename = argv[i+1];
} else if (strcmp("-o", argv[i]) == 0){
out_name = argv[i+1];
}
}
Map *map;
if (filename == NULL){
map = Map_new_air(xsize,zsize);
Block b;
b.id = 1;
b.metadata = 0;
Map_set_below(map, b, 60);
b.id=20; map->chunks[0]->blocks[0] = b; //Debugging
if (out_name != NULL){
filename = out_name;
}
} else {
map = Map_read(filename);
}
Server *server = Server_create(map, 10);
sigint_server = server;
server->is_running = 1;
server->filename = filename;
signal(SIGINT, catch_sigint);
pthread_create(&(server->distributor_thread),
NULL, &connection_distributor_thread, server);
logmsg(LOG_INFO, "Distributor thread started.");
struct timespec sleeptime;
sleeptime.tv_sec = 0;
sleeptime.tv_nsec = 50000000; // 50 ms.
while (server->is_running){
pthread_rwlock_wrlock(&server->state_lock);
pthread_rwlock_wrlock(&server->players_lock);
Server_tick(server);
pthread_rwlock_unlock(&server->state_lock);
pthread_rwlock_unlock(&server->players_lock);
nanosleep(&sleeptime, NULL);
}
pthread_join(server->distributor_thread, NULL);
logmsg(LOG_INFO, "Server shutting down!");
return 0;
}
开发者ID:SpenceSellers,项目名称:microMC,代码行数:64,代码来源:main.c
示例10: executeThreads
/** thread function **/
void * executeThreads(void *rank)
{
srand(time(NULL)); // initialize random seed
while(totalOps > 0)
{
/** mutex for totalOps global variable**/
pthread_mutex_lock(&mutexTotalOps);
totalOps--;
pthread_mutex_unlock(&mutexTotalOps);
if (insertFunctionCount == 0 && memberFunctionCount == 0 && deleteFunctionCount == 0)
{
break;
}
int rndVal=rand()%3+1; // generate random value from 1 to 1000
/** adjust pre defined ranges by considering function count **/
if(memberFunctionCount == 0)
{
if (insertFunctionCount == 0)
{
rndVal=3;
}
else if(deleteFunctionCount == 0)
{
rndVal=2;
}
else
{
rndVal=rand()%2+2;
}
}
else if (insertFunctionCount == 0)
{
if (memberFunctionCount == 0)
{
rndVal=3;
}
else if(deleteFunctionCount == 0)
{
rndVal=1;
}
else
{
int array[]= {1,3};
rndVal=array[rand()%2];
}
}
else if(deleteFunctionCount == 0)
{
if (memberFunctionCount == 0)
{
rndVal=2;
}
else if(insertFunctionCount == 0)
{
rndVal=1;
}
else
{
rndVal=rand()%2+1;
}
}
/** execute relevant operation according to the pre defined limit ranges **/
if(rndVal == 1)
{
pthread_rwlock_rdlock(&rwlock);
//pthread_mutex_lock(&mutexList);
member(rand()%1500+1,(int)rank);
//pthread_mutex_unlock(&mutexList);
pthread_rwlock_unlock(&rwlock);
}
else if(rndVal == 2)
{
//pthread_mutex_lock(&mutexList);
pthread_rwlock_wrlock(&rwlock);
insert_node(rand()%1000+1001,(int)rank);
//pthread_mutex_unlock(&mutexList);
pthread_rwlock_unlock(&rwlock);
}
else if(rndVal == 3)
{
pthread_rwlock_wrlock(&rwlock);
//pthread_mutex_lock(&mutexList);
delete_node(rand()%1500+1,(int)rank);
//pthread_mutex_unlock(&mutexList);
pthread_rwlock_unlock(&rwlock);
}
}
return NULL;
}
开发者ID:Nipuna-Sankalpa,项目名称:concurrent_lab_02,代码行数:97,代码来源:main.c
示例11: lock
void lock ()
{
int status = pthread_rwlock_wrlock(&m_rwlock);
POMAGMA_ASSERT1(status == 0, "pthread_rwlock_wrlock failed");
}
开发者ID:imclab,项目名称:pomagma,代码行数:5,代码来源:threading.hpp
示例12: RG_core_wlock
// wlock the core
int RG_core_wlock( struct RG_core* rg ) {
return pthread_rwlock_wrlock( &rg->lock );
}
开发者ID:iychoi,项目名称:syndicate,代码行数:5,代码来源:syndicate-rg.cpp
示例13: dessert_logcfg
/** Configure dessert logging framework and sets up logging.
*
* @param opts OR'd flags - @see DESSERT_LOG_*
* @return DESSERT_OK
*
* %DESCRIPTION:
**/
dessert_result dessert_logcfg(uint16_t opts) {
char dessert_logprefix[32];
snprintf(dessert_logprefix, sizeof(dessert_logprefix), "dessert/%s", dessert_proto);
pthread_rwlock_wrlock(&dessert_cfglock);
/* configure logging */
if((opts & DESSERT_LOG_SYSLOG) && !(opts & DESSERT_LOG_NOSYSLOG)) {
if(!(_dessert_logflags & _DESSERT_LOGFLAG_SYSLOG)) {
/* initialize syslog channel */
openlog(dessert_logprefix, LOG_PID, LOG_DAEMON);
}
_dessert_logflags |= _DESSERT_LOGFLAG_SYSLOG;
}
else if(!(opts & DESSERT_LOG_SYSLOG) && (opts & DESSERT_LOG_NOSYSLOG)) {
if(_dessert_logflags & _DESSERT_LOGFLAG_SYSLOG) {
/* close syslog channel */
closelog();
}
_dessert_logflags &= ~_DESSERT_LOGFLAG_SYSLOG;
}
if((opts & DESSERT_LOG_STDERR) && !(opts & DESSERT_LOG_NOSTDERR)
&& !(_dessert_status & _DESSERT_STATUS_DAEMON)) {
_dessert_logflags |= _DESSERT_LOGFLAG_STDERR;
}
else if((!(opts & DESSERT_LOG_STDERR) && (opts & DESSERT_LOG_NOSTDERR))
|| (_dessert_status & _DESSERT_STATUS_DAEMON)) {
_dessert_logflags &= ~_DESSERT_LOGFLAG_STDERR;
}
#ifdef HAVE_LIBZ
// enable or disable compression
if((opts & DESSERT_LOG_GZ) && !(opts & DESSERT_LOG_NOGZ)) {
_dessert_logflags |= _DESSERT_LOGFLAG_GZ;
}
else if((!(opts & DESSERT_LOG_GZ) && (opts & DESSERT_LOG_NOGZ))) {
_dessert_logflags &= ~_DESSERT_LOGFLAG_GZ;
}
#endif
if((opts & DESSERT_LOG_FILE) && !(opts & DESSERT_LOG_NOFILE)
&& (_dessert_logfd != NULL
#ifdef HAVE_LIBZ
|| _dessert_logfdgz != NULL
#endif
)) {
_dessert_logflags |= _DESSERT_LOGFLAG_LOGFILE;
}
else if((!(opts & DESSERT_LOG_FILE) && (opts & DESSERT_LOG_NOFILE))
|| (_dessert_logfd == NULL
#ifdef HAVE_LIBZ
&& _dessert_logfdgz == NULL
#endif
)) {
_dessert_logflags &= ~_DESSERT_LOGFLAG_LOGFILE;
}
if((opts & DESSERT_LOG_RBUF) && !(opts & DESSERT_LOG_NORBUF)) {
_dessert_logflags |= _DESSERT_LOGFLAG_RBUF;
}
else if(!(opts & DESSERT_LOG_RBUF) && (opts & DESSERT_LOG_NORBUF)) {
_dessert_logflags &= ~_DESSERT_LOGFLAG_RBUF;
}
pthread_rwlock_unlock(&dessert_cfglock);
return DESSERT_OK;
}
开发者ID:des-testbed,项目名称:libdessert,代码行数:80,代码来源:dessert_log.c
示例14: _dessert_cli_logging_ringbuffer
/** command "logging ringbuffer" */
int _dessert_cli_logging_ringbuffer(struct cli_def* cli, char* command, char* argv[], int argc) {
int newlen = -1;
if(argc != 1 || (newlen = (int) strtol(argv[0], NULL, 10)) < 0) {
cli_print(cli, "usage %s [buffer length]\n", command);
return CLI_ERROR;
}
if(newlen == _dessert_logrbuf_len) {
return CLI_OK;
}
if(newlen == 0) {
cli_print(cli,
"will not set buffer length to 0 - use no logging ringbuffer instead\n");
return CLI_ERROR;
}
pthread_rwlock_wrlock(&_dessert_logrbuf_len_lock);
/* make logging buffer larger - easy if not ENOMEM*/
if(newlen > _dessert_logrbuf_len) {
_dessert_logrbuf = realloc(_dessert_logrbuf, newlen
* DESSERT_LOGLINE_MAX * sizeof(char));
if(_dessert_logrbuf == NULL) {
_dessert_logrbuf_len = 0;
_dessert_logrbuf_cur = 0;
}
else {
_dessert_logrbuf_len = newlen;
}
dessert_logcfg(DESSERT_LOG_RBUF);
/* make logging buffer smaller - pain in the ass */
}
else if(newlen < _dessert_logrbuf_len) {
/* move current log buffer if needed */
if(_dessert_logrbuf_cur > newlen) {
memmove(_dessert_logrbuf, _dessert_logrbuf + (DESSERT_LOGLINE_MAX
*(_dessert_logrbuf_cur - newlen)), newlen
* DESSERT_LOGLINE_MAX * sizeof(char));
_dessert_logrbuf_cur -= newlen;
}
_dessert_logrbuf = realloc(_dessert_logrbuf, newlen
* DESSERT_LOGLINE_MAX * sizeof(char));
if(_dessert_logrbuf == NULL) {
_dessert_logrbuf_len = 0;
_dessert_logrbuf_cur = 0;
}
else {
_dessert_logrbuf_len = newlen;
}
}
else {
dessert_err("this never happens");
}
if(_dessert_logrbuf_used > _dessert_logrbuf_len - 1) {
_dessert_logrbuf_used = _dessert_logrbuf_len - 1;
}
pthread_rwlock_unlock(&_dessert_logrbuf_len_lock);
return CLI_OK;
}
开发者ID:des-testbed,项目名称:libdessert,代码行数:68,代码来源:dessert_log.c
示例15: sharddir_wrlock
void
sharddir_wrlock(struct sharddir *shardd)
{
CHECK_OBJ_NOTNULL(shardd, SHARDDIR_MAGIC);
AZ(pthread_rwlock_wrlock(&shardd->mtx));
}
开发者ID:xcir,项目名称:varnish-cache,代码行数:6,代码来源:shard_dir.c
示例16: RWLock_WriteLock
void RWLock_WriteLock(RWLock *rwlock) {
pthread_rwlock_wrlock(&rwlock->rw_);
}
开发者ID:pratikgaikar,项目名称:Tablefs,代码行数:3,代码来源:inodemutex.c
示例17: lock_w
int lock_w()
{
return pthread_rwlock_wrlock(&locker);
}
开发者ID:dokey4444,项目名称:busybox,代码行数:4,代码来源:elib_lock.hpp
示例18: acquireWrite
void acquireWrite() const {
PROFILE_MUTEX_START_LOCK();
pthread_rwlock_wrlock(&rw_lock_);
PROFILE_MUTEX_LOCKED();
}
开发者ID:MisterTea,项目名称:MAMEHub,代码行数:5,代码来源:Mutex.cpp
示例19: main
int main()
{
int cnt;
handler_called = 0;
if(pthread_rwlock_init(&rwlock, NULL) != 0)
{
printf("main: Error at pthread_rwlock_init()\n");
return PTS_UNRESOLVED;
}
printf("main: attempt write lock\n");
if(pthread_rwlock_wrlock(&rwlock) != 0)
{
printf("main: Error at pthread_rwlock_wrlock()\n");
return PTS_UNRESOLVED;
} else
printf("main: acquired write lock\n");
thread_state = NOT_CREATED_THREAD;
if(pthread_create(&sig_thread, NULL, th_fn, NULL) != 0)
{
printf("main: Error at pthread_create()\n");
return PTS_UNRESOLVED;
}
/* wait at most 3 seconds for sig_thread to block*/
cnt = 0;
do{
sleep(1);
}while(thread_state != EXITING_THREAD && cnt++ < 3);
if(thread_state == EXITING_THREAD)
{
printf("Test FAILED: thread did not block on read lock when a writer holds the lock\n");
exit(PTS_FAIL);
}
else if(thread_state != ENTERED_THREAD)
{
printf("Unexpected thread state: %d\n", thread_state);
exit(PTS_UNRESOLVED);
}
/* sig_thread is blocking */
printf("main: fire SIGUSR1 to sig_thread\n");
if(pthread_kill(sig_thread, SIGUSR1) != 0)
{
printf("main: failed to send SIGUSER to sig_thread\n");
exit(PTS_UNRESOLVED);
}
/* wait at most 3 seconds for the signal to be handled */
cnt = 0;
do{
sleep(1);
}while(handler_called == 0 && cnt++ < 3);
if(handler_called != 1)
{
printf("SIGUSR1 was not caught by sig_thread\n");
exit(PTS_UNRESOLVED);
}
/* sig_thread resume to block? */
cnt = 0;
do{
sleep(1);
}while(thread_state != EXITING_THREAD && cnt++ < 3);
if(thread_state == EXITING_THREAD)
{
printf("Test FAILED: upon return from signal handler, sig_thread does not resume to block\n");
exit(PTS_FAIL);
}else if(thread_state != ENTERED_THREAD)
{
printf("Unexpected thread state: %d\n", thread_state);
exit(PTS_UNRESOLVED);
}
printf("sig_thread: correctly still blocking after signal handler returns\n");
printf("main: unlock write lock\n");
if(pthread_rwlock_unlock(&rwlock) != 0)
{
printf("main: Failed to release write lock\n");
exit(PTS_UNRESOLVED);
}
/* sig_thread got the read lock? */
cnt = 0;
do{
sleep(1);
}while(thread_state != EXITING_THREAD && cnt++ < 3);
if(thread_state == ENTERED_THREAD)
{
printf("Test FAILED: sig_thread blocked on read lock when writer release the lock\n");
exit(PTS_FAIL);
}else if(thread_state != EXITING_THREAD)
{
printf("Unexpected thread state: %d\n", thread_state);
//.........这里部分代码省略.........
开发者ID:8l,项目名称:rose,代码行数:101,代码来源:4-1.c
示例20: main
//.........这里部分代码省略.........
TIMEOUT, (long)time_diff.tv_sec,
(long)time_diff.tv_usec);
exit(PTS_FAIL);
}
else
printf("thread1 correctly expired at timeout.\n");
}
else if(thread_state == ENTERED_THREAD)
{
printf("Test FAILED: wait is not terminated even "
"when the timer expired\n");
exit(PTS_FAIL);
}
else
{
printf("Unexpected state for thread1 %d\n", thread_state);
exit(PTS_UNRESOLVED);
}
printf("main: unlock read lock\n");
if(pthread_rwlock_unlock(&rwlock) != 0)
{
printf("Error when release read lock\n");
exit(PTS_UNRESOLVED);
}
if(pthread_join(thread1, NULL) != 0)
{
printf("Error when joining thread1\n");
return PTS_UNRESOLVED;
}
printf("main: attempt write lock\n");
if(pthread_rwlock_wrlock(&rwlock) != 0)
{
printf("Error at pthread_rwlock_wrlock()\n");
return PTS_UNRESOLVED;
}
printf("main: acquired write lock\n");
thread_state = NOT_CREATED_THREAD;
cnt = 0;
printf("main: create thread2\n");
if(pthread_create(&thread2, NULL, fn_wr, NULL) != 0)
{
printf("Error when creating thread2\n");
return PTS_UNRESOLVED;
}
/* we expect thread2 to expire blocking after timeout */
do{
sleep(1);
}while (thread_state !=EXITING_THREAD && cnt++ < 2*TIMEOUT);
if(thread_state == EXITING_THREAD)
{
/* the child thread does not block, check the time interval */
struct timeval time_diff;
time_diff.tv_sec = currsec2.tv_sec - currsec1.tv_sec;
time_diff.tv_usec = currsec2.tv_usec - currsec1.tv_usec;
if (time_diff.tv_usec < 0)
{
--time_diff.tv_sec;
time_diff.tv_usec += 1000000;
}
if(time_diff.tv_sec < TIMEOUT)
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:67,代码来源:3-1.c
注:本文中的pthread_rwlock_wrlock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论