Ejemplo n.º 1
0
/**
 * Delete a session and its associated queues.
 * @param   ses         session
 */
static void unvme_session_delete(unvme_session_t* ses)
{
    if (ses->id > 0) {
        pthread_spin_lock(&ses->iomem.lock);
        if (ses->iomem.size) {
            int i;
            for (i = 0; i < ses->iomem.count; i++) {
                (void) vfio_dma_free(ses->iomem.map[i]);
            }
            ses->iomem.size = ses->iomem.count = 0;
            free(ses->iomem.map);
        }
        pthread_spin_unlock(&ses->iomem.lock);
        pthread_spin_destroy(&ses->iomem.lock);
    }

    if (ses == ses->next) {
        DEBUG_FN("%x: adminq", unvme_dev.vfiodev->pci);
        unvme_adminq_delete(ses->queues);
    } else {
        DEBUG_FN("%x: q=%d-%d", unvme_dev.vfiodev->pci, ses->id,
                                ses->id + ses->qcount -1);
        while (--ses->qcount >= 0) {
            unvme_queue_t* ioq = &ses->queues[ses->qcount];
            if (ioq->ses) unvme_ioq_delete(ioq);
        }
    }
    LIST_DEL(unvme_dev.ses, ses);
    free(ses);
}
Ejemplo n.º 2
0
void cleanup_context(struct tur_checker_context *ct)
{
	pthread_mutex_destroy(&ct->lock);
	pthread_cond_destroy(&ct->active);
	pthread_spin_destroy(&ct->hldr_lock);
	free(ct);
}
Ejemplo n.º 3
0
int main()
{
    pthread_spinlock_t spinlock;
    struct sigaction act;

    /* Set up child thread to handle SIGALRM */
    act.sa_flags = 0;
    act.sa_handler = sig_handler;
    sigfillset(&act.sa_mask);
    sigaction(SIGALRM, &act, 0);

    printf("main: attemp to lock an un-initialized spin lock\n");

    printf("main: Send SIGALRM to me after 5 secs\n");
    alarm(5);

    /* Attempt to lock an uninitialized spinlock */
    rc = pthread_spin_lock(&spinlock);

    /* If we get here, call sig_handler() to check the return code of
     * pthread_spin_lock() */
    sig_handler();

    /* Unlock spinlock */
    pthread_spin_unlock(&spinlock);

    /* Destroy spinlock */
    pthread_spin_destroy(&spinlock);

    return PTS_PASS;
}
Ejemplo n.º 4
0
int
xwork_fini (struct xwork *xwork, int stop)
{
        int i = 0;
        int ret = 0;
        void *tret = 0;

        pthread_mutex_lock (&xwork->mutex);
        {
                xwork->stop = (xwork->stop || stop);
                pthread_cond_broadcast (&xwork->cond);
        }
        pthread_mutex_unlock (&xwork->mutex);

        for (i = 0; i < xwork->count; i++) {
                pthread_join (xwork->cthreads[i], &tret);
                tdbg ("CThread id %ld returned %p\n",
                      xwork->cthreads[i], tret);
        }

        if (debug) {
                assert (xwork->rootjob->refcnt == 1);
                dirjob_ret (xwork->rootjob, 0);
        }

        if (stats)
                pthread_spin_destroy(&stats_lock);

        return ret;
}
Ejemplo n.º 5
0
static int
do_test (void)
{
  pthread_spinlock_t s;

  if (pthread_spin_init (&s, PTHREAD_PROCESS_PRIVATE) != 0)
    {
      puts ("spin_init failed");
      return 1;
    }

  if (pthread_spin_lock (&s) != 0)
    {
      puts ("spin_lock failed");
      return 1;
    }

  if (pthread_spin_unlock (&s) != 0)
    {
      puts ("spin_unlock failed");
      return 1;
    }

  if (pthread_spin_destroy (&s) != 0)
    {
      puts ("spin_destroy failed");
      return 1;
    }

  return 0;
}
Ejemplo n.º 6
0
int main()
{

	pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE);
	lockandunlock();
	pthread_spin_destroy(&lock);

}
Ejemplo n.º 7
0
PADclose()
{
    while (!ev_fifo.empty())
        ev_fifo.pop();
    mutex_WasInit = false;
    pthread_spin_destroy(&mutex_KeyEvent);
    _PADclose();
}
Ejemplo n.º 8
0
    spinlock::~spinlock()
    {
#ifdef VOGL_BUILD_DEBUG
        VOGL_ASSERT(!m_in_lock);
#endif

        pthread_spin_destroy(&m_spinlock);
    }
Ejemplo n.º 9
0
Internal::~Internal(){
#ifdef INTERNAL_USE_SPINLOCKS
  pthread_spin_destroy(&_spin); 
#else
  pthread_mutex_destroy(&_mutex); 
  pthread_cond_destroy(&_cond); 
#endif
}
Ejemplo n.º 10
0
int init_pipe(struct pipe* p, int n_dst, int q_depth, int buf_sz)
{
	int free_bufs = n_dst * q_depth;
	struct pipe_elem* msg_all = (struct pipe_elem*)malloc(
		free_bufs * (sizeof(msg_all[0]) + buf_sz));
	void* buf_ptr;
	int def_dst_n, i;

	// allocate bufs
	if (!msg_all)
		return -1;
	p->priv = (void*)msg_all;

	// initialize src
	if (init_queue(&p->src, free_bufs))
		goto free_buf;
	
	// initialize dst
	def_dst_n = sizeof(p->_dst) / sizeof(p->_dst[0]);
	p->dst = n_dst < def_dst_n ? &p->_dst[0] :
		(struct queue*)malloc(n_dst * sizeof(p->dst[0]));
	if (!p->dst)
		goto free_src;
	for (i = 0; i < n_dst; i++) {
		if (init_queue(&p->dst[i], q_depth))
			goto free_dst;
	}

	// init spinlock
	if (pthread_spin_init(&p->lock, PTHREAD_PROCESS_PRIVATE)) 
		goto free_dst;

	// push buffers onto src
	buf_ptr = (void*)&msg_all[free_bufs];
	for (i = 0; i < free_bufs; i++) {
		msg_all[i].buf = buf_ptr;
		msg_all[i].seq = 0;
		msg_all[i].ref_cnt = 0;
		buf_ptr += buf_sz;

		assert(!enqueue(&p->src, &msg_all[i]));
	}

	p->n_dst = n_dst;
	return 0;

free_dst : 
	for (i--; i >= 0; i--)
		close_queue(&p->dst[i]);
free_src : 
	close_queue(&p->src);
free_buf : 
	free(msg_all);
destroy_lock : 
	pthread_spin_destroy(&p->lock);
	
	return -1;
}
Ejemplo n.º 11
0
	HawkSpinLock::~HawkSpinLock()
	{
		if (m_pSpinLock)
		{
			pthread_spin_destroy((pthread_spinlock_t*)m_pSpinLock);
			HawkFree(m_pSpinLock);
			m_pSpinLock = 0;
		}
	}
Ejemplo n.º 12
0
void
dirjob_free (struct dirjob *job)
{
        assert (list_empty (&job->list));

        pthread_spin_destroy (&job->lock);
        free (job->dirname);
        free (job);
}
Ejemplo n.º 13
0
void thread_context_destroy(struct netsniff_ng_thread_context * thread_ctx)
{
	assert(thread_ctx);

	pthread_attr_destroy(&thread_ctx->thread_attr);
	pthread_mutex_destroy(&thread_ctx->wait_mutex);
	pthread_cond_destroy(&thread_ctx->wait_cond);
	pthread_spin_destroy(&thread_ctx->config_lock);
}
Ejemplo n.º 14
0
bool spinlock_destroy(spinlock_t *lock)
{
    const int err = pthread_spin_destroy(lock);
    if (err) {
        error("spinlock error: %s", errno_error(err));
        return false;
    }
    return true;
}
Ejemplo n.º 15
0
Archivo: msg.c Proyecto: cfallin/nk
void nk_port_destroy(nk_port *port) {
  if (!port) {
    return;
  }
  assert(nk_msg_port_empty(&port->msgs));
  assert(nk_schob_runq_empty(&port->thds));
  pthread_spin_destroy(&port->lock);
  nk_freelist_free(&port->host->port_freelist, port);
}
Ejemplo n.º 16
0
int _starpu_spin_destroy(starpu_spinlock_t *lock)
{
#ifdef HAVE_PTHREAD_SPIN_LOCK
	return pthread_spin_destroy(&lock->lock);
#else
	/* we don't do anything */
	return 0;
#endif
}
Ejemplo n.º 17
0
void counter_destroy(Counter *counter)
{
#ifdef HAVE_PTHREAD_SPINLOCK_T
    pthread_spin_destroy(&counter->lock);
#else
    mutex_destroy(counter->lock);
#endif
    gw_free(counter);
}
Ejemplo n.º 18
0
void core_lock_destroy(struct core_lock *self)
{
#if defined(CORE_LOCK_USE_COMPARE_AND_SWAP)
    self->lock = CORE_LOCK_UNLOCKED;
#elif defined(CORE_LOCK_USE_SPIN_LOCK)
    pthread_spin_destroy(&self->lock);
#elif defined(CORE_LOCK_USE_MUTEX)
    pthread_mutex_destroy(&self->lock);
#endif
}
Ejemplo n.º 19
0
Archivo: bst_v2.c Proyecto: maxfalk/OSM
/**
 * Remove resources for the tree.
 *
 * @param root       root of the tree
 */
void tree_fini(struct bst_node ** root)
{

    /* TODO: Free any global variables you used for the BST */
    pthread_spin_destroy(&lock_cg);

    if (root != NULL)
        free(root);

}
Ejemplo n.º 20
0
void PMR_counter_destroy_lock(counter_t *counter)
{
#ifndef DISABLE_PTHREADS
 #ifdef NOSPINLOCKS
  pthread_mutex_destroy(&counter->lock);
 #else
  pthread_spin_destroy(&counter->lock);
 #endif
#endif
}
Ejemplo n.º 21
0
//テスト
int main(const int argc, const char* argv[])
{
	//スピンロック生成
	pthread_spin_init(&s_lock, PTHREAD_PROCESS_PRIVATE);//単独プロセス専用
//	pthread_spin_init(&s_lock, PTHREAD_PROCESS_SHARED);//プロセス間で共有
	
	//スレッド作成
	static const int THREAD_NUM = 3;
	pthread_t pth[THREAD_NUM];
	{
		pthread_attr_t attr;
		pthread_attr_init(&attr);
		pthread_attr_setstacksize(&attr, 1024);//スタックサイズ指定
		pthread_create(&pth[0], &attr, threadFunc, (void*)"太郎");
		pthread_create(&pth[1], &attr, threadFunc, (void*)"次郎");
		pthread_create(&pth[2], &attr, threadFunc, (void*)"三郎");
	}
	
	//スレッド終了待ち
	for(int i = 0; i < THREAD_NUM; ++i)
	{
		pthread_join(pth[i], NULL);
	}
	
	//スピにロックの取得と解放を大量に実行して時間を計測
	{
		struct timeval begin;
		gettimeofday(&begin, NULL);
		static const int TEST_TIMES = 10000000;
		for (int i = 0; i < TEST_TIMES; ++i)
		{
			pthread_spin_lock(&s_lock);
			pthread_spin_unlock(&s_lock);
		}
		struct timeval end;
		gettimeofday(&end, NULL);
		struct timeval duration;
		if( end.tv_usec >= begin.tv_usec)
		{
			duration.tv_sec = end.tv_sec - begin.tv_sec;
			duration.tv_usec = end.tv_usec - begin.tv_usec;
		}
		else
		{
			duration.tv_sec = end.tv_sec - begin.tv_sec - 1;
			duration.tv_usec = 1000000 - begin.tv_usec + end.tv_usec;
		}
		printf("Spinlock * %d = %d.%06d sec\n", TEST_TIMES, duration.tv_sec, duration.tv_usec);
	}
	
	//スピンロック破棄
	pthread_spin_destroy(&s_lock);
	
	return EXIT_SUCCESS;
}
Ejemplo n.º 22
0
int main(int argc, char *argv[])
{
    long nproc = 0;
    long i;
    pthread_t *threads;

    if (argc != 1) {
        fprintf(stderr, "Usage: %s\n", argv[0]);
        return 1;
    }
    
    nproc = sysconf(_SC_NPROCESSORS_ONLN);
    if (nproc < 0) {
        perror("sysconf");
        return 1;
    }

#if defined _USE_MUTEX
    pthread_mutex_init(&mutex, NULL);
#elif defined _USE_SPIN
    pthread_spin_init(&spinlock, 0);
#endif

    threads = malloc(sizeof(pthread_t) * nproc);
    if (threads == NULL) {
        perror("malloc");
        return 1;
    }

    printf("Starting %ld threads...\n", nproc);

    for (i = 0; i < nproc; i++) {
        if (pthread_create(&threads[i], NULL, incrementer, (void *)&i)) {
            perror("pthread_create");
            nproc = i;
            break;
        }
    }

    for (i = 0; i < nproc; i++) {
        pthread_join(threads[i], NULL);
    }
    free(threads);

    printf("global_int actual value:   %d\n", global_int);
    printf("global_int expected value: %d\n", (int)(INC_TO * nproc));

#if defined _USE_MUTEX
    pthread_mutex_destroy(&mutex);
#elif defined _USE_SPIN
    pthread_spin_destroy(&spinlock);
#endif

    return 0;
}
Ejemplo n.º 23
0
/** check if OK, free struct */
void 
checklock_destroy(enum check_lock_type type, struct checked_lock** lock,
        const char* func, const char* file, int line)
{
	const size_t contention_interest = 1; /* promille contented locks */
	struct checked_lock* e;
	if(!lock) 
		return;
	e = *lock;
	if(!e)
		return;
	checktype(type, e, func, file, line);

	/* check if delete is OK */
	acquire_locklock(e, func, file, line);
	if(e->hold_count != 0)
		lock_error(e, func, file, line, "delete while locked.");
	if(e->wait_count != 0)
		lock_error(e, func, file, line, "delete while waited on.");
	prot_check(e, func, file, line);
	*lock = NULL; /* use after free will fail */
	LOCKRET(pthread_mutex_unlock(&e->lock));

	/* contention, look at fraction in trouble. */
	if(e->history_count > 1 &&
	   1000*e->contention_count/e->history_count > contention_interest) {
		log_info("lock created %s %s %d has contention %u of %u (%d%%)",
			e->create_func, e->create_file, e->create_line,
			(unsigned int)e->contention_count, 
			(unsigned int)e->history_count,
			(int)(100*e->contention_count/e->history_count));
	}

	/* delete it */
	LOCKRET(pthread_mutex_destroy(&e->lock));
	prot_clear(e);
	/* since nobody holds the lock - see check above, no need to unlink 
	 * from the thread-held locks list. */
	switch(e->type) {
		case check_lock_mutex:
			LOCKRET(pthread_mutex_destroy(&e->u.mutex));
			break;
		case check_lock_spinlock:
			LOCKRET(pthread_spin_destroy(&e->u.spinlock));
			break;
		case check_lock_rwlock:
			LOCKRET(pthread_rwlock_destroy(&e->u.rwlock));
			break;
		default:
			log_assert(0);
	}
	memset(e, 0, sizeof(struct checked_lock));
	free(e);
}
Ejemplo n.º 24
0
static void
my_finit_hook (void)
{
    pthread_spin_lock(&lock);
    /* Restore all old hooks */
    __malloc_hook = old_malloc_hook;
    __realloc_hook = old_realloc_hook;
    __free_hook = old_free_hook;
    printf("Memtool finit!\n");
    pthread_spin_unlock(&lock);
    pthread_spin_destroy(&lock);
}
Ejemplo n.º 25
0
/**
 * Destroy firewall instance.
 * @param[in] fwd Firewall handle.
 */
void zfwall_destroy(struct zfirewall *fire)
{
    pthread_spin_destroy(&fire->lock);

    for (int proto = 0; proto < PROTO_MAX; proto++) {
        for (int rule = 0; rule < PORT_MAX; rule++) {
                utarray_done(&fire->rules[proto][rule]);
        }
    }

    free(fire);
}
Ejemplo n.º 26
0
Archivo: thd.c Proyecto: cfallin/nk
static void nk_thd_destroy(nk_thd *t) {
  nk_hostthd *hostthd = nk_hostthd_self();
  assert(hostthd != NULL);
  nk_host *host = hostthd->host;

  pthread_mutex_lock(&nk_thd_stack_freelist_mutex);
  nk_freelist_free(&nk_thd_stack_freelist, t->stack);
  pthread_mutex_unlock(&nk_thd_stack_freelist_mutex);

  pthread_spin_destroy(&t->running_lock);
  nk_schob_destroy(&t->schob);
  nk_freelist_free(&host->thd_freelist, t);
}
void KmaClose(void) {
	if(fdKMA < 0) {
		printf("fdKMA is not initialized. please call Init() first\n");
		return;
	}

	CancelAllTraceFunc();

	pthread_spin_destroy(&traceFuncArrayLock);

	close(fdKMA);
	return;
}
Ejemplo n.º 28
0
static int aio_socket_release(struct epoll_context* ctx)
{
	if( 0 == __sync_sub_and_fetch_4(&ctx->ref, 1) )
	{
		pthread_spin_destroy(&ctx->locker);

#if defined(DEBUG) || defined(_DEBUG)
		memset(ctx, 0xCC, sizeof(*ctx));
#endif
		free(ctx);
	}
	return 0;
}
Ejemplo n.º 29
0
void close_pipe(struct pipe* p)
{
	int i;
	
	for (i = 0; i < p->n_dst; i++)
		close_queue(&p->dst[i]);
	if (p->dst != &p->_dst[0])
		free(p->dst);
	close_queue(&p->src);
	free(p->priv);
	pthread_spin_destroy(&p->lock);
	
}
Ejemplo n.º 30
0
Archivo: 3-1.c Proyecto: kraj/ltp
int main(void)
{
	int rc;
	pthread_spinlock_t spinlock;
	struct sigaction act;

	/* Set up child thread to handle SIGALRM */
	act.sa_flags = 0;
	act.sa_handler = sig_handler;
	sigfillset(&act.sa_mask);
	sigaction(SIGALRM, &act, 0);

	if (pthread_spin_init(&spinlock, PTHREAD_PROCESS_PRIVATE) != 0) {
		printf("main: Error at pthread_spin_init()\n");
		return PTS_UNRESOLVED;
	}

	printf("main: attempt spin lock\n");

	/* We should get the lock */
	if (pthread_spin_lock(&spinlock) != 0) {
		printf
		    ("Test FAILED: main cannot get spin lock when no one owns the lock\n");
		return PTS_FAIL;
	}
	printf("main: acquired spin lock\n");

	printf("main: send SIGALRM to me after 2 secs\n");
	alarm(2);

	printf("main: re-lock spin lock\n");
	rc = pthread_spin_lock(&spinlock);

	if (rc == EDEADLK) {
		printf
		    ("main: correctly got EDEADLK when re-locking the spin lock\n");
		printf("Test PASSED\n");
	} else {
		printf("main: get return code: %d , %s\n", rc, strerror(rc));
		printf
		    ("Test PASSED: *Note: Did not return EDEADLK when re-locking a spinlock already in  use, but standard says 'may' fail\n");
	}

	/* Unlock spinlock */
	pthread_spin_unlock(&spinlock);

	/* Destroy spinlock */
	pthread_spin_destroy(&spinlock);

	return PTS_PASS;
}