void trie_cleanup(void) { rwlock_wr_lock(&tree_lock); ptree_free(tree); rwlock_unlock(&tree_lock); rwlock_destroy(&tree_lock); }
int destroy_cache(cache_t *c) { printk(1, "[cache]: Destroying cache '%s'...\n", c->name); rwlock_acquire(c->rwl, RWL_WRITER); chash_t *h = c->hash; c->hash = 0; sync_cache(c); /* Destroy the tree */ chash_destroy(h); struct llistnode *curnode, *next; struct ce_t *obj; ll_for_each_entry_safe(&c->primary_ll, curnode, next, struct ce_t *, obj) { ll_maybe_reset_loop(&c->primary_ll, curnode, next); remove_element(c, obj, 1); } ll_destroy(&c->dirty_ll); ll_destroy(&c->primary_ll); ll_remove_entry(cache_list, c); rwlock_release(c->rwl, RWL_WRITER); rwlock_destroy(c->rwl); printk(1, "[cache]: Cache '%s' destroyed\n", c->name); return 1; }
/* you probably do not want to call this function directly. Use vfs_icache_put instead. */ void vfs_inode_destroy(struct inode *node) { if(node->kdev && node->kdev->destroy) node->kdev->destroy(node); if(node->kdev) { dm_device_put(node->kdev); node->kdev = 0; } rwlock_destroy(&node->lock); rwlock_destroy(&node->metalock); assert(!node->count); assert(!node->dirents.count); hash_destroy(&node->dirents); assert(!(node->flags & INODE_INUSE)); fs_inode_destroy_physicals(node); kfree(node); }
void repo_destroy(repo* rep) { if (rep->mountpt) gen_free(rep->mountpt); if (rep->repo) gen_free(rep->repo); rwlock_destroy(&rep->fslock); mutex_destroy(&rep->idlock); }
static void destroy_sockaddr_mapper(void) { rwlock_wr_lock(&sockaddr_map_lock); for_each_hash(&sockaddr_mapper, cleanup_batch_sockaddr_mapper); free_hash(&sockaddr_mapper); rwlock_unlock(&sockaddr_map_lock); rwlock_destroy(&sockaddr_map_lock); }
/* * Function: CreateMobilityAgentEntry * * Arguments: maEntryType - Whether the entry is dynamic or * static * address - The Mobility Agent's IP Address * SPI - The Mobility Agent's SPI * lifetime - The lifetime of the entry (for * dynamic entries only) * * Description: This function will create the Mobility Agent * Entry, and will add it to the Hash table. * The SPI provided MUST have been previously * defined, otherwise an error will occur. * * If the node is created as a dynamic entry, * we will setup the entry's expiration time. * * The entry will be locked upon return. * The caller is responsible for unlocking the * node when it is finished with it. * * Returns: upon successful return, this function will * return the Mobility Agent Entry pointer, * otherwise NULL. */ MobilityAgentEntry * CreateMobilityAgentEntry(boolean_t isDynamic, ipaddr_t address, uint32_t SPI, uint32_t lifetime) { MobilityAgentEntry *entry = NULL; time_t currentTime; /* * First, let's make sure that we do not already have * this SPI defined. */ if (findHashTableEntryUint(&mipSecAssocHash, SPI, LOCK_NONE, NULL, 0, 0, 0) == NULL) { syslog(LOG_ERR, "SPI entry %d not found", SPI); return (NULL); } entry = (MobilityAgentEntry *)calloc(1, sizeof (MobilityAgentEntry)); if (!entry) { syslog(LOG_CRIT, "FATAL: Unable to allocate MIP Agent Entry"); return (NULL); } /* Now add our values */ entry->maAddr = address; entry->maSPI = SPI; entry->maIsEntryDynamic = isDynamic; if (isDynamic) { /* * Setup when the key expires... */ GET_TIME(currentTime); entry->maExpiration = currentTime + lifetime; } else { entry->maExpiration = TIME_INFINITY; } if (rwlock_init(&entry->maNodeLock, USYNC_THREAD, NULL)) { syslog(LOG_ERR, "Unable to initialize read/write lock"); free(entry); return (NULL); } if (linkHashTableEntryUint(&mipAgentHash, entry->maAddr, entry, LOCK_WRITE)) { syslog(LOG_ERR, "Unable to add MIP Agent entry to hash " "table"); (void) rwlock_destroy(&entry->maNodeLock); free(entry); return (NULL); } return (entry); }
/** * @brief Free a magma folder object and its underlying records. * @return This function returns no value. */ void magma_folder_free(magma_folder_t *folder) { if (folder) { inx_cleanup(folder->records); rwlock_destroy(&(folder->lock)); mm_free(folder); } return; }
P_LIB_API void p_rwlock_free (PRWLock *lock) { if (P_UNLIKELY (lock == NULL)) return; if (P_UNLIKELY (rwlock_destroy (&lock->hdl) != 0)) P_ERROR ("PRWLock::p_rwlock_free: rwlock_destroy() failed"); p_free (lock); }
void destroy_cpusched(void) { rwlock_wr_lock(&map_lock); xfree(cpu_assigned); cpu_len = 0; for_each_hash(&mapper, cleanup_batch); free_hash(&mapper); rwlock_unlock(&map_lock); rwlock_destroy(&map_lock); }
int bacstack_session_destroy(bacstack_session_t *session) { return 1 && rwlock_destroy(&session->routetable_lock) && bacstack_routetable_destroy(&session->routetable) && pool_destroy(&session->message_pool) && pool_destroy(&session->proc_pool) && bacdl_server_destroy(&session->dl_server) && thread_destroy(&session->msg_proc_thread) && thread_destroy(&session->dl_accept_thread) && thread_destroy(&session->dl_receive_thread); }
void CRYPTO_thread_cleanup(void) { int i; CRYPTO_set_locking_callback(NULL); for (i = 0; i < CRYPTO_num_locks(); i++) { # ifdef USE_MUTEX mutex_destroy(&(lock_cs[i])); # else rwlock_destroy(&(lock_cs[i])); # endif } OPENSSL_free(lock_cs); OPENSSL_free(lock_count); }
void destroy_serv_store(void) { struct server_store *elem, *nelem = NULL; rwlock_wr_lock(&store_lock); selected = NULL; elem = store; while (elem) { nelem = elem->next; elem->next = NULL; server_store_free(elem); elem = nelem; } rwlock_unlock(&store_lock); rwlock_destroy(&store_lock); }
void servers_free(bool end) { DBUG_ENTER("servers_free"); if (!hash_inited(&servers_cache)) DBUG_VOID_RETURN; if (!end) { free_root(&mem, MYF(MY_MARK_BLOCKS_FREE)); my_hash_reset(&servers_cache); DBUG_VOID_RETURN; } rwlock_destroy(&THR_LOCK_servers); free_root(&mem,MYF(0)); hash_free(&servers_cache); DBUG_VOID_RETURN; }
/** * @brief Allocate and initialize a meta user object. * * @return NULL on failure, or a pointer to the newly allocated meta user object on success. */ meta_user_t * meta_alloc(void) { meta_user_t *user; pthread_rwlockattr_t attr; // Configure the rwlock attributes structure to prefer write lock requests. if (rwlock_attr_init(&attr)) { log_pedantic("Unable to initialize the read/write lock attributes."); return NULL; } else if (rwlock_attr_setkind(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NP)) { log_pedantic("Unable to set the read/write lock attributes."); rwlock_attr_destroy(&attr); return NULL; } // Allocate the meta user object. if (!(user = mm_alloc(sizeof(meta_user_t)))) { log_pedantic("Unable to allocate %zu bytes for a user meta information structure.", sizeof(meta_user_t)); rwlock_attr_destroy(&attr); return NULL; } // Wipe the meta user object and set all of the pointers to NULL. mm_wipe(user, sizeof(meta_user_t)); // Initialize the rwlock. if (rwlock_init(&(user->lock), &attr) != 0) { log_pedantic("Unable to initialize the read/write lock."); rwlock_attr_destroy(&attr); mm_free(user); return NULL; } // Initialize the mutex. else if (mutex_init(&(user->refs.lock), NULL) != 0) { log_pedantic("Unable to initialize the user reference lock."); rwlock_destroy(&(user->lock)); rwlock_attr_destroy(&attr); mm_free(user); return NULL; } rwlock_attr_destroy(&attr); return user; }
/* WARNING: This does not sync!!! */ void remove_element(cache_t *c, struct ce_t *o, int locked) { if(!o) return; if(o->dirty) panic(PANIC_NOSYNC, "tried to remove non-sync'd element"); if(!locked) rwlock_acquire(c->rwl, RWL_WRITER); if(o->dirty) set_dirty(c, o, 0); assert(c->count); sub_atomic(&c->count, 1); ll_remove(&c->primary_ll, o->list_node); if(c->hash) chash_delete(c->hash, o->id, o->key); if(o->data) kfree(o->data); rwlock_destroy(o->rwl); kfree(o); if(!locked) rwlock_release(c->rwl, RWL_WRITER); }
void destroy_user_store(void) { struct user_store *elem, *nelem = NULL; rwlock_wr_lock(&store_lock); elem = store; while (elem) { nelem = elem->next; elem->next = NULL; user_store_free(elem); elem = nelem; } rwlock_unlock(&store_lock); rwlock_destroy(&store_lock); destroy_sock_mapper(); destroy_sockaddr_mapper(); }
MipTunlEntry * CreateTunlEntry(int tnum, ipaddr_t target, ipaddr_t tunsrc, int muxfd) { MipTunlEntry *entry = NULL; /* * First, let's make sure that we do not already have * this target defined. */ if ((findHashTableEntryUint(&mipTunlHash, target, LOCK_NONE, MipTunlEntryLookup, tunsrc, 0, 0)) != NULL) { syslog(LOG_ERR, "Duplicate target entry requested %x", target); return (NULL); } entry = (MipTunlEntry *)calloc(1, sizeof (MipTunlEntry)); if (!entry) { syslog(LOG_CRIT, "FATAL: Unable to allocate Tunl Entry"); return (NULL); } entry->tunnelno = tnum; entry->tunnelsrc = tunsrc; entry->mux_fd = muxfd; if (rwlock_init(&entry->TunlNodeLock, USYNC_THREAD, NULL)) { syslog(LOG_ERR, "Unable to initialize read/write lock"); free(entry); return (NULL); } if (linkHashTableEntryUint(&mipTunlHash, target, entry, LOCK_WRITE)) { syslog(LOG_ERR, "Unable to add Tunnel entry to hash table"); (void) rwlock_destroy(&entry->TunlNodeLock); free(entry); return (NULL); } return (entry); }
int main(int argc, char** argv) { const int thread_count = 10; pthread_t tid[thread_count]; int i; rwlock_init(&s_rwlock); for (i = 0; i < thread_count; i++) { pthread_create(&tid[i], 0, thread_func, 0); } for (i = 0; i < thread_count; i++) { pthread_join(tid[i], 0); } rwlock_destroy(&s_rwlock); fprintf(stderr, "Finished.\n"); return 0; }
/** * @brief Free a meta user object. * * @param user a pointer to the meta user object to be destroyed. * * @return This function returns no value. */ void meta_free(meta_user_t *user) { if (user) { prime_cleanup(user->prime.key); prime_cleanup(user->prime.signet); inx_cleanup(user->aliases); inx_cleanup(user->folders); inx_cleanup(user->message_folders); inx_cleanup(user->messages); inx_cleanup(user->contacts); st_cleanup(user->username, user->verification, user->realm.mail); // When read/write locking issues have been fixed, this line can be used once again. rwlock_destroy(&(user->lock)); mutex_destroy(&(user->refs.lock)); mm_free(user); } return; }
void rw_destroy(krwlock_t *rwlp) { (void) rwlock_destroy(&rwlp->rw_lock); rwlp->rw_owner = _KTHREAD_INVALID; }
/* ARGSUSED */ HaMobileNodeEntry * CreateMobileNodeEntry(boolean_t isDynamic, ipaddr_t homeAddr, char *mnNAI, uint32_t mnNaiLen, ipaddr_t homeAgentAddr, uint32_t SPI, char *state, uint32_t poolIdentifier) { HaMobileNodeEntry *entry = NULL; MipSecAssocEntry *saEntry; #ifdef RADIUS_ENABLED time_t currentTime; #endif /* RADIUS_ENABLED */ if (homeAddr == INADDR_ANY && (mnNAI == NULL || mnNaiLen == 0)) { syslog(LOG_ERR, "Home Address OR NAI Must be specified"); return (NULL); } /* * First, let's make sure that we already have * this SPI defined. */ if ((saEntry = findHashTableEntryUint(&mipSecAssocHash, SPI, LOCK_NONE, NULL, 0, 0, 0)) == NULL) { syslog(LOG_ERR, "SPI entry %d not found", SPI); return (NULL); } /* * Let's see if we already have this pool. */ if (poolIdentifier) { if (findHashTableEntryUint(&mipPoolHash, poolIdentifier, LOCK_NONE, NULL, 0, 0, 0) == NULL) { syslog(LOG_CRIT, "Pool entry %d not found.", poolIdentifier); return (NULL); } } /* * If an NAI is provided, make sure that it is legal */ if (mnNAI) { if (mnNaiLen > MAX_NAI_LENGTH) { syslog(LOG_ERR, "Error: Mobile Node NAI too long"); return (NULL); } } entry = (HaMobileNodeEntry *)calloc(1, sizeof (HaMobileNodeEntry)); if (!entry) { syslog(LOG_CRIT, "FATAL: Unable to allocate Mobile Node Entry"); return (NULL); } /* Now add our values */ entry->haMnIsEntryDynamic = isDynamic; entry->haMnAddr = homeAddr; if (homeAgentAddr == 0) { entry->haBindingIfaceAddr = haAddr; } else { entry->haBindingIfaceAddr = homeAgentAddr; } entry->haMnBindingCnt = 0; #ifdef RADIUS_ENABLED GET_TIME(currentTime); entry->haRadiusState = state; entry->haRadiusLastLookupTime = currentTime; #endif /* RADIUS_ENABLED */ entry->haMnSPI = SPI; entry->haPoolIdentifier = poolIdentifier; if (mnNAI) { (void) strncpy((char *)entry->haMnNAI, mnNAI, mnNaiLen); entry->haMnNAI[mnNaiLen] = '\0'; entry->haMnNAILen = mnNaiLen; } HAinitID(&entry->haMnRegIDHigh, &entry->haMnRegIDLow, saEntry->mipSecReplayMethod); if (rwlock_init(&entry->haMnNodeLock, USYNC_THREAD, NULL)) { syslog(LOG_ERR, "Unable to initialize read/write lock"); free(entry); return (NULL); } if (poolIdentifier && mnNaiLen) { /* Add the entry to the NAI hash */ if (linkHashTableEntryString(&haMobileNodeHash, (unsigned char *)entry->haMnNAI, mnNaiLen, entry, LOCK_WRITE)) { syslog(LOG_ERR, "Unable to add Mobile Node entry to " "hash table"); (void) rwlock_destroy(&entry->haMnNodeLock); free(entry); return (NULL); } } else { if (linkHashTableEntryUint(&haMobileNodeHash, entry->haMnAddr, entry, LOCK_WRITE)) { syslog(LOG_ERR, "Unable to add Mobile Node entry to " "hash table"); (void) rwlock_destroy(&entry->haMnNodeLock); free(entry); return (NULL); } } return (entry); }
void vfs_dirent_destroy(struct dirent *dir) { assert(!dir->count); rwlock_destroy(&dir->lock); kfree(dir); }
int mi_close(register MI_INFO *info) { int error=0,flag; MYISAM_SHARE *share=info->s; DBUG_ENTER("mi_close"); DBUG_PRINT("enter",("base: 0x%lx reopen: %u locks: %u", (long) info, (uint) share->reopen, (uint) share->tot_locks)); pthread_mutex_lock(&THR_LOCK_myisam); if (info->lock_type == F_EXTRA_LCK) info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */ if (share->reopen == 1 && share->kfile >= 0) _mi_decrement_open_count(info); if (info->lock_type != F_UNLCK) { if (mi_lock_database(info,F_UNLCK)) error=my_errno; } pthread_mutex_lock(&share->intern_lock); if (share->options & HA_OPTION_READ_ONLY_DATA) { share->r_locks--; share->tot_locks--; } if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED)) { if (end_io_cache(&info->rec_cache)) error=my_errno; info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); } flag= !--share->reopen; myisam_open_list=list_delete(myisam_open_list,&info->open_list); pthread_mutex_unlock(&share->intern_lock); my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR)); if (flag) { if (share->kfile >= 0 && flush_key_blocks(share->key_cache, share->kfile, share->temporary ? FLUSH_IGNORE_CHANGED : FLUSH_RELEASE)) error=my_errno; if (share->kfile >= 0) { /* If we are crashed, we can safely flush the current state as it will not change the crashed state. We can NOT write the state in other cases as other threads may be using the file at this point */ if (share->mode != O_RDONLY && mi_is_crashed(info)) mi_state_info_write(share->kfile, &share->state, 1); if (my_close(share->kfile,MYF(0))) error = my_errno; } #ifdef HAVE_MMAP if (share->file_map) _mi_unmap_file(info); #endif if (share->decode_trees) { my_free((uchar*) share->decode_trees,MYF(0)); my_free((uchar*) share->decode_tables,MYF(0)); } #ifdef THREAD thr_lock_delete(&share->lock); VOID(pthread_mutex_destroy(&share->intern_lock)); { int i,keys; keys = share->state.header.keys; VOID(rwlock_destroy(&share->mmap_lock)); for(i=0; i<keys; i++) { VOID(rwlock_destroy(&share->key_root_lock[i])); } } #endif my_free((uchar*) info->s,MYF(0)); } pthread_mutex_unlock(&THR_LOCK_myisam); if (info->ftparser_param) { my_free((uchar*)info->ftparser_param, MYF(0)); info->ftparser_param= 0; } if (info->dfile >= 0 && my_close(info->dfile,MYF(0))) error = my_errno; myisam_log_command(MI_LOG_CLOSE,info,NULL,0,error); my_free((uchar*) info,MYF(0)); if (error) { DBUG_RETURN(my_errno=error); } DBUG_RETURN(0); } /* mi_close */
int bacstack_session_init(bacstack_session_t *session) { int ret = 1; memset(session, 0, sizeof(*session)); /* this setting sets the range that is used * as the network numbers of directly attached netork. * For example, if this value is set to 1000, then * the network out of port 0 will be assigned * network number 1000. The network out of port * 100 would be assigned network number 1100. This * number must be chosen to not conflict with * existing network numbers on the BACnet network */ session->local_networks_origin = 65535 - 255; if(!rwlock_init(&session->routetable_lock)) { ret = 0; goto done; } if(!bacstack_routetable_init(&session->routetable, 2048)) { ret = 0; goto done; } if(!pool_init(&session->message_pool, BACSTACK_SESSION_MESSAGE_POOL_CAPACITY)) { ret = 0; goto done; } for(int i = 0; i < BACSTACK_SESSION_MESSAGE_POOL_CAPACITY; i++) { bacstack_message_t *message = malloc(sizeof(bacstack_message_t)); if(message == NULL || !bacstack_message_init(message)) { ret = 0; goto done; } if(!pool_release(&session->message_pool, message)) { ret = 0; goto done; } } if(!pool_init(&session->proc_pool, BACSTACK_SESSION_MESSAGE_POOL_CAPACITY)) { ret = 0; goto done; } if(!bacdl_server_init(&session->dl_server, 54321)) { ret = 0; goto done; } if(!thread_init(&session->msg_proc_thread, bacstack_session_msg_proc_thread_handler, session)) { ret = 0; goto done; } if(!thread_init(&session->dl_accept_thread, bacstack_session_dl_accept_thread_handler, session)) { ret = 0; goto done; } if(!thread_init(&session->dl_receive_thread, bacstack_session_dl_receive_thread_handler, session)) { ret = 0; goto done; } done: if(!ret){ rwlock_destroy(&session->routetable_lock); bacstack_routetable_destroy(&session->routetable); pool_destroy(&session->message_pool); pool_destroy(&session->proc_pool); bacdl_server_destroy(&session->dl_server); thread_destroy(&session->msg_proc_thread); thread_destroy(&session->dl_accept_thread); thread_destroy(&session->dl_receive_thread); } return ret; }
/* * Function: CreateSecAssocEntry * * Arguments: SPI - Security Parameter Index * SaType - Whether the entry is dynamic or * static * ReplayProtection - The replay protection * type * AlgorithmType - The authentication algorithm * type * AlgorithmMode - The mode used for the * algorithm. * keyLength - The length of the key * key - A pointer to the key * lifetime - The lifetime of the entry (for * dynamic entries only) * * Description: This function will create a Security Association * entry, and will add it to the hash table. If the * SPI already exists, we will return an error. * * If the node is created as a dynamic entry, * we will setup the entry's expiration time. * * Also, if the SA is dynamic and a duplicate SA * is received, it is updated, and no error is * returned. (if the SA is *not* dynamic, an * error *is* returned.) * * The entry will be locked upon return. * The caller is responsible for unlocking the * node when it is finished with it. * * Returns: upon successful return, this function will * return the Security Association Entry * pointer, otherwise NULL. */ MipSecAssocEntry * CreateSecAssocEntry(boolean_t isDynamic, uint32_t SPI, int ReplayProtection, int AlgorithmType, int AlgorithmMode, int keyLength, char *key, int lifetime) { MipSecAssocEntry *entry = NULL; time_t currentTime; boolean_t alreadyInserted = _B_FALSE; /* * First, let's make sure that we do not already have * this SPI defined. */ if ((entry = findHashTableEntryUint(&mipSecAssocHash, SPI, LOCK_WRITE, NULL, 0, 0, 0)) != NULL) { if (isDynamic == _B_FALSE) { syslog(LOG_ERR, "Duplicate SPI entry requested %d", SPI); (void) rw_unlock(&entry->mipSecNodeLock); return (NULL); } else { alreadyInserted = _B_TRUE; (void) fprintf(stderr, "Updating SPI %d\n", SPI); } } /* Entry is set if dynamic and already found */ if (!entry) { entry = (MipSecAssocEntry *)calloc(1, sizeof (MipSecAssocEntry)); if (!entry) { syslog(LOG_CRIT, "FATAL: Unable to allocate Sec Assoc Entry"); return (NULL); } } entry->mipSecSPI = SPI; entry->mipSecReplayMethod = ReplayProtection; entry->mipSecAlgorithmType = AlgorithmType; entry->mipSecAlgorithmMode = AlgorithmMode; entry->mipSecKeyLen = keyLength; entry->mipSecIsEntryDynamic = isDynamic; if (isDynamic) { /* * Setup when the key expires... */ GET_TIME(currentTime); entry->mipSecKeyLifetime = currentTime + lifetime; } else { entry->mipSecKeyLifetime = TIME_INFINITY; } (void) memcpy(entry->mipSecKey, key, keyLength); /* If it is already in table, we already own it with the RWLOCK set */ if (!alreadyInserted) { if (rwlock_init(&entry->mipSecNodeLock, USYNC_THREAD, NULL)) { syslog(LOG_ERR, "Unable to initialize " "read/write lock"); free(entry); return (NULL); } if (linkHashTableEntryUint(&mipSecAssocHash, SPI, entry, LOCK_WRITE)) { syslog(LOG_ERR, "Unable to add Security " "Assoc. entry to hash tabl"); (void) rwlock_destroy(&entry->mipSecNodeLock); free(entry); return (NULL); } } return (entry); }
/* static void writerthread(void *junk, unsigned long num) { (void)junk; rwlock_acquire_write(testrwlock); random_yielder(4); testval1++; kprintf_n("Thread %lu: Writer val:%lu\n", num, testval1); random_yielder(4); rwlock_release_write(testrwlock); V(donesem); return; }*/ int rwtest(int nargs, char **args) { (void)nargs; (void)args; int i, result; kprintf_n("Starting rwt1...\n"); for (i=0; i<CREATELOOPS; i++) { kprintf_t("."); testrwlock = rwlock_create("testreaderwriterlock"); if (testrwlock == NULL) { panic("rwt1: rwlock_create failed\n"); } donesem = sem_create("donesem", 0); if (donesem == NULL) { panic("rtw1: sem_create failed\n"); } if(i != CREATELOOPS -1) { rwlock_destroy(testrwlock); sem_destroy(donesem); } } spinlock_init(&status_lock); test_status = TEST161_SUCCESS; testval1 = 0; // create threads code for (i=0; i<NUMREADERS1; i++) { kprintf_t("."); result = thread_fork("rwlockstest", NULL, readerthread, NULL, i); if(result) { panic("rwt1: thread_fork failed: %s\n", strerror(result)); } } /* for (i=0; i<NUMWRITERS1; i++) { kprintf_t("."); result = thread_fork("rwlockstest", NULL, writerthread, NULL, i); if(result) { panic("rwt1: thread_fork failed: %s\n", strerror(result)); } */ kprintf("%d\n", i); int numthreads = NUMREADERS1; for(i=0; i<numthreads; i++) { kprintf_t("."); P(donesem); } rwlock_destroy(testrwlock); sem_destroy(donesem); testrwlock = NULL; donesem = NULL; kprintf_n("\n"); kprintf_n("\n"); success(TEST161_FAIL, SECRET, "rwt1"); return 0; }
static void rc_rwlock_destroy(WT_RESOURCE *rc) { rwlock_destroy(&rc->lock); }
/* * Function: CreateInterfaceEntry * * Arguments: dev - A pointer to the device name * regLifetime - The maximum registration lifetime that * are willing to accept. * advertiseOnBcast - Whether we will advertise on the * broadcast address. * minInterval - The minimum interval between adv. * maxInterval - The maximum interval between adv. * advLifetime - The maximum advertisement lifetime * lifetime that we will advertise on this * interface. * advSeqNum - The sequence number that we will * initially advertise. * servicesFlags - The flags that we will advertise * on the interface. * prefixFlags - determines whether we will advertise * the prefix length extension. * reverseTunnelAllowed - are we going to allow MN's to * request the reverse tunnel, and thereby send * FA_REVERSE_TUNNEL_UNAVAILABLE errors to MN's * requesting a reverse tunnel? Note, this is set to * RT_NONE, RT_FA, RT_HA, or RT_BOTH depending on which * of our agents is allowing the reverse tunnel. * reverseTunnelRequired - are we going to require MN's to * request the reverse tunnel, and thereby send * FA_REVERSE_TUNNEL_REQUIRED errors to MN's not * requesting a reverse tunnel? Note, this is set to * RT_NONE, RT_FA, RT_HA, or RT_BOTH depending on which * of our agents is requiring the reverse tunnel. * advInterval - Advertisement interval for this interface * * Description: This function will create an interface entry, * and will add it to the hash table. We will * directly retrieve the interface's IP address and * MAC address. * * Returns: int, 0 if successful. * * Comment: This function takes too many arguments. If this function * ever needs a major change, passing a structure with all * arguments should be considered. * */ int CreateInterfaceEntry(char *dev, int regLifetime, boolean_t advertiseOnBcast, int minInterval, int maxInterval, int advLifetime, uint16_t advSeqNum, int servicesFlags, boolean_t prefixFlags, uint8_t reverseTunnelAllowed, uint8_t reverseTunnelRequired, boolean_t advLimitUnsolicited, uint8_t advInitCount, uint32_t advInterval, boolean_t isDynamic) { MaAdvConfigEntry *entry; char *cp; /* If a virtual network interface is specified, warn the user */ if (dev != NULL) { if ((strncmp(dev, VNI, VNISTRLEN) == 0)) { cp = dev + VNISTRLEN; cp += strspn(cp, "0123456789"); if (*cp == '\0' || *cp == ':' || *cp == '*') syslog(LOG_WARNING, "%s specified. vni is a" " virtual interface that does not transmit" " or receive packets. See vni(7D)", dev); } } /* Let's check for dynamic interface entry */ if (strchr(dev, '*') == NULL) { entry = (MaAdvConfigEntry *) calloc(1, sizeof (MaAdvConfigEntry)); if (entry == NULL) { syslog(LOG_CRIT, "FATAL: Unable to allocate " "AdvConfigEntry"); return (-2); } } else { int len; DynamicIfaceTypeEntry *dyn_entry; DynamicIfaceTypeEntry *save_entry; /* * Since devicename contains '*', it must be an entry * for dynamic interface.For dynamic interface entry * in the config file, we do not create entry in the * MaAdvConfigEntry[], rather we keep a linked list * of dynamic interface types. For each type of dynamic * interface entry, the attributes will be common and * saved in DynamicIfaceTypeEntry data structure. * When mipagent detects one new interface that matches * with the same type and that is not an exisisting one * that went through down-up cycle, then it creates a new * entry and attaches to the MaAdvConfigEntry list */ len = strlen(dev); if (len > 0 && dev[len - 1] != '*') { syslog(LOG_ERR, "Invalid dynamic interface %s in mipagent.conf", dev); return (-1); } /* Replace '*' with null character */ dev[len -1] = '\0'; mipverbose(("CreateInterfaceEntry: dynamic device %s\n", dev)); if (dynamicIfaceHead == NULL) { dynamicIfaceHead = (DynamicIfaceTypeEntry *) calloc(1, sizeof (DynamicIfaceTypeEntry)); dyn_entry = dynamicIfaceHead; } else { /* search if this type exists already */ dyn_entry = dynamicIfaceHead; while (dyn_entry != NULL) { if (strcmp(dyn_entry->dynamicIfcetype, dev) == 0) { mipverbose(("CreateInterfaceEntry:" " Dynamic Entry already exists" " %s\n", dev)); return (0); } save_entry = dyn_entry; dyn_entry = dyn_entry->next; } dyn_entry = (DynamicIfaceTypeEntry *) calloc(1, sizeof (DynamicIfaceTypeEntry)); if (dyn_entry != NULL) { /* Link to the dynamicEntry list */ save_entry->next = dyn_entry; } } /* Fill in the structure with the parameter values */ (void) strncpy(dyn_entry->dynamicIfcetype, dev, LIFNAMSIZ); dyn_entry->AdvLimitUnsolicited = advLimitUnsolicited; dyn_entry->AdvInitCount = advInitCount; dyn_entry->AdvInterval = advInterval; dyn_entry->AdvServiceflag = servicesFlags; dyn_entry->AdvPrefixflag = prefixFlags; dyn_entry->RevtunReqd = reverseTunnelRequired; dyn_entry->RevtunAllowed = reverseTunnelAllowed; dyn_entry->RegLifetime = regLifetime; dyn_entry->AdvLifetime = advLifetime; dyn_entry->advertiseOnBcast = advertiseOnBcast; dyn_entry->next = NULL; /* Set the global variable DynamicInterface */ DynamicInterface = _B_TRUE; return (0); } /* else dynamic entry */ /* Now add our interface values */ (void) strncpy(entry->maIfaceName, dev, (LIFNAMSIZ -1)); /* * Simplify the configuration effort, read IP address, netmask * and hardware address directly from the interface. */ if (getIfaceInfo(entry->maIfaceName, &entry->maIfaceAddr, &entry->maIfaceNetmask, &entry->maIfaceFlags, &entry->maIfindex)) { free(entry); syslog(LOG_ERR, "Unable to get interface information: %m"); return (-1); } /* * Save the first address usable for registering with the * SNMP master. */ if (subagent_addr != 0) subagent_addr = entry->maIfaceAddr; /* * Don't attempt to get the hardware address if it's a point-to-point * interface. */ if ((entry->maIfaceFlags & IFF_POINTOPOINT) == 0) { if (getEthernetAddr(entry->maIfaceName, entry->maIfaceHWaddr)) { syslog(LOG_ERR, "Unable to get interface address " "information on %s (%s)", dev, strerror(errno)); mipverbose(("Unable to get interface address " "information on %s (%s)\n", dev, strerror(errno))); free(entry); return (-1); } } entry->maAdvMaxRegLifetime = regLifetime; /* * TODO: Under Solaris, pkts for LINK_BCAST_ADDR seem to * be sent on all of a host's interfaces. Don't know if this * can be controlled using some options similar to * IP_MULTICAST_IF. */ if (advertiseOnBcast == 1) { entry->maAdvAddr = inet_addr(LINK_BCAST_ADDR); } else { entry->maAdvAddr = inet_addr(LINK_MCAST_ADV_ADDR); } entry->maAdvMaxInterval = maxInterval; entry->maAdvMinInterval = minInterval; entry->maAdvMaxAdvLifetime = advLifetime; entry->maAdvSeqNum = advSeqNum; entry->maAdvServiceFlags = (char)servicesFlags; entry->maAdvPrefixLenInclusion = prefixFlags; entry->maReverseTunnelAllowed = reverseTunnelAllowed; entry->maReverseTunnelRequired = reverseTunnelRequired; entry->maAdvLimitUnsolicited = advLimitUnsolicited; if (advLimitUnsolicited == _B_FALSE) entry->maAdvInitCount = 1; else entry->maAdvInitCount = advInitCount; entry->maAdvInterval = advInterval; /* Set maNextAdvTime in getAndDispatchNetwork */ entry->maNextAdvTime = LONG_MAX; /* The follwoing is always set false in this routine */ entry->maAdvDynamicInterface = isDynamic; if (rwlock_init(&entry->maIfaceNodeLock, USYNC_THREAD, NULL)) { syslog(LOG_ERR, "Unable to initialize read/write lock"); free(entry); return (NULL); } /* * Ok, this is just a temp hack, but we need to save the * local address of the interface. Otherwise we will need to * configure the home agent for each Mobile Node, which is * just too much config for everybody. Given that we really * only work with one interface, this is not a big deal, but * this DOES need to be cleaned up. */ haAddr = entry->maIfaceAddr; /* * We do not request that the node be locked in this case since * we do not need the pointer to be returned. We are just calling * and ensuring that a pointer was in fact returned. */ if (linkHashTableEntryUint(&maAdvConfigHash, entry->maIfaceAddr, entry, LOCK_NONE)) { syslog(LOG_ERR, "Unable to add interface entry to hash table"); (void) rwlock_destroy(&entry->maIfaceNodeLock); free(entry); return (-1); } return (0); }