Exemplo n.º 1
0
static
VOID
SrvTree2Free(
    PLWIO_SRV_TREE_2 pTree
    )
{
    LWIO_LOG_DEBUG("Freeing tree [object:0x%x][tid:%u]",
                    pTree,
                    pTree->ulTid);

    // Cannot be in the parent since parent would have a reference.
    LWIO_ASSERT(!SrvTree2IsInParent_inlock(pTree));

    if (pTree->pMutex)
    {
        pthread_rwlock_destroy(&pTree->mutex);
        pTree->pMutex = NULL;
    }

    if (pTree->pFileCollection)
    {
        LwRtlRBTreeFree(pTree->pFileCollection);
    }

    if (pTree->hFile)
    {
        IoCloseFile(pTree->hFile);
    }

    if (pTree->pShareInfo)
    {
        SrvShareReleaseInfo(pTree->pShareInfo);
    }

    if (pTree->resource.ulResourceId)
    {
        PSRV_RESOURCE pResource = NULL;

        SrvElementsUnregisterResource(pTree->resource.ulResourceId,
                                      &pResource);
        pTree->resource.ulResourceId = 0;
    }

    // Release parent at the end
    if (pTree->pSession)
    {
        SrvSession2Release(pTree->pSession);
    }

    SrvFreeMemory(pTree);
}
Exemplo n.º 2
0
Arquivo: 2-1.c Projeto: 1587/ltp
int main(void)
{
	int cnt = 0;
	int rc = 0;

	pthread_t thread;

	rc = pthread_rwlock_init(&rwlock, NULL);
	if (rc != 0) {
		printf
		    ("Test FAILED: Error at pthread_rwlock_init(), returns %d\n",
		     rc);
		return PTS_FAIL;
	}

	thread_state = 1;
	printf("main: create thread\n");
	if (pthread_create(&thread, NULL, fn_rd, NULL) != 0) {
		printf("main: failed to create thread\n");
		return PTS_UNRESOLVED;
	}

	/* If the shared data is not altered by child after 3 seconds,
	   we regard it as blocked */
	/* We expect the thread not to block */
	cnt = 0;
	do {
		sleep(1);
	} while (thread_state != 3 && cnt++ < 3);

	if (thread_state == 2) {
		printf("Test FAILED: thread blocked on read lock\n");
		exit(PTS_FAIL);
	} else if (thread_state != 3) {
		printf("main: Unexpected thread state\n");
		exit(PTS_UNRESOLVED);
	}

	if (pthread_join(thread, NULL) != 0) {
		printf("main: Error at pthread_join()\n");
		exit(PTS_UNRESOLVED);
	}

	if (pthread_rwlock_destroy(&rwlock) != 0) {
		printf("Error at pthread_rwlock_destroy()\n");
		return PTS_UNRESOLVED;
	}

	printf("Test PASSED\n");
	return PTS_PASS;
}
Exemplo n.º 3
0
void
mas_threads_destroy( void )
{
  CTRL_PREPARE;

  pthread_attr_destroy( &ctrl.thglob.custom_attr );

  pthread_attr_destroy( &ctrl.thglob.logger_attr );
  pthread_cond_destroy( &ctrl.thglob.logger_wait_cond );
  pthread_mutex_destroy( &ctrl.thglob.logger_wait_mutex );

  pthread_attr_destroy( &ctrl.thglob.master_attr );
  pthread_attr_destroy( &ctrl.thglob.ticker_attr );
  pthread_attr_destroy( &ctrl.thglob.watcher_attr );
  CPU_FREE( ctrl.thglob.master_set );
  ctrl.thglob.master_set = NULL;

  pthread_attr_destroy( &ctrl.thglob.listener_attr );
  CPU_FREE( ctrl.thglob.listener_set );
  ctrl.thglob.listener_set = NULL;

  pthread_attr_destroy( &ctrl.thglob.transaction_attr );
  CPU_FREE( ctrl.thglob.transaction_set );
  ctrl.thglob.transaction_set = NULL;

  pthread_rwlock_destroy( &ctrl.thglob.modules_list_rwlock );
  pthread_rwlock_destroy( &ctrl.thglob.lcontrols_list_rwlock );
  pthread_rwlock_destroy( &ctrl.thglob.control_rwlock );

  pthread_mutex_destroy( &ctrl.thglob.mfp_mutex );
  pthread_mutex_destroy( &ctrl.thglob.msg_mutex );
  pthread_mutex_destroy( &ctrl.thglob.emsg_mutex );
  pthread_mutex_destroy( &ctrl.thglob.cleanup_transactions_mutex );
  pthread_mutex_destroy( &ctrl.thglob.malloc_mutex );
  pthread_mutex_destroy( &ctrl.thglob.cnttr1_mutex );
  pthread_mutex_destroy( &ctrl.thglob.cnttr2_mutex );
//pthread_mutex_destroy( &ctrl.thglob.log_mutex );
}
Exemplo n.º 4
0
	void DownSpeed::Clear()
	{
#ifdef CszTest
        Csz::LI("[%s->%s->%d]",__FILE__,__func__,__LINE__);
#endif
		auto code= bthread_timer_del(id);
		if (code!= 0)
		{
			Csz::ErrMsg("[%s->%s->%d]->failed,calculate speed still running or einval,code=%d",__FILE__,__func__,__LINE__,code);
		}
		pthread_rwlock_destroy(&lock);
		queue.clear();
		return ;
	}
Exemplo n.º 5
0
void
sharddir_delete(struct sharddir **sharddp)
{
	struct sharddir *shardd;

	AN(sharddp);
	shardd = *sharddp;
	*sharddp = NULL;

	CHECK_OBJ_NOTNULL(shardd, SHARDDIR_MAGIC);
	shardcfg_delete(shardd);
	AZ(pthread_rwlock_destroy(&shardd->mtx));
	FREE_OBJ(shardd);
}
Exemplo n.º 6
0
NTSTATUS
NpfsFreeFCB(
    PNPFS_FCB pFCB
    )
{
    NTSTATUS ntStatus = 0;

    pthread_rwlock_destroy(&pFCB->PipeListRWLock);
    LwRtlUnicodeStringFree(&pFCB->PipeName);

    NpfsFreeMemory(pFCB);

    return(ntStatus);
}
Exemplo n.º 7
0
static apr_status_t thread_rwlock_cleanup(void *data)
{
    apr_thread_rwlock_t *rwlock = (apr_thread_rwlock_t *)data;
    apr_status_t stat;

    pthread_rwlock_unlock(rwlock->rwlock);
    stat = pthread_rwlock_destroy(rwlock->rwlock);
#ifdef PTHREAD_SETS_ERRNO
    if (stat) {
        stat = errno;
    }
#endif
    return stat;
} 
Exemplo n.º 8
0
void delete_list(c_list *list) {
	if(list) {
		c_node *tmp = list->head;
		while(tmp) {
			c_node *tmp2 = tmp;
			tmp = tmp2->next;
			delete_node(tmp2);
		}
		
		pthread_rwlock_destroy((list->lock));
		free(list->lock);
		free(list);
	}
}
Exemplo n.º 9
0
/* clean up upon library unload */
void __attribute ((destructor)) memhack_exit (void)
{
	u32 i;
#if USE_DEBUG_LOG
	if (DBG_FILE_VAR) {
		fflush(DBG_FILE_VAR);
		fclose(DBG_FILE_VAR);
	}
#endif
	if (!active || !config)
		return;
	for (i = 0; config[i] != NULL; i++)
		pthread_rwlock_destroy(&config[i]->lock);
}
Exemplo n.º 10
0
void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock)
{
    if (lock == NULL)
        return;

# ifdef USE_RWLOCK
    pthread_rwlock_destroy(lock);
# else
    pthread_mutex_destroy(lock);
# endif
    OPENSSL_free(lock);

    return;
}
Exemplo n.º 11
0
void
vdir_delete(struct vdir **vdp)
{
	struct vdir *vd;

	TAKE_OBJ_NOTNULL(vd, vdp, VDIR_MAGIC);

	AZ(vd->dir);
	free(vd->backend);
	free(vd->weight);
	AZ(pthread_rwlock_destroy(&vd->mtx));
	vbit_destroy(vd->healthy);
	FREE_OBJ(vd);
}
Exemplo n.º 12
0
static void
lookupRefDestruct(lookup_ref_t *pThis)
{
	lookupStopReloader(pThis);
	pthread_mutex_destroy(&pThis->reloader_mut);
	pthread_cond_destroy(&pThis->run_reloader);
	pthread_attr_destroy(&pThis->reloader_thd_attr);

	pthread_rwlock_destroy(&pThis->rwlock);
	lookupDestruct(pThis->self);
	free(pThis->name);
	free(pThis->filename);
	free(pThis);
}
Exemplo n.º 13
0
void thread_list_free(struct thread_list_t *list)
{
	struct thread_list_node_t *prev = NULL;

	pthread_rwlock_destroy(&list->lock);
	
	while (list->head)
	{
		prev = list->head;
		list->head = list->head->next;
		free(prev);
	}
	free(list);	
}
Exemplo n.º 14
0
/**
 * Free resources used to hold information about the tree. This
 * function does not free memory pointed to by the data pointer
 * in a node - you have to free this memory by walking thru the
 * tree or use the callback version of rbt_free for a specific
 * tree type.
 * @param rbt tree pointer
 */
void rbt_free(rbt_t *rbt, void (*callback)(void *))
{
        struct rbt_node *stack[48], *n;
        register uint8_t depth;

        rbt_wlock(rbt);

        depth = 0;
        n = rbt_node_ptr(rbt->root);

        if (n != NULL) {
                rbt_walk_push(n);

                while(depth > 0) {
                        n = rbt_node_ptr(rbt_walk_top()->_chld[RBT_NODE_SL]);

                        if (n != NULL)
                                rbt_walk_push(n);
                        else {
                        __in:
                                if (callback != NULL)
                                        callback((void *)&(rbt_walk_top()->_node));

                                n = rbt_node_ptr(rbt_walk_top()->_chld[RBT_NODE_SR]);
                                free(rbt_walk_top());

                                if (n != NULL)
                                        rbt_walk_top() = n;
                                else {
                                        if (--depth > 0)
                                                goto __in;
                                        else
                                                break;
                                }
                        }
                }
        }
        rbt_wunlock(rbt);

        rbt->root = NULL;
        rbt->size = 0;
        rbt->type = -1;

#if defined(RBT_IMPLICIT_LOCKING)
        pthread_rwlock_destroy (&rbt->lock);
#endif
        free (rbt);
        return;
}
Exemplo n.º 15
0
TEST(pthread, pthread_rwlock_smoke) {
  pthread_rwlock_t l;
  ASSERT_EQ(0, pthread_rwlock_init(&l, NULL));

  // Single read lock
  ASSERT_EQ(0, pthread_rwlock_rdlock(&l));
  ASSERT_EQ(0, pthread_rwlock_unlock(&l));

  // Multiple read lock
  ASSERT_EQ(0, pthread_rwlock_rdlock(&l));
  ASSERT_EQ(0, pthread_rwlock_rdlock(&l));
  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
  ASSERT_EQ(0, pthread_rwlock_unlock(&l));

  // Write lock
  ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
  ASSERT_EQ(0, pthread_rwlock_unlock(&l));

  // Try writer lock
  ASSERT_EQ(0, pthread_rwlock_trywrlock(&l));
  ASSERT_EQ(EBUSY, pthread_rwlock_trywrlock(&l));
  ASSERT_EQ(EBUSY, pthread_rwlock_tryrdlock(&l));
  ASSERT_EQ(0, pthread_rwlock_unlock(&l));

  // Try reader lock
  ASSERT_EQ(0, pthread_rwlock_tryrdlock(&l));
  ASSERT_EQ(0, pthread_rwlock_tryrdlock(&l));
  ASSERT_EQ(EBUSY, pthread_rwlock_trywrlock(&l));
  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
  ASSERT_EQ(0, pthread_rwlock_unlock(&l));

  // Try writer lock after unlock
  ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
  ASSERT_EQ(0, pthread_rwlock_unlock(&l));

#ifdef __BIONIC__
  // EDEADLK in "read after write"
  ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
  ASSERT_EQ(EDEADLK, pthread_rwlock_rdlock(&l));
  ASSERT_EQ(0, pthread_rwlock_unlock(&l));

  // EDEADLK in "write after write"
  ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
  ASSERT_EQ(EDEADLK, pthread_rwlock_wrlock(&l));
  ASSERT_EQ(0, pthread_rwlock_unlock(&l));
#endif

  ASSERT_EQ(0, pthread_rwlock_destroy(&l));
}
Exemplo n.º 16
0
dcol::~dcol()
{
	myLogger.lw(INFO,"DESTRUCTOR: Cleaning up.");
	
	// Destroy timer RW mutex:
	pthread_rwlock_destroy(&timerLock);
	
	// Deallocate Memory:
	if (dataThread != NULL)
	{
		delete [] dataThread;
		dataThread = NULL;
	}
	/*
	if (paramThread != NULL)
	{
		delete [] paramThread;
		paramThread = NULL;
	}
	*/
	if (dataGood != NULL)
	{
		delete [] dataGood;
		dataGood = NULL;
	}
	/*
	if (paramGood != NULL)
	{
		delete [] paramGood;
		paramGood = NULL;
	}
	*/
	if (dcolTask != NULL)
	{
		delete [] dcolTask;
		dcolTask = NULL;
	}
	
	/*
	if (pcolTask != NULL)
	{
		delete [] pcolTask;
		pcolTask = NULL;
	}
	*/
	
	myLogger.lw(INFO,"DESTRUCTOR: DCOL TERMINATED.");
	myLogger.close();
}
Exemplo n.º 17
0
void sampler_free(sampler s)
{
	size_t i;

	if(s != NULL) {
		pthread_rwlock_destroy(&s->lock);
		mem_free(s->times);

		for(i = 0; i < s->nentity; i++) 
			mem_free(s->entities[i].data);

		mem_free(s->entities);
		mem_free(s);
	}
}
Exemplo n.º 18
0
// free a directory handle
static void fskit_dir_handle_destroy( struct fskit_dir_handle* dirh ) {

   dirh->dent = NULL;

   if( dirh->path != NULL ) {
      fskit_safe_free( dirh->path );
      dirh->path = NULL;
   }

   pthread_rwlock_destroy( &dirh->lock );

   memset( dirh, 0, sizeof(struct fskit_dir_handle) );

   fskit_safe_free( dirh );
}
Exemplo n.º 19
0
int list_destroy(struct list *list) {

    int ret;
    
    assert(list->root == NULL);

    ret = pthread_rwlock_destroy(list->listrwlock);
    assert(ret == 0);
    free(list->listrwlock);
    list->listrwlock = NULL;

    list->root = NULL;

    return 0;
}
Exemplo n.º 20
0
void
kore_task_destroy(struct kore_task *t)
{
	kore_debug("kore_task_destroy: %p", t);

	if (t->req != NULL) {
		t->req = NULL;
		LIST_REMOVE(t, rlist);
	}

	close(t->fds[0]);
	close(t->fds[1]);		/* This might already be closed. */

	pthread_rwlock_destroy(&(t->lock));
}
Exemplo n.º 21
0
int mutex_done(void)
{
  unsigned int i;

  for(i=0; i < mutex_num; i++)
  {
    if (mutex_type == SB_MUTEX || mutex_type == SB_MUTEX_ADAPTIVE)
      pthread_mutex_destroy(&thread_locks[i].mutex);
    else
      pthread_rwlock_destroy(&thread_locks[i].rwlock);
  }
  free(thread_locks);
  
  return 0;
}
Exemplo n.º 22
0
void dt_control_cleanup(dt_control_t *s)
{
  // vacuum TODO: optional?
  // DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "PRAGMA incremental_vacuum(0)", NULL, NULL, NULL);
  // DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "vacuum", NULL, NULL, NULL);
  dt_pthread_mutex_destroy(&s->queue_mutex);
  dt_pthread_mutex_destroy(&s->cond_mutex);
  dt_pthread_mutex_destroy(&s->log_mutex);
  dt_pthread_mutex_destroy(&s->run_mutex);
  pthread_rwlock_destroy(&s->xprofile_lock);
  if (s->accelerator_list)
  {
    g_slist_free_full(s->accelerator_list, g_free);
  }
}
Exemplo n.º 23
0
void
cb_seeds_free(struct cb_seeds *seeds) {
    int32_t errno;
    int32_t i;

    if (0 != (errno = pthread_rwlock_destroy(&seeds->lock))) {
        fprintf(stderr, "Could not destroy rwlock. Errno: %d\n", errno);
        exit(1);
    }
    for (i = 0; i < seeds->locs_length; i++)
        cb_seed_loc_free(seeds->locs[i]); /* frees the whole list */
    free(seeds->locs);
    free(seeds->powers);
    free(seeds);
}
Exemplo n.º 24
0
int
main()
{
  assert(rwlock == NULL);

  assert(pthread_rwlock_init(&rwlock, NULL) == 0);

  assert(rwlock != NULL);

  assert(pthread_rwlock_destroy(&rwlock) == 0);

  assert(rwlock == NULL);

  return 0;
}
Exemplo n.º 25
0
static int
do_test (void)
{
  size_t cnt;
  for (cnt = 0; cnt < sizeof (kind) / sizeof (kind[0]); ++cnt)
    {
      pthread_rwlock_t r;
      pthread_rwlockattr_t a;

      if (pthread_rwlockattr_init (&a) != 0)
        FAIL_EXIT1 ("round %Zu: rwlockattr_t failed\n", cnt);

      if (pthread_rwlockattr_setkind_np (&a, kind[cnt]) != 0)
        FAIL_EXIT1 ("round %Zu: rwlockattr_setkind failed\n", cnt);

      if (pthread_rwlock_init (&r, &a) != 0)
        FAIL_EXIT1 ("round %Zu: rwlock_init failed\n", cnt);

      if (pthread_rwlockattr_destroy (&a) != 0)
        FAIL_EXIT1 ("round %Zu: rwlockattr_destroy failed\n", cnt);

      struct timespec ts;
      xclock_gettime (CLOCK_REALTIME, &ts);

      ++ts.tv_sec;

      /* Get a read lock.  */
      if (pthread_rwlock_timedrdlock (&r, &ts) != 0)
        FAIL_EXIT1 ("round %Zu: rwlock_timedrdlock failed\n", cnt);

      printf ("%zu: got timedrdlock\n", cnt);

      pthread_t th;
      if (pthread_create (&th, NULL, tf, &r) != 0)
        FAIL_EXIT1 ("round %Zu: create failed\n", cnt);

      void *status;
      if (pthread_join (th, &status) != 0)
        FAIL_EXIT1 ("round %Zu: join failed\n", cnt);
      if (status != NULL)
        FAIL_EXIT1 ("failure in round %Zu\n", cnt);

      if (pthread_rwlock_destroy (&r) != 0)
        FAIL_EXIT1 ("round %Zu: rwlock_destroy failed\n", cnt);
    }

  return 0;
}
Exemplo n.º 26
0
/* create a new lookup table object AND include it in our list of
 * lookup tables.
 */
static rsRetVal
lookupNew(lookup_ref_t **ppThis)
{
	lookup_ref_t *pThis = NULL;
	lookup_t *t = NULL;
	int initialized = 0;
	DEFiRet;

	CHKmalloc(pThis = calloc(1, sizeof(lookup_ref_t)));
	CHKmalloc(t = calloc(1, sizeof(lookup_t)));
	CHKiConcCtrl(pthread_rwlock_init(&pThis->rwlock, NULL));
	initialized++; /*1*/
	CHKiConcCtrl(pthread_mutex_init(&pThis->reloader_mut, NULL));
	initialized++; /*2*/
	CHKiConcCtrl(pthread_cond_init(&pThis->run_reloader, NULL));
	initialized++; /*3*/
	CHKiConcCtrl(pthread_attr_init(&pThis->reloader_thd_attr));
	initialized++; /*4*/
	pThis->do_reload = pThis->do_stop = 0;
	pThis->reload_on_hup = 1; /*DO reload on HUP (default)*/
	CHKiConcCtrl(pthread_create(&pThis->reloader, &pThis->reloader_thd_attr, lookupTableReloader, pThis));
	initialized++; /*5*/

	pThis->next = NULL;
	if(loadConf->lu_tabs.root == NULL) {
		loadConf->lu_tabs.root = pThis;
	} else {
		loadConf->lu_tabs.last->next = pThis;
	}
	loadConf->lu_tabs.last = pThis;

	pThis->self = t;

	*ppThis = pThis;
finalize_it:
	if(iRet != RS_RET_OK) {
		errmsg.LogError(errno, iRet, "a lookup table could not be initialized: failed at init-step %d "
		"(please enable debug logs for details)", initialized);
		if (initialized > 4) lookupStopReloader(pThis);
		if (initialized > 3) pthread_attr_destroy(&pThis->reloader_thd_attr);
		if (initialized > 2) pthread_cond_destroy(&pThis->run_reloader);
		if (initialized > 1) pthread_mutex_destroy(&pThis->reloader_mut);
		if (initialized > 0) pthread_rwlock_destroy(&pThis->rwlock);
		free(t);
		free(pThis);
	}
	RETiRet;
}
Exemplo n.º 27
0
void free_hash()
{
	for (unsigned int i = 0; i < MAX_HASH; ++i)
	{
		hashnode_t *temp = hashTable[i]->h_next;
		hashnode_t *todel;
		while (temp != NULL)
		{
			todel = temp;
			temp = temp->h_next;
			freeResource(todel);
		}
		pthread_rwlock_destroy(&hashTable[i]->m_rwlock);
		freeResource(hashTable[i]);
	}
}
Exemplo n.º 28
0
static void
RdkHandle_dealloc(PyObject *self, PyObject *(*stop_func) (RdkHandle *))
{
    PyObject *stop_result = stop_func((RdkHandle *)self);
    if (!stop_result) {
        /* We'll swallow the exception, so let's try to log info first */
        PyObject *res = PyObject_CallMethod(
                logger, "exception", "s", "In dealloc: stop() failed.");
        PyErr_Clear();
        Py_XDECREF(res);
    } else {
        Py_DECREF(stop_result);
    }
    pthread_rwlock_destroy(&((RdkHandle *)self)->rwlock);
    self->ob_type->tp_free(self);
}
Exemplo n.º 29
0
/**
 * Destroy session.
 * @param[in] sess
 */
void session_destroy(struct zsession *sess)
{
    // update counters
    __atomic_sub_fetch(&zinst()->sessions_cnt, 1, __ATOMIC_RELAXED);
    if (0 == sess->client->id) {
        __atomic_sub_fetch(&zinst()->unauth_sessions_cnt, 1, __ATOMIC_RELAXED);
    }

    pthread_rwlock_destroy(&sess->lock_client);
    client_session_remove(sess->client, sess);
    client_release(sess->client);

    if(sess->nat) znat_destroy(sess->nat);

    free(sess);
}
Exemplo n.º 30
0
NTSTATUS
SvcmStop(
    PLW_SVCM_INSTANCE pInstance
)
{
    UMN_LOG_VERBOSE("Shutting down threads");

    UmnSrvStopPollerThread();

    UmnSrvFreeConfig(gpAPIConfig);
    LW_ASSERT(pthread_rwlock_destroy(&gUmnConfigLock) == 0);

    UMN_LOG_INFO("Usermonitor Service exiting...");

    return 0;
}