void Yap_InitConstExps(void) { unsigned int i; ExpEntry *p; for (i = 0; i < sizeof(InitConstTab)/sizeof(InitConstEntry); ++i) { AtomEntry *ae = RepAtom(Yap_LookupAtom(InitConstTab[i].OpName)); if (ae == NULL) { Yap_EvalError(RESOURCE_ERROR_HEAP,TermNil,"at InitConstExps"); return; } WRITE_LOCK(ae->ARWLock); if (Yap_GetExpPropHavingLock(ae, 0)) { WRITE_UNLOCK(ae->ARWLock); break; } p = (ExpEntry *) Yap_AllocAtomSpace(sizeof(ExpEntry)); p->KindOfPE = ExpProperty; p->ArityOfEE = 0; p->ENoOfEE = 0; p->FOfEE = InitConstTab[i].f; AddPropToAtom(ae, (PropEntry *)p); WRITE_UNLOCK(ae->ARWLock); } }
/* * NAME: jfs_sync(vfsp) * * FUNCTION: commit all regular files in the vfs which have not been * committed since the last time jfs_sync() was invoked. * * initiates i/o for all modified journalled pages which * can be written to their home address or marks those which * can not so that they will be written when they are committed. * a new logsync value is computed for the log. * * PARAMETER: none * * RETURN: always 0 */ int32 jfs_sync(struct vfs *vfsp) { inode_t *ipmnt; if (vfsp->vfs_flag & VFS_READONLY) return 0; ipmnt = ((inode_t *)vfsp->vfs_data)->i_ipmnt; if (!(WRITE_LOCK_TRY(&ipmnt->i_rdwrlock))) return 0; /* Avoid deadlock with hard quiesce */ if (ipmnt->i_cachedev->cd_flag & CD_QUIESCE) { WRITE_UNLOCK(&ipmnt->i_rdwrlock); return 0; } /* commit all regular files in this vfs */ iSyncFS(vfsp); /* sync the log associated with the vfs */ lmSync((log_t *)(((inode_t *)vfsp->vfs_data)->i_ipmnt->i_iplog)); WRITE_UNLOCK(&ipmnt->i_rdwrlock); return 0; }
void Yap_LookupAtomWithAddress(const char *atom, AtomEntry *ae) { /* lookup atom in atom table */ register CELL hash; register const unsigned char *p; Atom a; /* compute hash */ p = (const unsigned char *)atom; hash = HashFunction(p) % AtomHashTableSize; /* ask for a WRITE lock because it is highly unlikely we shall find anything */ WRITE_LOCK(HashChain[hash].AERWLock); a = HashChain[hash].Entry; /* search atom in chain */ if (SearchAtom(p, a) != NIL) { Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "repeated initialization for atom %s", ae); WRITE_UNLOCK(HashChain[hash].AERWLock); return; } /* add new atom to start of chain */ NOfAtoms++; ae->NextOfAE = a; HashChain[hash].Entry = AbsAtom(ae); ae->PropsOfAE = NIL; strcpy((char *)ae->StrOfAE, (char *)atom); INIT_RWLOCK(ae->ARWLock); WRITE_UNLOCK(HashChain[hash].AERWLock); }
void Yap_ReleaseAtom(Atom atom) { /* Releases an atom from the hash chain */ register Int hash; register const unsigned char *p; AtomEntry *inChain; AtomEntry *ap = RepAtom(atom); char unsigned *name = ap->UStrOfAE; /* compute hash */ p = name; hash = HashFunction(p) % AtomHashTableSize; WRITE_LOCK(HashChain[hash].AERWLock); if (HashChain[hash].Entry == atom) { NOfAtoms--; HashChain[hash].Entry = ap->NextOfAE; WRITE_UNLOCK(HashChain[hash].AERWLock); return; } /* else */ inChain = RepAtom(HashChain[hash].Entry); while (inChain->NextOfAE != atom) inChain = RepAtom(inChain->NextOfAE); WRITE_LOCK(inChain->ARWLock); inChain->NextOfAE = ap->NextOfAE; WRITE_UNLOCK(inChain->ARWLock); WRITE_UNLOCK(HashChain[hash].AERWLock); }
static BBProp PutBBProp(AtomEntry *ae, Term mod USES_REGS) /* get BBentry for at; */ { Prop p0; BBProp p; WRITE_LOCK(ae->ARWLock); p = RepBBProp(p0 = ae->PropsOfAE); while (p0 != NIL && (!IsBBProperty(p->KindOfPE) || (p->ModuleOfBB != mod))) { p = RepBBProp(p0 = p->NextOfPE); } if (p0 == NIL) { p = (BBProp)Yap_AllocAtomSpace(sizeof(*p)); if (p == NULL) { WRITE_UNLOCK(ae->ARWLock); Yap_Error(OUT_OF_HEAP_ERROR,ARG1,"could not allocate space in bb_put/2"); return(NULL); } AddPropToAtom(ae, (PropEntry *)p); p->ModuleOfBB = mod; p->Element = 0L; p->KeyOfBB = AbsAtom(ae); p->KindOfPE = BBProperty; INIT_RWLOCK(p->BBRWLock); } WRITE_UNLOCK(ae->ARWLock); return (p); }
/* Returns verdict for packet, or -1 for invalid. */ static int tcp_packet(struct ip_conntrack *conntrack, struct iphdr *iph, size_t len, enum ip_conntrack_info ctinfo) { enum tcp_conntrack newconntrack, oldtcpstate; struct tcphdr *tcph = (struct tcphdr *)((u_int32_t *)iph + iph->ihl); /* We're guaranteed to have the base header, but maybe not the options. */ if (len < (iph->ihl + tcph->doff) * 4) { DEBUGP("ip_conntrack_tcp: Truncated packet.\n"); return -1; } WRITE_LOCK(&tcp_lock); oldtcpstate = conntrack->proto.tcp.state; newconntrack = tcp_conntracks [CTINFO2DIR(ctinfo)] [get_conntrack_index(tcph)][oldtcpstate]; /* Invalid */ if (newconntrack == TCP_CONNTRACK_MAX) { DEBUGP("ip_conntrack_tcp: Invalid dir=%i index=%u conntrack=%u\n", CTINFO2DIR(ctinfo), get_conntrack_index(tcph), conntrack->proto.tcp.state); WRITE_UNLOCK(&tcp_lock); return -1; } conntrack->proto.tcp.state = newconntrack; /* Poor man's window tracking: record SYN/ACK for handshake check */ if (oldtcpstate == TCP_CONNTRACK_SYN_SENT && CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY && tcph->syn && tcph->ack) conntrack->proto.tcp.handshake_ack = htonl(ntohl(tcph->seq) + 1); WRITE_UNLOCK(&tcp_lock); /* If only reply is a RST, we can consider ourselves not to have an established connection: this is a fairly common problem case, so we can delete the conntrack immediately. --RR */ if (!(conntrack->status & IPS_SEEN_REPLY) && tcph->rst) { if (del_timer(&conntrack->timeout)) conntrack->timeout.function((unsigned long)conntrack); } else { /* Set ASSURED if we see see valid ack in ESTABLISHED after SYN_RECV */ if (oldtcpstate == TCP_CONNTRACK_SYN_RECV && CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL && tcph->ack && !tcph->syn && tcph->ack_seq == conntrack->proto.tcp.handshake_ack) set_bit(IPS_ASSURED_BIT, &conntrack->status); ip_ct_refresh(conntrack, tcp_timeouts[newconntrack]); } return NF_ACCEPT; }
static Atom LookupAtom(const unsigned char *atom) { /* lookup atom in atom table */ uint64_t hash; const unsigned char *p; Atom a, na; AtomEntry *ae; size_t sz = AtomHashTableSize; /* compute hash */ p = atom; hash = HashFunction(p); hash = hash % sz ; /* we'll start by holding a read lock in order to avoid contention */ READ_LOCK(HashChain[hash].AERWLock); a = HashChain[hash].Entry; /* search atom in chain */ na = SearchAtom(atom, a); if (na != NIL) { READ_UNLOCK(HashChain[hash].AERWLock); return (na); } READ_UNLOCK(HashChain[hash].AERWLock); /* we need a write lock */ WRITE_LOCK(HashChain[hash].AERWLock); /* concurrent version of Yap, need to take care */ #if defined(YAPOR) || defined(THREADS) if (a != HashChain[hash].Entry) { a = HashChain[hash].Entry; na = SearchAtom(atom, a); if (na != NIL) { WRITE_UNLOCK(HashChain[hash].AERWLock); return (na); } } #endif /* add new atom to start of chain */ ae = (AtomEntry *)Yap_AllocAtomSpace((sizeof *ae) + strlen((const char *)atom) + 1); if (ae == NULL) { WRITE_UNLOCK(HashChain[hash].AERWLock); return NIL; } NOfAtoms++; na = AbsAtom(ae); ae->PropsOfAE = NIL; if (ae->UStrOfAE != atom) strcpy((char *)ae->StrOfAE, (const char *)atom); ae->NextOfAE = a; HashChain[hash].Entry = na; INIT_RWLOCK(ae->ARWLock); WRITE_UNLOCK(HashChain[hash].AERWLock); if (NOfAtoms > 2 * AtomHashTableSize) { Yap_signal(YAP_CDOVF_SIGNAL); } return na; }
static int OpDec(int p, const char *type, Atom a, Term m) { int i; AtomEntry *ae = RepAtom(a); OpEntry *info; if (m == TermProlog) m = PROLOG_MODULE; else if (m == USER_MODULE) m = PROLOG_MODULE; for (i = 1; i <= 7; ++i) if (strcmp(type, optypes[i]) == 0) break; if (i > 7) { Yap_Error(DOMAIN_ERROR_OPERATOR_SPECIFIER,MkAtomTerm(Yap_LookupAtom(type)),"op/3"); return(FALSE); } if (p) { if (i == 1 || i == 2 || i == 4) p |= DcrlpFlag; if (i == 1 || i == 3 || i == 6) p |= DcrrpFlag; } WRITE_LOCK(ae->ARWLock); info = Yap_GetOpPropForAModuleHavingALock(ae, m); if (EndOfPAEntr(info)) { info = (OpEntry *) Yap_AllocAtomSpace(sizeof(OpEntry)); info->KindOfPE = Ord(OpProperty); info->OpModule = m; info->OpName = a; //LOCK(OpListLock); info->OpNext = OpList; OpList = info; //UNLOCK(OpListLock); AddPropToAtom(ae, (PropEntry *)info); INIT_RWLOCK(info->OpRWLock); WRITE_LOCK(info->OpRWLock); WRITE_UNLOCK(ae->ARWLock); info->Prefix = info->Infix = info->Posfix = 0; } else { WRITE_LOCK(info->OpRWLock); WRITE_UNLOCK(ae->ARWLock); } if (i <= 3) { GET_LD if (truePrologFlag(PLFLAG_ISO) && info->Posfix != 0) /* there is a posfix operator */ { /* ISO dictates */ WRITE_UNLOCK(info->OpRWLock); Yap_Error(PERMISSION_ERROR_CREATE_OPERATOR,MkAtomTerm(a),"op/3"); return FALSE; } info->Infix = p; } else if (i <= 5) {
static void alloc_request_p(u_int32_t xid, u_int16_t proto, u_int32_t ip, u_int16_t port) { struct request_p *req_p; /* Verifies if entry already exists */ WRITE_LOCK(&ipct_rpc_udp_lock); req_p = LIST_FIND(&request_p_list_udp, request_p_cmp, struct request_p *, xid, ip, port); if (req_p) { /* Refresh timeout */ if (del_timer(&req_p->timeout)) { req_p->timeout.expires = jiffies + EXP; add_timer(&req_p->timeout); } WRITE_UNLOCK(&ipct_rpc_udp_lock); return; } WRITE_UNLOCK(&ipct_rpc_udp_lock); /* Allocate new request_p */ req_p = (struct request_p *) kmalloc(sizeof(struct request_p), GFP_ATOMIC); if (!req_p) { DEBUGP("can't allocate request_p\n"); return; } req_p->list.next = NULL; req_p->list.prev = NULL; req_p->xid = xid; req_p->ip = ip; req_p->port = port; req_p->proto = proto; /* Initialize timer */ init_timer(&req_p->timeout); req_p->timeout.expires = jiffies + EXP; req_p->timeout.data = (unsigned long)req_p; req_p->timeout.function = delete_request_p; add_timer(&req_p->timeout); /* Put in list */ WRITE_LOCK(&ipct_rpc_udp_lock); list_prepend(&request_p_list_udp, req_p); WRITE_UNLOCK(&ipct_rpc_udp_lock); return; }
// Called when a process, which already opened the dev file, attempts to read from it static ssize_t dev_device_read(struct file *filp, char *buffer, size_t length, loff_t *offset) { char msg[100]; int bytes_read = 0; WRITE_LOCK(g_ser_device_lock); sprintf(msg,"SEREADMO char device registred and open %d times", g_device_counter); WRITE_UNLOCK(g_ser_device_lock); bytes_read = strlen(msg); if(*offset >= bytes_read) // no more bytes to read return 0; bytes_read -= *offset; // bytes left to read if(bytes_read > length) bytes_read = length; if(copy_to_user(buffer,msg+(*offset),bytes_read) != 0) { MSG_FAILED("SEREADMO copy_to_user failed\n"); bytes_read = 0; } *offset += bytes_read; return bytes_read; }
/* Update sender->td_end after NAT successfully mangled the packet */ int ip_conntrack_tcp_update(struct sk_buff *skb, struct ip_conntrack *conntrack, int dir) { struct iphdr *iph = skb->nh.iph; struct tcphdr *tcph = (void *)skb->nh.iph + skb->nh.iph->ihl*4; __u32 end; #ifdef DEBUGP_VARS struct ip_ct_tcp_state *sender = &conntrack->proto.tcp.seen[dir]; struct ip_ct_tcp_state *receiver = &conntrack->proto.tcp.seen[!dir]; #endif end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, iph, tcph); WRITE_LOCK(&tcp_lock); /* * We have to worry for the ack in the reply packet only... */ if (after(end, conntrack->proto.tcp.seen[dir].td_end)) conntrack->proto.tcp.seen[dir].td_end = end; conntrack->proto.tcp.last_end = end; WRITE_UNLOCK(&tcp_lock); DEBUGP("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i " "receiver end=%u maxend=%u maxwin=%u scale=%i\n", sender->td_end, sender->td_maxend, sender->td_maxwin, sender->td_scale, receiver->td_end, receiver->td_maxend, receiver->td_maxwin, receiver->td_scale); return 1; }
// Called when a process closes the device file static int dev_device_release(struct inode *inode, struct file *file) { WRITE_LOCK(g_ser_device_lock); g_device_counter--; WRITE_UNLOCK(g_ser_device_lock); return 0; }
// Called when a process tries to open the device file, like "cat /dev/sereadmo" static int dev_device_open(struct inode *inode, struct file *file) { WRITE_LOCK(g_ser_device_lock); g_device_counter++; WRITE_UNLOCK(g_ser_device_lock); return 0; }
/* Noone stores the protocol anywhere; simply delete it. */ void ip_nat_protocol_unregister(struct ip_nat_protocol *proto) { WRITE_LOCK(&ip_nat_lock); ip_nat_protos[proto->protonum] = &ip_nat_unknown_protocol; WRITE_UNLOCK(&ip_nat_lock); /* Someone could be still looking at the proto in a bh. */ synchronize_net(); }
static void req_cl(struct request_p * r) { WRITE_LOCK(&ipct_rpc_udp_lock); del_timer(&r->timeout); LIST_DELETE(&request_p_list_udp, r); WRITE_UNLOCK(&ipct_rpc_udp_lock); kfree(r); return; }
/* vsc: We must guarantee that IsVarTerm(functor) returns true! */ Functor Yap_MkFunctor(Atom ap, unsigned int arity) { AtomEntry *ae = RepAtom(ap); Functor f; WRITE_LOCK(ae->ARWLock); f = InlinedUnlockedMkFunctor(ae, arity); WRITE_UNLOCK(ae->ARWLock); return (f); }
static void delete_request_p(unsigned long request_p_ul) { struct request_p *p = (void *)request_p_ul; WRITE_LOCK(&ipct_rpc_udp_lock); LIST_DELETE(&request_p_list_udp, p); WRITE_UNLOCK(&ipct_rpc_udp_lock); kfree(p); return; }
/* vsc: We must guarantee that IsVarTerm(functor) returns true! */ void Yap_MkFunctorWithAddress(Atom ap, unsigned int arity, FunctorEntry *p) { AtomEntry *ae = RepAtom(ap); WRITE_LOCK(ae->ARWLock); p->KindOfPE = FunctorProperty; p->NameOfFE = ap; p->ArityOfFE = arity; AddPropToAtom(ae, (PropEntry *)p); WRITE_UNLOCK(ae->ARWLock); }
/* Noone stores the protocol anywhere; simply delete it. */ void ip_nat_protocol_unregister(struct ip_nat_protocol *proto) { WRITE_LOCK(&ip_nat_lock); LIST_DELETE(&protos, proto); WRITE_UNLOCK(&ip_nat_lock); /* Someone could be still looking at the proto in a bh. */ br_write_lock_bh(BR_NETPROTO_LOCK); br_write_unlock_bh(BR_NETPROTO_LOCK); MOD_DEC_USE_COUNT; }
void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto) { WRITE_LOCK(&ip_conntrack_lock); ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol; WRITE_UNLOCK(&ip_conntrack_lock); /* Somebody could be still looking at the proto in bh. */ synchronize_net(); /* Remove all contrack entries for this protocol */ ip_ct_selective_cleanup(kill_proto, &proto->proto); }
PUBLIC int avl_tree_insert (avl_tree_t *tree, void *data_to_be_inserted, void **data_already_present) { int rv; WRITE_LOCK(tree); rv = thread_unsafe_avl_tree_insert(tree, data_to_be_inserted, data_already_present); WRITE_UNLOCK(tree); return rv; }
PUBLIC int avl_tree_remove (avl_tree_t *tree, void *data_to_be_removed, void **data_actually_removed) { int rv; WRITE_LOCK(tree); rv = thread_unsafe_avl_tree_remove(tree, data_to_be_removed, data_actually_removed); WRITE_UNLOCK(tree); return rv; }
/* Protocol registration. */ int ip_nat_protocol_register(struct ip_nat_protocol *proto) { int ret = 0; WRITE_LOCK(&ip_nat_lock); if (ip_nat_protos[proto->protonum] != &ip_nat_unknown_protocol) { ret = -EBUSY; goto out; } ip_nat_protos[proto->protonum] = proto; out: WRITE_UNLOCK(&ip_nat_lock); return ret; }
static int h245_expect(struct ip_conntrack *ct) { WRITE_LOCK(&ip_conntrack_lock); //ct->ifx_alg_qos_mark = IFX_ALG_APP_H323 | IFX_ALG_PROTO_CTRL ; ct->ifx_alg_qos_mark = IFX_ALG_APP_H323 | IFX_ALG_PROTO_RTP ; DEBUGP("h245_expect: helper for %p added\n", ct); // RTP helper //ct->helper = &rtp_helper; WRITE_UNLOCK(&ip_conntrack_lock); return NF_ACCEPT; /* unused */ }
/* FIXME: Allow NULL functions and sub in pointers to generic for them. --RR */ int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto) { int ret = 0; WRITE_LOCK(&ip_conntrack_lock); if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) { ret = -EBUSY; goto out; } ip_ct_protos[proto->proto] = proto; out: WRITE_UNLOCK(&ip_conntrack_lock); return ret; }
void Yap_InitBinaryExps(void) { unsigned int i; ExpEntry *p; for (i = 0; i < sizeof(InitBinTab)/sizeof(InitBinEntry); ++i) { AtomEntry *ae = RepAtom(Yap_LookupAtom(InitBinTab[i].OpName)); if (ae == NULL) { Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"at InitBinaryExps"); return; } WRITE_LOCK(ae->ARWLock); if (Yap_GetExpPropHavingLock(ae, 2)) { WRITE_UNLOCK(ae->ARWLock); break; } p = (ExpEntry *) Yap_AllocAtomSpace(sizeof(ExpEntry)); p->KindOfPE = ExpProperty; p->ArityOfEE = 2; p->ENoOfEE = 2; p->FOfEE = InitBinTab[i].f; p->NextOfPE = ae->PropsOfAE; ae->PropsOfAE = AbsExpProp(p); WRITE_UNLOCK(ae->ARWLock); } Yap_InitCPred("is", 4, p_binary_is, TestPredFlag | SafePredFlag); Yap_InitCPred("$binary_op_as_integer", 2, p_binary_op_as_integer, TestPredFlag|SafePredFlag); Yap_InitAsmPred("$plus", 3, _plus, export_p_plus, SafePredFlag); Yap_InitAsmPred("$minus", 3, _minus, export_p_minus, SafePredFlag); Yap_InitAsmPred("$times", 3, _times, export_p_times, SafePredFlag); Yap_InitAsmPred("$div", 3, _div, export_p_div, SafePredFlag); Yap_InitAsmPred("$and", 3, _and, export_p_and, SafePredFlag); Yap_InitAsmPred("$or", 3, _or, export_p_or, SafePredFlag); Yap_InitAsmPred("$sll", 3, _sll, export_p_sll, SafePredFlag); Yap_InitAsmPred("$slr", 3, _slr, export_p_slr, SafePredFlag); }
OpEntry * Yap_OpPropForModule(Atom a, Term mod) { /* look property list of atom a for kind */ AtomEntry *ae = RepAtom(a); PropEntry *pp; OpEntry *info = NULL; if (mod == TermProlog) mod = PROLOG_MODULE; WRITE_LOCK(ae->ARWLock); pp = RepProp(ae->PropsOfAE); while (!EndOfPAEntr(pp)) { if (pp->KindOfPE == OpProperty) { info = (OpEntry *)pp; if (info->OpModule == mod) { WRITE_LOCK(info->OpRWLock); WRITE_UNLOCK(ae->ARWLock); return info; } } pp = pp->NextOfPE; } info = (OpEntry *)Yap_AllocAtomSpace(sizeof(OpEntry)); info->KindOfPE = Ord(OpProperty); info->OpModule = mod; info->OpName = a; LOCK(OpListLock); info->OpNext = OpList; OpList = info; UNLOCK(OpListLock); AddPropToAtom(ae, (PropEntry *)info); INIT_RWLOCK(info->OpRWLock); WRITE_LOCK(info->OpRWLock); WRITE_UNLOCK(ae->ARWLock); info->Prefix = info->Infix = info->Posfix = 0; return info; }
PUBLIC void avl_tree_destroy (avl_tree_t *tree) { WRITE_LOCK(tree); avl_node_destroy_nodes(tree, tree->root_node, 0); assert(tree->n == 0); tree->root_node = NULL; #if 0 tree->first_node = tree->last_node = NULL; #endif tree->cmpf = NULL; WRITE_UNLOCK(tree); LOCK_OBJ_DESTROY(tree); }
/* Protocol registration. */ int ip_nat_protocol_register(struct ip_nat_protocol *proto) { int ret = 0; struct list_head *i; WRITE_LOCK(&ip_nat_lock); for (i = protos.next; i != &protos; i = i->next) { if (((struct ip_nat_protocol *)i)->protonum == proto->protonum) { ret = -EBUSY; goto out; } } list_prepend(&protos, proto); MOD_INC_USE_COUNT; out: WRITE_UNLOCK(&ip_nat_lock); return ret; }
PUBLIC int avl_tree_init (avl_tree_t *tree, int make_it_thread_safe, object_comparer cmpf, mem_monitor_t *parent_mem_monitor, chunk_manager_parameters_t *cmpp) { if (NULL == cmpf) return EINVAL; MEM_MONITOR_SETUP(tree); LOCK_SETUP(tree); CHUNK_MANAGER_SETUP(tree, sizeof(avl_node_t), cmpp); tree->cmpf = cmpf; tree->n = 0; tree->root_node = NULL; tree->cannot_be_modified = 0; WRITE_UNLOCK(tree); return 0; }