这篇教程C++ write_lock函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中write_lock函数的典型用法代码示例。如果您正苦于以下问题:C++ write_lock函数的具体用法?C++ write_lock怎么用?C++ write_lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了write_lock函数的23个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: expand_fd_arrayint expand_fd_array(struct files_struct *files, int nr){ struct file **new_fds; int error, nfds; error = -EMFILE; if (files->max_fds >= NR_OPEN || nr >= NR_OPEN) goto out; nfds = files->max_fds; write_unlock(&files->file_lock); /* * Expand to the max in easy steps, and keep expanding it until * we have enough for the requested fd array size. */ do {#if NR_OPEN_DEFAULT < 256 if (nfds < 256) nfds = 256; else#endif if (nfds < (PAGE_SIZE / sizeof(struct file *))) nfds = PAGE_SIZE / sizeof(struct file *); else { nfds = nfds * 2; if (nfds > NR_OPEN) nfds = NR_OPEN; } } while (nfds <= nr); error = -ENOMEM; new_fds = alloc_fd_array(nfds); write_lock(&files->file_lock); if (!new_fds) goto out; /* Copy the existing array and install the new pointer */ if (nfds > files->max_fds) { struct file **old_fds; int i; old_fds = xchg(&files->fd, new_fds); i = xchg(&files->max_fds, nfds); /* Don't copy/clear the array if we are creating a new fd array for fork() */ if (i) { memcpy(new_fds, old_fds, i * sizeof(struct file *)); /* clear the remainder of the array */ memset(&new_fds[i], 0, (nfds-i) * sizeof(struct file *)); write_unlock(&files->file_lock); free_fd_array(old_fds, i); write_lock(&files->file_lock); } } else { /* Somebody expanded the array while we slept ... */ write_unlock(&files->file_lock); free_fd_array(new_fds, nfds); write_lock(&files->file_lock); } error = 0;out: return error;}
开发者ID:nhanh0,项目名称:hah,代码行数:70,
示例2: write_lockvoid SortedVectorMapRow<V>::ApplyInc(int32_t column_id, const void *update) { std::unique_lock<SharedMutex> write_lock(rw_mutex_); ApplyIncUnsafe(column_id, update);}
开发者ID:Nikraaaazy,项目名称:bosen,代码行数:4,
示例3: ip6_frag_queue//.........这里部分代码省略......... } } if (end == offset) goto err; /* Point into the IP datagram 'data' part. */ if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data)) goto err; if (pskb_trim_rcsum(skb, end - offset)) goto err; /* Find out which fragments are in front and at the back of us * in the chain of fragments so far. We must know where to put * this fragment, right? */ prev = fq->q.fragments_tail; if (!prev || FRAG6_CB(prev)->offset < offset) { next = NULL; goto found; } prev = NULL; for(next = fq->q.fragments; next != NULL; next = next->next) { if (FRAG6_CB(next)->offset >= offset) break; /* bingo! */ prev = next; }found: /* RFC5722, Section 4, amended by Errata ID : 3089 * When reassembling an IPv6 datagram, if * one or more its constituent fragments is determined to be an * overlapping fragment, the entire datagram (and any constituent * fragments) MUST be silently discarded. */ /* Check for overlap with preceding fragment. */ if (prev && (FRAG6_CB(prev)->offset + prev->len) > offset) goto discard_fq; /* Look for overlap with succeeding segment. */ if (next && FRAG6_CB(next)->offset < end) goto discard_fq; FRAG6_CB(skb)->offset = offset; /* Insert this fragment in the chain of fragments. */ skb->next = next; if (!next) fq->q.fragments_tail = skb; if (prev) prev->next = skb; else fq->q.fragments = skb; dev = skb->dev; if (dev) { fq->iif = dev->ifindex; skb->dev = NULL; } fq->q.stamp = skb->tstamp; fq->q.meat += skb->len; atomic_add(skb->truesize, &fq->q.net->mem); /* The first fragment. * nhoffset is obtained from the first fragment, of course. */ if (offset == 0) { fq->nhoffset = nhoff; fq->q.last_in |= INET_FRAG_FIRST_IN; } if (fq->q.last_in == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) && fq->q.meat == fq->q.len) { int res; unsigned long orefdst = skb->_skb_refdst; skb->_skb_refdst = 0UL; res = ip6_frag_reasm(fq, prev, dev); skb->_skb_refdst = orefdst; return res; } skb_dst_drop(skb); write_lock(&ip6_frags.lock); list_move_tail(&fq->q.lru_list, &fq->q.net->lru_list); write_unlock(&ip6_frags.lock); return -1;discard_fq: fq_kill(fq);err: IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMFAILS); kfree_skb(skb); return -1;}
开发者ID:andy-padavan,项目名称:rt-n56u,代码行数:101,
示例4: ip_frag_queue//.........这里部分代码省略......... * any overlaps are eliminated. */ if (prev) { int i = (FRAG_CB(prev)->offset + prev->len) - offset; if (i > 0) { offset += i; err = -EINVAL; if (end <= offset) goto err; err = -ENOMEM; if (!pskb_pull(skb, i)) goto err; if (skb->ip_summed != CHECKSUM_UNNECESSARY) skb->ip_summed = CHECKSUM_NONE; } } err = -ENOMEM; while (next && FRAG_CB(next)->offset < end) { int i = end - FRAG_CB(next)->offset; /* overlap is 'i' bytes */ if (i < next->len) { /* Eat head of the next overlapped fragment * and leave the loop. The next ones cannot overlap. */ if (!pskb_pull(next, i)) goto err; FRAG_CB(next)->offset += i; qp->q.meat -= i; if (next->ip_summed != CHECKSUM_UNNECESSARY) next->ip_summed = CHECKSUM_NONE; break; } else { struct sk_buff *free_it = next; /* Old fragment is completely overridden with * new one drop it. */ next = next->next; if (prev) prev->next = next; else qp->q.fragments = next; qp->q.meat -= free_it->len; frag_kfree_skb(qp->q.net, free_it); } } FRAG_CB(skb)->offset = offset; /* Insert this fragment in the chain of fragments. */ skb->next = next; if (!next) qp->q.fragments_tail = skb; if (prev) prev->next = skb; else qp->q.fragments = skb; dev = skb->dev; if (dev) { qp->iif = dev->ifindex; skb->dev = NULL; } qp->q.stamp = skb->tstamp; qp->q.meat += skb->len; qp->ecn |= ecn; atomic_add(skb->truesize, &qp->q.net->mem); if (offset == 0) qp->q.last_in |= INET_FRAG_FIRST_IN; if (ip_hdr(skb)->frag_off & htons(IP_DF) && skb->len + ihl > qp->q.max_size) qp->q.max_size = skb->len + ihl; if (qp->q.last_in == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) && qp->q.meat == qp->q.len) { unsigned long orefdst = skb->_skb_refdst; skb->_skb_refdst = 0UL; err = ip_frag_reasm(qp, prev, dev); skb->_skb_refdst = orefdst; return err; } skb_dst_drop(skb); write_lock(&ip4_frags.lock); list_move_tail(&qp->q.lru_list, &qp->q.net->lru_list); write_unlock(&ip4_frags.lock); return -EINPROGRESS;err: kfree_skb(skb); return err;}
开发者ID:jing-git,项目名称:rt-n56u-1,代码行数:101,
示例5: my_writestatic ssize_t my_write(struct file *fp, const char __user *buf, size_t len, loff_t *off) { write_lock(&rwlock); data = data==1 ? 0 : 1; //NORACE! write_unlock(&rwlock); return 0;}
开发者ID:Ingramz,项目名称:analyzer,代码行数:6,
示例6: fld_index_create/** * insert range in fld store. * * /param range range to be inserted * /param th transaction for this operation as it could compound * transaction. * * /retval 0 success * /retval -ve error * * The whole fld index insertion is protected by seq->lss_mutex (see * seq_server_alloc_super), i.e. only one thread will access fldb each * time, so we do not need worry the fld file and cache will being * changed between declare and create. * Because the fld entry can only be increamental, so we will only check * whether it can be merged from the left. * * Caller must hold fld->lsf_lock **/int fld_index_create(const struct lu_env *env, struct lu_server_fld *fld, const struct lu_seq_range *new_range, struct thandle *th){ struct lu_seq_range *range; struct lu_seq_range *tmp; struct fld_thread_info *info; int rc = 0; int deleted = 0; struct fld_cache_entry *flde; ENTRY; info = lu_context_key_get(&env->le_ctx, &fld_thread_key); LASSERT(mutex_is_locked(&fld->lsf_lock)); range = &info->fti_lrange; memset(range, 0, sizeof(*range)); tmp = &info->fti_irange; rc = fld_index_lookup(env, fld, new_range->lsr_start, range); if (rc != -ENOENT) { rc = rc == 0 ? -EEXIST : rc; GOTO(out, rc); } if (new_range->lsr_start == range->lsr_end && range->lsr_end != 0 && lu_seq_range_compare_loc(new_range, range) == 0) { range_cpu_to_be(tmp, range); rc = dt_delete(env, fld->lsf_obj, (struct dt_key *)&tmp->lsr_start, th); if (rc != 0) GOTO(out, rc); *tmp = *new_range; tmp->lsr_start = range->lsr_start; deleted = 1; } else { *tmp = *new_range; } range_cpu_to_be(tmp, tmp); rc = dt_insert(env, fld->lsf_obj, (struct dt_rec *)tmp, (struct dt_key *)&tmp->lsr_start, th, 1); if (rc != 0) { CERROR("%s: insert range "DRANGE" failed: rc = %d/n", fld->lsf_name, PRANGE(new_range), rc); GOTO(out, rc); } flde = fld_cache_entry_create(new_range); if (IS_ERR(flde)) GOTO(out, rc = PTR_ERR(flde)); write_lock(&fld->lsf_cache->fci_lock); if (deleted) fld_cache_delete_nolock(fld->lsf_cache, new_range); rc = fld_cache_insert_nolock(fld->lsf_cache, flde); write_unlock(&fld->lsf_cache->fci_lock); if (rc) OBD_FREE_PTR(flde);out: RETURN(rc);}
开发者ID:Keeper-of-the-Keys,项目名称:Lustre,代码行数:80,
示例7: powernet_snmp_ups_check_stateint powernet_snmp_ups_check_state(UPSINFO *ups){ struct snmp_ups_internal_data *Sid = (struct snmp_ups_internal_data *)ups->driver_internal_data; fd_set fds; int numfds, rc, block; struct timeval tmo, exit, now; int sleep_time; /* Check for commlost under lock since UPS status might be changed */ write_lock(ups); rc = powernet_check_comm_lost(ups); write_unlock(ups); if (rc == 0) return 0; sleep_time = ups->wait_time; /* If we're not doing SNMP traps, just sleep and exit */ if (!Sid->trap_session) { sleep(sleep_time); return 1; } /* Figure out when we need to exit by */ gettimeofday(&exit, NULL); exit.tv_sec += sleep_time; while(1) { /* Figure out how long until we have to exit */ gettimeofday(&now, NULL); if (now.tv_sec > exit.tv_sec || (now.tv_sec == exit.tv_sec && now.tv_usec >= exit.tv_usec)) { /* Done already? How time flies... */ return 0; } tmo.tv_sec = exit.tv_sec - now.tv_sec; tmo.tv_usec = exit.tv_usec - now.tv_usec; if (tmo.tv_usec < 0) { tmo.tv_sec--; /* Normalize */ tmo.tv_usec += 1000000; } /* Get select parameters from SNMP library */ FD_ZERO(&fds); block = 0; numfds = 0; snmp_select_info(&numfds, &fds, &tmo, &block); /* Wait for something to happen */ rc = select(numfds, &fds, NULL, NULL, &tmo); switch (rc) { case 0: /* Timeout */ /* Tell SNMP library about the timeout */ snmp_timeout(); break; case -1: /* Error */ if (errno == EINTR || errno == EAGAIN) continue; /* assume SIGCHLD */ Dmsg1(200, "select error: ERR=%s/n", strerror(errno)); return 0; default: /* Data available */ /* Reset trap flag and run callback processing */ Sid->trap_received = false; snmp_read(&fds); /* If callback processing set the flag, we got a trap */ if (Sid->trap_received) return 1; break; } }}
开发者ID:AllardJ,项目名称:Tomato,代码行数:81,
示例8: fq_unlinkstatic __inline__ void fq_unlink(struct nf_ct_frag6_queue *fq){ write_lock(&nf_ct_frag6_lock); __fq_unlink(fq); write_unlock(&nf_ct_frag6_lock);}
开发者ID:BackupTheBerlios,项目名称:tew632-brp-svn,代码行数:6,
示例9: read_unlock void RWMutex::upgrade_read_to_write_lock() { read_unlock(); write_lock(); }
开发者ID:davenso,项目名称:embree,代码行数:5,
示例10: neigh_expire_timer_checkstatic void neigh_expire_timer_check(unsigned long dummy){ int i; unsigned long flags; save_flags(flags); cli(); write_lock(&clip_tbl.lock); for (i = 0; i <= NEIGH_HASHMASK; i++) { struct neighbour **np; for (np = &clip_tbl.hash_buckets[i]; *np;) { struct neighbour *n = *np; struct atmarp_entry *entry = NEIGH2ENTRY(n); struct clip_vcc *clip_vcc; int need_resolving = 1; if (time_before(jiffies + CLIP_ENTRY_EXPIRE / 4, entry->expires)) need_resolving = 0; for (clip_vcc = entry->vccs; clip_vcc; clip_vcc = clip_vcc->next) { if (clip_vcc->idle_timeout && time_after(jiffies, clip_vcc->last_use + clip_vcc->idle_timeout)) { DPRINTK("releasing vcc %p->%p of entry %p/n", clip_vcc, clip_vcc->vcc, entry); atm_async_release_vcc(clip_vcc->vcc, -ETIMEDOUT); } else if (need_resolving && !clip_vcc->resolve_timeout) clip_start_resolving(clip_vcc); } if (!need_resolving || time_before(jiffies, entry->expires)) { np = &n->next; continue; } if (atomic_read(&n->refcnt) > 1) { struct sk_buff *skb; DPRINTK("destruction postponed with ref %d/n", atomic_read(&n->refcnt)); while ((skb = skb_dequeue(&n->arp_queue))) dev_kfree_skb(skb); np = &n->next; continue; } *np = n->next; DPRINTK("expired neigh %p/n",n); n->dead = 1; neigh_release(n); } } mod_timer(&neigh_expire_timer, jiffies + CLIP_CHECK_INTERVAL * HZ); write_unlock(&clip_tbl.lock); restore_flags(flags);}
开发者ID:DentonGentry,项目名称:gfiber-gfrg100,代码行数:64,
示例11: rxrpc_bind/* * bind a local address to an RxRPC socket */static int rxrpc_bind(struct socket *sock, struct sockaddr *saddr, int len){ struct sockaddr_rxrpc *srx = (struct sockaddr_rxrpc *)saddr; struct rxrpc_local *local; struct rxrpc_sock *rx = rxrpc_sk(sock->sk); u16 service_id; int ret; _enter("%p,%p,%d", rx, saddr, len); ret = rxrpc_validate_address(rx, srx, len); if (ret < 0) goto error; service_id = srx->srx_service; lock_sock(&rx->sk); switch (rx->sk.sk_state) { case RXRPC_UNBOUND: rx->srx = *srx; local = rxrpc_lookup_local(sock_net(&rx->sk), &rx->srx); if (IS_ERR(local)) { ret = PTR_ERR(local); goto error_unlock; } if (service_id) { write_lock(&local->services_lock); if (rcu_access_pointer(local->service)) goto service_in_use; rx->local = local; rcu_assign_pointer(local->service, rx); write_unlock(&local->services_lock); rx->sk.sk_state = RXRPC_SERVER_BOUND; } else { rx->local = local; rx->sk.sk_state = RXRPC_CLIENT_BOUND; } break; case RXRPC_SERVER_BOUND: ret = -EINVAL; if (service_id == 0) goto error_unlock; ret = -EADDRINUSE; if (service_id == rx->srx.srx_service) goto error_unlock; ret = -EINVAL; srx->srx_service = rx->srx.srx_service; if (memcmp(srx, &rx->srx, sizeof(*srx)) != 0) goto error_unlock; rx->second_service = service_id; rx->sk.sk_state = RXRPC_SERVER_BOUND2; break; default: ret = -EINVAL; goto error_unlock; } release_sock(&rx->sk); _leave(" = 0"); return 0;service_in_use: write_unlock(&local->services_lock); rxrpc_put_local(local); ret = -EADDRINUSE;error_unlock: release_sock(&rx->sk);error: _leave(" = %d", ret); return ret;}
开发者ID:avagin,项目名称:linux,代码行数:78,
示例12: get_unused_fd/* * Find an empty file descriptor entry, and mark it busy. */int get_unused_fd(void){ struct files_struct * files = current->files; int fd, error; error = -EMFILE; write_lock(&files->file_lock);repeat: fd = find_next_zero_bit(files->open_fds, files->max_fdset, files->next_fd); /* * N.B. For clone tasks sharing a files structure, this test * will limit the total number of files that can be opened. */ if (fd >= current->rlim[RLIMIT_NOFILE].rlim_cur) goto out; /* Do we need to expand the fdset array? */ if (fd >= files->max_fdset) { error = expand_fdset(files, fd); if (!error) { error = -EMFILE; goto repeat; } goto out; } /* * Check whether we need to expand the fd array. */ if (fd >= files->max_fds) { error = expand_fd_array(files, fd); if (!error) { error = -EMFILE; goto repeat; } goto out; } FD_SET(fd, files->open_fds); FD_CLR(fd, files->close_on_exec); files->next_fd = fd + 1;#if 1 /* Sanity check */ if (files->fd[fd] != NULL) { printk(KERN_WARNING "get_unused_fd: slot %d not NULL!/n", fd); files->fd[fd] = NULL; }#endif error = fd;out: write_unlock(&files->file_lock); return error;}
开发者ID:rroart,项目名称:freevms,代码行数:66,
示例13: osd_attr_set//.........这里部分代码省略......... /* do both accounting updates outside oo_attr_lock below */ if ((valid & LA_UID) && (la->la_uid != obj->oo_attr.la_uid)) { /* Update user accounting. Failure isn't fatal, but we still * log an error message */ rc = -zap_increment_int(osd->od_os, osd->od_iusr_oid, la->la_uid, 1, oh->ot_tx); if (rc) CERROR("%s: failed to update accounting ZAP for user " "%d (%d)/n", osd->od_svname, la->la_uid, rc); rc = -zap_increment_int(osd->od_os, osd->od_iusr_oid, obj->oo_attr.la_uid, -1, oh->ot_tx); if (rc) CERROR("%s: failed to update accounting ZAP for user " "%d (%d)/n", osd->od_svname, obj->oo_attr.la_uid, rc); } if ((valid & LA_GID) && (la->la_gid != obj->oo_attr.la_gid)) { /* Update group accounting. Failure isn't fatal, but we still * log an error message */ rc = -zap_increment_int(osd->od_os, osd->od_igrp_oid, la->la_gid, 1, oh->ot_tx); if (rc) CERROR("%s: failed to update accounting ZAP for user " "%d (%d)/n", osd->od_svname, la->la_gid, rc); rc = -zap_increment_int(osd->od_os, osd->od_igrp_oid, obj->oo_attr.la_gid, -1, oh->ot_tx); if (rc) CERROR("%s: failed to update accounting ZAP for user " "%d (%d)/n", osd->od_svname, obj->oo_attr.la_gid, rc); } write_lock(&obj->oo_attr_lock); cnt = 0; if (valid & LA_ATIME) { osa->atime[0] = obj->oo_attr.la_atime = la->la_atime; SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(osd), NULL, osa->atime, 16); } if (valid & LA_MTIME) { osa->mtime[0] = obj->oo_attr.la_mtime = la->la_mtime; SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(osd), NULL, osa->mtime, 16); } if (valid & LA_CTIME) { osa->ctime[0] = obj->oo_attr.la_ctime = la->la_ctime; SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(osd), NULL, osa->ctime, 16); } if (valid & LA_MODE) { /* mode is stored along with type, so read it first */ obj->oo_attr.la_mode = (obj->oo_attr.la_mode & S_IFMT) | (la->la_mode & ~S_IFMT); osa->mode = obj->oo_attr.la_mode; SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MODE(osd), NULL, &osa->mode, 8); } if (valid & LA_SIZE) { osa->size = obj->oo_attr.la_size = la->la_size; SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_SIZE(osd), NULL, &osa->size, 8); } if (valid & LA_NLINK) { osa->nlink = obj->oo_attr.la_nlink = la->la_nlink; SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_LINKS(osd), NULL,
开发者ID:sdsc,项目名称:lustre-release,代码行数:67,
示例14: miscd_dodaemonstatic int miscd_dodaemon(char *argv1, char *daemon){ struct sigaction act; char *commandline; char commbuf[10]; char ch; if (!check_file_writable(PASSFILE)) { fprintf(stderr, "Error! File %s is not writable./n", PASSFILE); exit(-1); } if (!check_file_writable(BOARDS)) { fprintf(stderr, "Error! File %s is not writable./n", BOARDS); exit(-1); } truncate(BOARDS, MAXBOARD * sizeof(struct boardheader)); if (load_ucache() != 0) { printf("ft,load ucache error!"); exit(-1); } /* init tmpfs */ sprintf(genbuf1,"%s/home",TMPFSROOT); mkdir(genbuf1,0700); sprintf(genbuf1,"%s/boards",TMPFSROOT); mkdir(genbuf1,0700); for (ch='A';ch<='Z';ch++) { sprintf(genbuf1,"%s/home/%c",TMPFSROOT,ch); mkdir(genbuf1,0700); } resolve_boards(); resolve_utmp(); resolve_guest_table(); if (argv1 != NULL) { switch (fork()) { case -1: printf("faint, i can't fork./n"); exit(0); break; case 0: break; default: exit(0); break; } commandline = argv1; } else { commandline = commbuf; } setsid();#if defined(FREEBSD) || defined(MACOSX) setpgid(0, 0);#else // by zixia setpgrp(0, 0); setpgrp();#endif#ifdef AIX act.sa_handler = NULL; act.sa_flags = SA_RESTART | SA_NOCLDWAIT; sigaction(SIGCHLD, &act, NULL);#else act.sa_handler = reaper; act.sa_flags = SA_RESTART; sigaction(SIGCHLD, &act, NULL);#endif if (((daemon == NULL) || (!strcmp(daemon, "timed"))) && ((argv1 == NULL) || fork())) { strcpy(commandline, "timed"); timed(); exit(0); } if (((daemon == NULL) || (!strcmp(daemon, "killd"))) && ((argv1 == NULL) || fork())) { strcpy(commandline, "killd"); char line[20]; const char *path = "var/killd.pid"; int pidfd = open(path, O_RDWR | O_CREAT, 0660); if (write_lock(pidfd, 0, SEEK_SET, 0) < 0) { bbslog("3error", "killd had already been started!"); exit(-1); } snprintf(line, sizeof(line), "%ld/n", (long)getpid()); ftruncate(pidfd, 0); write(pidfd, line, strlen(line)); while (1) { time_t ft; ft = getnextday4am(); do { sleep(ft - time(0)); } while (ft > time(0)); if (argv1 == NULL) { dokilluser(); //doupdategiveupuser();//.........这里部分代码省略.........
开发者ID:wyat,项目名称:kbs,代码行数:101,
示例15: nf_ct_frag6_queue//.........这里部分代码省略......... * in the chain of fragments so far. We must know where to put * this fragment, right? */ prev = NULL; for (next = fq->fragments; next != NULL; next = next->next) { if (NFCT_FRAG6_CB(next)->offset >= offset) break; /* bingo! */ prev = next; } /* We found where to put this one. Check for overlap with * preceding fragment, and, if needed, align things so that * any overlaps are eliminated. */ if (prev) { int i = (NFCT_FRAG6_CB(prev)->offset + prev->len) - offset; if (i > 0) { offset += i; if (end <= offset) { DEBUGP("overlap/n"); goto err; } if (!pskb_pull(skb, i)) { DEBUGP("Can't pull/n"); goto err; } if (skb->ip_summed != CHECKSUM_UNNECESSARY) skb->ip_summed = CHECKSUM_NONE; } } /* Look for overlap with succeeding segments. * If we can merge fragments, do it. */ while (next && NFCT_FRAG6_CB(next)->offset < end) { /* overlap is 'i' bytes */ int i = end - NFCT_FRAG6_CB(next)->offset; if (i < next->len) { /* Eat head of the next overlapped fragment * and leave the loop. The next ones cannot overlap. */ DEBUGP("Eat head of the overlapped parts.: %d", i); if (!pskb_pull(next, i)) goto err; /* next fragment */ NFCT_FRAG6_CB(next)->offset += i; fq->meat -= i; if (next->ip_summed != CHECKSUM_UNNECESSARY) next->ip_summed = CHECKSUM_NONE; break; } else { struct sk_buff *free_it = next; /* Old fragmnet is completely overridden with * new one drop it. */ next = next->next; if (prev) prev->next = next; else fq->fragments = next; fq->meat -= free_it->len; frag_kfree_skb(free_it, NULL); } } NFCT_FRAG6_CB(skb)->offset = offset; /* Insert this fragment in the chain of fragments. */ skb->next = next; if (prev) prev->next = skb; else fq->fragments = skb; skb->dev = NULL; skb_get_timestamp(skb, &fq->stamp); fq->meat += skb->len; atomic_add(skb->truesize, &nf_ct_frag6_mem); /* The first fragment. * nhoffset is obtained from the first fragment, of course. */ if (offset == 0) { fq->nhoffset = nhoff; fq->last_in |= FIRST_IN; } write_lock(&nf_ct_frag6_lock); list_move_tail(&fq->lru_list, &nf_ct_frag6_lru_list); write_unlock(&nf_ct_frag6_lock); return 0;err: return -1;}
开发者ID:BackupTheBerlios,项目名称:tew632-brp-svn,代码行数:101,
示例16: TRC_STATUSvoid JSONEnumService::update_enum(){ // Check whether the file exists. struct stat s; if ((stat(_configuration.c_str(), &s) != 0) && (errno == ENOENT)) { TRC_STATUS("No ENUM configuration (file %s does not exist)", _configuration.c_str()); CL_SPROUT_ENUM_FILE_MISSING.log(_configuration.c_str()); return; } TRC_STATUS("Loading ENUM configuration from %s", _configuration.c_str()); // Read from the file std::ifstream fs(_configuration.c_str()); std::string enum_str((std::istreambuf_iterator<char>(fs)), std::istreambuf_iterator<char>()); if (enum_str == "") { // LCOV_EXCL_START TRC_ERROR("Failed to read ENUM configuration data from %s", _configuration.c_str()); CL_SPROUT_ENUM_FILE_EMPTY.log(_configuration.c_str()); return; // LCOV_EXCL_STOP } // Now parse the document rapidjson::Document doc; doc.Parse<0>(enum_str.c_str()); if (doc.HasParseError()) { TRC_ERROR("Failed to read ENUM configuration data: %s/nError: %s", enum_str.c_str(), rapidjson::GetParseError_En(doc.GetParseError())); CL_SPROUT_ENUM_FILE_INVALID.log(_configuration.c_str()); return; } try { std::vector<NumberPrefix> new_number_prefixes; JSON_ASSERT_CONTAINS(doc, "number_blocks"); JSON_ASSERT_ARRAY(doc["number_blocks"]); const rapidjson::Value& nb_arr = doc["number_blocks"]; for (rapidjson::Value::ConstValueIterator nb_it = nb_arr.Begin(); nb_it != nb_arr.End(); ++nb_it) { try { std::string prefix; JSON_GET_STRING_MEMBER(*nb_it, "prefix", prefix); std::string regex; JSON_GET_STRING_MEMBER(*nb_it, "regex", regex); // Entry is well-formed, so add it. TRC_DEBUG("Found valid number prefix block %s", prefix.c_str()); NumberPrefix pfix; pfix.prefix = prefix; if (parse_regex_replace(regex, pfix.match, pfix.replace)) { new_number_prefixes.push_back(pfix); TRC_STATUS(" Adding number prefix %s, regex=%s", pfix.prefix.c_str(), regex.c_str()); } else { TRC_WARNING("Badly formed regular expression in ENUM number block %s", regex.c_str()); } } catch (JsonFormatError err) { // Badly formed number block. TRC_WARNING("Badly formed ENUM number block (hit error at %s:%d)", err._file, err._line); CL_SPROUT_ENUM_FILE_INVALID.log(_configuration.c_str()); } } // Take a write lock on the mutex in RAII style boost::lock_guard<boost::shared_mutex> write_lock(_number_prefixes_rw_lock); _number_prefixes = new_number_prefixes; } catch (JsonFormatError err) { TRC_ERROR("Badly formed ENUM configuration data - missing number_blocks object"); CL_SPROUT_ENUM_FILE_INVALID.log(_configuration.c_str()); }}
开发者ID:holm-xie,项目名称:sprout,代码行数:98,
示例17: hp_sdc_putunsigned long hp_sdc_put(void){ hp_sdc_transaction *curr; uint8_t act; int idx, curridx; int limit = 0; write_lock(&hp_sdc.lock); /* If i8042 buffers are full, we cannot do anything that requires output, so we skip to the administrativa. */ if (hp_sdc.ibf) { hp_sdc_status_in8(); if (hp_sdc.ibf) goto finish; } anew: /* See if we are in the middle of a sequence. */ if (hp_sdc.wcurr < 0) hp_sdc.wcurr = 0; read_lock_irq(&hp_sdc.rtq_lock); if (hp_sdc.rcurr == hp_sdc.wcurr) hp_sdc.wcurr++; read_unlock_irq(&hp_sdc.rtq_lock); if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0; curridx = hp_sdc.wcurr; if (hp_sdc.tq[curridx] != NULL) goto start; while (++curridx != hp_sdc.wcurr) { if (curridx >= HP_SDC_QUEUE_LEN) { curridx = -1; /* Wrap to top */ continue; } read_lock_irq(&hp_sdc.rtq_lock); if (hp_sdc.rcurr == curridx) { read_unlock_irq(&hp_sdc.rtq_lock); continue; } read_unlock_irq(&hp_sdc.rtq_lock); if (hp_sdc.tq[curridx] != NULL) break; /* Found one. */ } if (curridx == hp_sdc.wcurr) { /* There's nothing queued to do. */ curridx = -1; } hp_sdc.wcurr = curridx; start: /* Check to see if the interrupt mask needs to be set. */ if (hp_sdc.set_im) { hp_sdc_status_out8(hp_sdc.im | HP_SDC_CMD_SET_IM); hp_sdc.set_im = 0; goto finish; } if (hp_sdc.wcurr == -1) goto done; curr = hp_sdc.tq[curridx]; idx = curr->actidx; if (curr->actidx >= curr->endidx) { hp_sdc.tq[curridx] = NULL; /* Interleave outbound data between the transactions. */ hp_sdc.wcurr++; if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0; goto finish; } act = curr->seq[idx]; idx++; if (curr->idx >= curr->endidx) { if (act & HP_SDC_ACT_DEALLOC) kfree(curr); hp_sdc.tq[curridx] = NULL; /* Interleave outbound data between the transactions. */ hp_sdc.wcurr++; if (hp_sdc.wcurr >= HP_SDC_QUEUE_LEN) hp_sdc.wcurr = 0; goto finish; } while (act & HP_SDC_ACT_PRECMD) { if (curr->idx != idx) { idx++; act &= ~HP_SDC_ACT_PRECMD; break; } hp_sdc_status_out8(curr->seq[idx]); curr->idx++; /* act finished? */ if ((act & HP_SDC_ACT_DURING) == HP_SDC_ACT_PRECMD)//.........这里部分代码省略.........
开发者ID:CSCLOG,项目名称:beaglebone,代码行数:101,
示例18: action_lock_lockstatic inline void action_lock_lock(void){ lockdep_off(); write_lock(&krg_action_lock);}
开发者ID:jeanparpaillon,项目名称:kerrighed-kernel,代码行数:5,
示例19: hp_sdc_mlc_isr/************************* Interrupt context ******************************/static void hp_sdc_mlc_isr (int irq, void *dev_id, uint8_t status, uint8_t data){ int idx; hil_mlc *mlc = &hp_sdc_mlc; write_lock(&mlc->lock); if (mlc->icount < 0) { printk(KERN_WARNING PREFIX "HIL Overflow!/n"); up(&mlc->isem); goto out; } idx = 15 - mlc->icount; if ((status & HP_SDC_STATUS_IRQMASK) == HP_SDC_STATUS_HILDATA) { mlc->ipacket[idx] |= data | HIL_ERR_INT; mlc->icount--; if (hp_sdc_mlc_priv.got5x || !idx) goto check; if ((mlc->ipacket[idx - 1] & HIL_PKT_ADDR_MASK) != (mlc->ipacket[idx] & HIL_PKT_ADDR_MASK)) { mlc->ipacket[idx] &= ~HIL_PKT_ADDR_MASK; mlc->ipacket[idx] |= (mlc->ipacket[idx - 1] & HIL_PKT_ADDR_MASK); } goto check; } /* We know status is 5X */ if (data & HP_SDC_HIL_ISERR) goto err; mlc->ipacket[idx] = (data & HP_SDC_HIL_R1MASK) << HIL_PKT_ADDR_SHIFT; hp_sdc_mlc_priv.got5x = 1; goto out; check: hp_sdc_mlc_priv.got5x = 0; if (mlc->imatch == 0) goto done; if ((mlc->imatch == (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL)) && (mlc->ipacket[idx] == (mlc->imatch | idx))) goto done; if (mlc->ipacket[idx] == mlc->imatch) goto done; goto out; err: printk(KERN_DEBUG PREFIX "err code %x/n", data); switch (data) { case HP_SDC_HIL_RC_DONE: printk(KERN_WARNING PREFIX "Bastard SDC reconfigured loop!/n"); break; case HP_SDC_HIL_ERR: mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_PERR | HIL_ERR_FERR | HIL_ERR_FOF; break; case HP_SDC_HIL_TO: mlc->ipacket[idx] |= HIL_ERR_INT | HIL_ERR_LERR; break; case HP_SDC_HIL_RC: printk(KERN_WARNING PREFIX "Bastard SDC decided to reconfigure loop!/n"); break; default: printk(KERN_WARNING PREFIX "Unknown HIL Error status (%x)!/n", data); break; } /* No more data will be coming due to an error. */ done: tasklet_schedule(mlc->tasklet); up(&mlc->isem); out: write_unlock(&mlc->lock);}
开发者ID:Medvedroid,项目名称:OT_903D-kernel-2.6.35.7,代码行数:79,
示例20: xp_write_lockinline void xp_write_lock(struct xp_rwlock *rwlock){ write_lock(&(rwlock->rwlock));}
开发者ID:eqmcc,项目名称:dazuko,代码行数:4,
示例21: cifs_create//.........这里部分代码省略......... } rc = CIFSSMBOpen(xid, pTcon, full_path, disposition, desiredAccess, CREATE_NOT_DIR, &fileHandle, &oplock, buf, cifs_sb->local_nls); if (rc) { cFYI(1, ("cifs_create returned 0x%x ", rc)); } else { /* If Open reported that we actually created a file then we now have to set the mode if possible */ if ((cifs_sb->tcon->ses->capabilities & CAP_UNIX) && (oplock & CIFS_CREATE_ACTION)) if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) { CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode, (__u64)current->euid, (__u64)current->egid, 0 /* dev */, cifs_sb->local_nls); } else { CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode, (__u64)-1, (__u64)-1, 0 /* dev */, cifs_sb->local_nls); } else { /* BB implement via Windows security descriptors */ /* eg CIFSSMBWinSetPerms(xid,pTcon,full_path,mode,-1,-1,local_nls);*/ /* could set r/o dos attribute if mode & 0222 == 0 */ } /* BB server might mask mode so we have to query for Unix case*/ if (pTcon->ses->capabilities & CAP_UNIX) rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb,xid); else { rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb,xid); if(newinode) newinode->i_mode = mode; } if (rc != 0) { cFYI(1,("Create worked but get_inode_info failed with rc = %d", rc)); } else { direntry->d_op = &cifs_dentry_ops; d_instantiate(direntry, newinode); } if((nd->flags & LOOKUP_OPEN) == FALSE) { /* mknod case - do not leave file open */ CIFSSMBClose(xid, pTcon, fileHandle); } else if(newinode) { pCifsFile = (struct cifsFileInfo *) kmalloc(sizeof (struct cifsFileInfo), GFP_KERNEL); if (pCifsFile) { memset((char *)pCifsFile, 0, sizeof (struct cifsFileInfo)); pCifsFile->netfid = fileHandle; pCifsFile->pid = current->tgid; pCifsFile->pInode = newinode; pCifsFile->invalidHandle = FALSE; pCifsFile->closePend = FALSE; init_MUTEX(&pCifsFile->fh_sem); /* put the following in at open now */ /* pCifsFile->pfile = file; */ write_lock(&GlobalSMBSeslock); list_add(&pCifsFile->tlist,&pTcon->openFileList); pCifsInode = CIFS_I(newinode); if(pCifsInode) { /* if readable file instance put first in list*/ if (write_only == TRUE) { list_add_tail(&pCifsFile->flist, &pCifsInode->openFileList); } else { list_add(&pCifsFile->flist, &pCifsInode->openFileList); } if((oplock & 0xF) == OPLOCK_EXCLUSIVE) { pCifsInode->clientCanCacheAll = TRUE; pCifsInode->clientCanCacheRead = TRUE; cFYI(1,("Exclusive Oplock granted on inode %p", newinode)); } else if((oplock & 0xF) == OPLOCK_READ) pCifsInode->clientCanCacheRead = TRUE; } write_unlock(&GlobalSMBSeslock); } } } if (buf) kfree(buf); if (full_path) kfree(full_path); FreeXid(xid); return rc;}
开发者ID:BackupTheBerlios,项目名称:tuxap,代码行数:101,
示例22: sys_setProcessBudgetasmlinkage int sys_setProcessBudget(pid_t pid, unsigned long budget, struct timespec period) { struct task_struct * curr; struct task_struct * temp; unsigned long temp_time; struct cpufreq_policy * lastcpupolicy = cpufreq_cpu_get(0); unsigned long max_frequency = (lastcpupolicy->cpuinfo).max_freq / 1000 ; //Getting MAX frequency in MHz unsigned long sysclock_freq = 0; struct timespec task_budget; unsigned int ret_freq = 0, temp_freq; int ret_val; ktime_t p; struct task_ct_struct * list; //Error checks for input arguments if (!((period.tv_sec > 0) || (period.tv_nsec > 0))) { printk("Invalid time period/n"); return -EINVAL; } if (pid <= 0) { printk("Invalid PID/n"); return -EINVAL; } //checking admission write_lock(&tasklist_lock); //First get budget from cycles in (millions) / current CPU frequency in (Mhz) * 1000 ns temp_time = (budget / (max_frequency)) * 1000; task_budget = ns_to_timespec(temp_time); printk("Time in ns = %lu and frequency = %lu Mhz/n",temp_time,max_frequency); printk("Taks struct budget %ldsec and %ldnsec/n",task_budget.tv_sec,task_budget.tv_nsec); if(timespec_compare(&task_budget, &period) >= 0){ printk("Budget >= Period/n"); write_unlock(&tasklist_lock); return -EINVAL; } //We need to do it only in the case when we are running tasks without bin packing if(is_bin_packing_set == 0){ if(check_admission(task_budget, period) == 0){ printk("Cant add task to the taskset/n"); write_unlock(&tasklist_lock); return -EPERM; } } //Finding task struct given its pid curr = (struct task_struct *) find_task_by_vpid(pid); if(curr == NULL){ printk("Couldn't find task/n"); write_unlock(&tasklist_lock); return -ESRCH; } //If the task already had budget we are essentially changing the budget //So the task should go in a new place in the global list. //Thus, we delete the task and then reinsert it in the list. if(curr->is_budget_set == 1){ del_periodic_task(&(curr->periodic_task)); } //First check if a period timer already exists from a previous edition of this syscall. //If yes then we cancel it. //If this syscall returns 0 or 1 then timer is succesfully cancelled if (((curr -> time_period).tv_sec > 0) || ((curr -> time_period).tv_nsec > 0)) { hrtimer_cancel(&(curr->period_timer)); } //If timer is being initialized the first time then //Initialize timer , set the callback and set expiry period to Budget else { hrtimer_init(&(curr->period_timer),CLOCK_MONOTONIC,HRTIMER_MODE_REL); (curr->period_timer).function = &period_timer_callback; } //First check if a budget timer already exists from a previous edition of this syscall. //If yes then we cancel it. // If this syscall returns 0 or 1 then timer is succesfully cancelled if (((curr -> budget_time).tv_sec > 0) || ((curr -> budget_time).tv_nsec > 0)) { hrtimer_cancel(&(curr->budget_timer)); } //If timer is being initialized the first time then //Initialize timer , set the callback and set expiry period to Budget else { hrtimer_init(&(curr->budget_timer),CLOCK_MONOTONIC,HRTIMER_MODE_REL); (curr->budget_timer).function = &budget_timer_callback; } //Setting flag if(is_bin_packing_set == 0){ curr->is_budget_set = 1; temp = curr; do { //Setting flag temp->is_budget_set = 1; }while_each_thread(curr,temp); }
开发者ID:abhishekbhardwaj007,项目名称:Android-RealTimeExtensions,代码行数:100,
示例23: expand_fdset/* * Expand the fdset in the files_struct. Called with the files spinlock * held for write. */int expand_fdset(struct files_struct *files, int nr){ fd_set *new_openset = 0, *new_execset = 0; int error, nfds = 0; error = -EMFILE; if (files->max_fdset >= NR_OPEN || nr >= NR_OPEN) goto out; nfds = files->max_fdset; write_unlock(&files->file_lock); /* Expand to the max in easy steps */ do { if (nfds < (PAGE_SIZE * 8)) nfds = PAGE_SIZE * 8; else { nfds = nfds * 2; if (nfds > NR_OPEN) nfds = NR_OPEN; } } while (nfds <= nr); error = -ENOMEM; new_openset = alloc_fdset(nfds); new_execset = alloc_fdset(nfds); write_lock(&files->file_lock); if (!new_openset || !new_execset) goto out; error = 0; /* Copy the existing tables and install the new pointers */ if (nfds > files->max_fdset) { int i = files->max_fdset / (sizeof(unsigned long) * 8); int count = (nfds - files->max_fdset) / 8; /* * Don't copy the entire array if the current fdset is * not yet initialised. */ if (i) { memcpy (new_openset, files->open_fds, files->max_fdset/8); memcpy (new_execset, files->close_on_exec, files->max_fdset/8); memset (&new_openset->fds_bits[i], 0, count); memset (&new_execset->fds_bits[i], 0, count); } nfds = xchg(&files->max_fdset, nfds); new_openset = xchg(&files->open_fds, new_openset); new_execset = xchg(&files->close_on_exec, new_execset); write_unlock(&files->file_lock); free_fdset (new_openset, nfds); free_fdset (new_execset, nfds); write_lock(&files->file_lock); return 0; } /* Somebody expanded the array while we slept ... */out: write_unlock(&files->file_lock); if (new_openset) free_fdset(new_openset, nfds); if (new_execset) free_fdset(new_execset, nfds); write_lock(&files->file_lock); return error;}
开发者ID:nhanh0,项目名称:hah,代码行数:72,
注:本文中的write_lock函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ write_lock_bh函数代码示例 C++ write_line函数代码示例 |