示例#1
0
void
openlog(const char *ident, int logstat, int logfac)
{
	THREAD_LOCK();
	openlog_unlocked(ident, logstat, logfac);
	THREAD_UNLOCK();
}
示例#2
0
static char *
getlogin_basic(int *status)
{
	static char logname[MAXLOGNAME];

	if (_logname_valid == 0) {
#ifdef __NETBSD_SYSCALLS
		if (__getlogin(logname, sizeof(logname) - 1) < 0) {
#else
		if (_getlogin(logname, sizeof(logname)) < 0) {
#endif
			*status = errno;
			return (NULL);
		}
		_logname_valid = 1;
	}
	*status = 0;
	return (*logname ? logname : NULL);
}

char *
getlogin(void)
{
	char	*result;
	int	status;

	THREAD_LOCK();
	result = getlogin_basic(&status);
	THREAD_UNLOCK();
	return (result);
}
示例#3
0
GAULFUNC void ga_chromosome_integer_deallocate( population *pop,
                                       entity *corpse )
  {

  if (!pop) die("Null pointer to population structure passed.");
  if (!corpse) die("Null pointer to entity structure passed.");

  if (corpse->chromosome==NULL)
    die("This entity already contains no chromosomes.");

#ifdef USE_CHROMO_CHUNKS
  THREAD_LOCK(pop->chromo_chunk_lock);
  mem_chunk_free(pop->chromo_chunk, corpse->chromosome[0]);
  mem_chunk_free(pop->chromoarray_chunk, corpse->chromosome);
  corpse->chromosome=NULL;

  if (mem_chunk_isempty(pop->chromo_chunk))
    {
    mem_chunk_destroy(pop->chromo_chunk);
    mem_chunk_destroy(pop->chromoarray_chunk);
    pop->chromo_chunk = NULL;
    }
  THREAD_UNLOCK(pop->chromo_chunk_lock);
#else
  s_free(corpse->chromosome[0]);
  s_free(corpse->chromosome);
  corpse->chromosome=NULL;
#endif

  return;
  }
示例#4
0
static void event_enable_write(ACL_EVENT *eventp, ACL_VSTREAM *stream,
	int timeout, ACL_EVENT_NOTIFY_RDWR callback, void *context)
{
	const char *myname = "event_enable_write";
	EVENT_POLL_THR *event_thr = (EVENT_POLL_THR *) eventp;
	ACL_EVENT_FDTABLE *fdp;
	ACL_SOCKET sockfd;

	sockfd = ACL_VSTREAM_SOCK(stream);
	fdp = (ACL_EVENT_FDTABLE*) stream->fdp;
	if (fdp == NULL) {
		fdp = event_fdtable_alloc();
		fdp->listener = 0;
		fdp->stream = stream;
		stream->fdp = (void *) fdp;
	} else if (fdp->flag & EVENT_FDTABLE_FLAG_READ)
		acl_msg_panic("%s(%d)->%s: fd %d: multiple I/O request",
			__FILE__, __LINE__, myname, sockfd);
	else {
		fdp->listener = 0;
		fdp->stream = stream;
	}

	if (fdp->w_callback != callback || fdp->w_context != context) {
		fdp->w_callback = callback;
		fdp->w_context = context;
	}

	if (timeout > 0) {
		fdp->w_timeout = timeout * 1000000;
		fdp->w_ttl = eventp->present + fdp->w_timeout;
	} else {
		fdp->w_ttl = 0;
		fdp->w_timeout = 0;
	}

	if ((fdp->flag & EVENT_FDTABLE_FLAG_WRITE) != 0)
		return;

	stream->nrefer++;
	fdp->flag = EVENT_FDTABLE_FLAG_WRITE | EVENT_FDTABLE_FLAG_EXPT;

	THREAD_LOCK(&event_thr->event.tb_mutex);

	fdp->fdidx = eventp->fdcnt;
	eventp->fdtabs[eventp->fdcnt++] = fdp;

	event_thr->fds[fdp->fdidx].fd = sockfd;
	event_thr->fds[fdp->fdidx].events = POLLOUT | POLLHUP | POLLERR;
	if (eventp->maxfd == ACL_SOCKET_INVALID || eventp->maxfd < sockfd)
		eventp->maxfd = sockfd;

	acl_fdmap_add(event_thr->fdmap, sockfd, fdp);

	THREAD_UNLOCK(&event_thr->event.tb_mutex);

	if (event_thr->event.blocked && event_thr->event.evdog
	    && event_dog_client(event_thr->event.evdog) != stream)
		event_dog_notify(event_thr->event.evdog);
}
示例#5
0
/*\ client sends strided data + request to server
\*/
int armci_send_req_msg_strided(int proc, request_header_t *msginfo,char *ptr,
                               int strides, int stride_arr[], int count[])
{
int cluster = armci_clus_id(proc);
int stat, bytes;

    if(DEBUG_){
      printf("%d:armci_send_req_msg_strided: op=%d to=%d bytes= %d \n",armci_me,
             msginfo->operation,proc,msginfo->datalen);
      fflush(stdout);
    }

    /* we write header + data descriptor */
    bytes = sizeof(request_header_t) + msginfo->dscrlen;

    THREAD_LOCK(armci_user_threads.net_lock);

    stat = armci_WriteToSocket(SRV_sock[cluster], msginfo, bytes);
    if(stat<0)armci_die("armci_send_strided:write failed",stat);
#if defined(USE_SOCKET_VECTOR_API)
    if(msginfo->operation==PUT && msginfo->datalen==0)
        armci_SendStridedToSocket( SRV_sock[cluster],ptr,stride_arr,count,
             strides,(struct iovec *)(msginfo+1) );
    else
#endif
    /* for larger blocks write directly to socket thus avoiding memcopy */
    armci_write_strided_sock(ptr, strides,stride_arr,count,SRV_sock[cluster]);

    THREAD_UNLOCK(armci_user_threads.net_lock);

    return 0;
}
示例#6
0
GAULFUNC void random_seed(const unsigned int seed)
  { 
  int	i; 

#ifdef USE_OPENMP
  if (is_initialised == FALSE)
    {
    omp_init_lock(&random_state_lock);
    is_initialised = TRUE;
    }
#else
  is_initialised = TRUE;
#endif

  THREAD_LOCK(random_state_lock);

  current_state.v[0]=(seed & RANDOM_RAND_MAX);

  for(i=1; i<RANDOM_NUM_STATE_VALS; i++)
    current_state.v[i] = (RANDOM_LC_ALPHA * current_state.v[i-1]
                          + RANDOM_LC_BETA) & RANDOM_RAND_MAX;

  current_state.j = 0;
  current_state.k = RANDOM_MM_ALPHA-RANDOM_MM_BETA;
  current_state.x = RANDOM_MM_ALPHA-0;

  THREAD_UNLOCK(random_state_lock);

  return;
  } 
示例#7
0
void get_remote(double *buf, int I, int J)
{
    int proc_owner;
    int edge, size;

#ifdef USE_MUTEX
    THREAD_LOCK(mutex);
#endif

    proc_owner = block_owner(I, J) / th_per_p;

    edge = n%block_size;
    if (edge == 0) {
        edge = block_size;
    }

    if ((I == nblocks-1) && (J == nblocks-1)) {
        size = edge*edge;
    }
    else if ((I == nblocks-1) || (J == nblocks-1)) {
        size = edge*block_size;
    }
    else {
        size = block_size*block_size;
    }
    size = size * sizeof(double);

    if (proc_owner == me) memcpy(buf, a[I+J*nblocks], size);
    else ARMCI_Get(a[I+J*nblocks], buf, size, proc_owner);

#ifdef USE_MUTEX
    THREAD_UNLOCK(mutex);
#endif
}
示例#8
0
void
arc4random_stir(void)
{
	THREAD_LOCK();
	arc4_check_init();
	arc4_stir();
	rs_stired = 1;
	THREAD_UNLOCK();
}
示例#9
0
void
arc4random_addrandom(u_char *dat, int datlen)
{
	THREAD_LOCK();
	arc4_check_init();
	arc4_check_stir();
	arc4_addrandom(dat, datlen);
	THREAD_UNLOCK();
}
示例#10
0
static void avltree_node_free(AVLNode *node)
  {
  THREAD_LOCK(avltree_node_buffer_lock);
  node->right = node_free_list;
  node_free_list = node;
  THREAD_UNLOCK(avltree_node_buffer_lock);

  return;
  }
示例#11
0
/*
 * Find a free FILE for fopen et al.
 */
FILE *
__sfp(void)
{
	FILE	*fp;
	int	n;
	struct glue *g;

	if (!__sdidinit)
		__sinit();
	/*
	 * The list must be locked because a FILE may be updated.
	 */
	THREAD_LOCK();
	for (g = &__sglue; g != NULL; g = g->next) {
		for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
			if (fp->pub._flags == 0)
				goto found;
	}
	THREAD_UNLOCK();	/* don't hold lock while malloc()ing. */
	if ((g = moreglue(NDYNAMIC)) == NULL)
		return (NULL);
	THREAD_LOCK();		/* reacquire the lock */
	SET_GLUE_PTR(lastglue->next, g); /* atomically append glue to list */
	lastglue = g;		/* not atomic; only accessed when locked */
	fp = g->iobs;
found:
	fp->pub._flags = 1;	/* reserve this slot; caller sets real flags */
	THREAD_UNLOCK();
	fp->pub._p = NULL;	/* no current pointer */
	fp->pub._w = 0;		/* nothing to read or write */
	fp->pub._r = 0;
	fp->_bf._base = NULL;	/* no buffer */
	fp->_bf._size = 0;
	fp->pub._lbfsize = 0;	/* not line buffered */
	fp->pub._fileno = -1;	/* no file */
/*	fp->_cookie = <any>; */	/* caller sets cookie, _read/_write etc */
	fp->_ub._base = NULL;	/* no ungetc buffer */
	fp->_ub._size = 0;
	fp->_lb._base = NULL;	/* no line buffer */
	fp->_lb._size = 0;
/*	fp->_lock = NULL; */	/* once set always set (reused) */
	memset(WCIO_GET(fp), 0, sizeof(struct wchar_io_data));
	return (fp);
}
示例#12
0
void
closelog(void)
{
	THREAD_LOCK();
	(void)_close(LogFile);
	LogFile = -1;
	LogTag = NULL;
	status = NOCONN;
	THREAD_UNLOCK();
}
示例#13
0
static void event_disable_readwrite(ACL_EVENT *eventp, ACL_VSTREAM *stream)
{
	const char *myname = "event_disable_readwrite";
	EVENT_SELECT_THR *event_thr = (EVENT_SELECT_THR *) eventp;
	ACL_EVENT_FDTABLE *fdp;
	ACL_SOCKET sockfd;

	sockfd = ACL_VSTREAM_SOCK(stream);

	THREAD_LOCK(&event_thr->event.tb_mutex);
	if (!FD_ISSET(sockfd, &event_thr->xmask)) {
		acl_msg_error("%s(%d): sockfd(%d) not be set",
			myname, __LINE__, sockfd);
		THREAD_UNLOCK(&event_thr->event.tb_mutex);
		return;
	}
	fdp = (ACL_EVENT_FDTABLE *) stream->fdp;
	if (fdp == NULL) {
		acl_msg_error("%s(%d): fdp null", myname, __LINE__);
		THREAD_UNLOCK(&event_thr->event.tb_mutex);
		return;
	}

	if (fdp->fdidx == -1)
		acl_msg_fatal("%s(%d): fdidx(%d) invalid",
			myname, __LINE__, fdp->fdidx);

	FD_CLR(sockfd, &event_thr->xmask);
	FD_CLR(sockfd, &event_thr->rmask);
	FD_CLR(sockfd, &event_thr->wmask);

	fdp->flag = 0;

	if (eventp->maxfd == sockfd)
		eventp->maxfd = ACL_SOCKET_INVALID;
	if (eventp->fdtabs[fdp->fdidx] == fdp) {
		if (fdp->fdidx < --eventp->fdcnt) {
			eventp->fdtabs[fdp->fdidx] = eventp->fdtabs[eventp->fdcnt];
			eventp->fdtabs[fdp->fdidx]->fdidx = fdp->fdidx;
		}
	} else
		acl_msg_fatal("%s(%d): fdidx(%d)'s fdp invalid",
			myname, __LINE__, fdp->fdidx);

	if (fdp->fdidx_ready > 0
	    && fdp->fdidx_ready < eventp->fdcnt_ready
	    && eventp->fdtabs_ready[fdp->fdidx_ready] == fdp)
	{
		eventp->fdtabs_ready[fdp->fdidx_ready] = NULL;
	}
	event_fdtable_free(fdp);
	stream->fdp = NULL;
	stream->nrefer--;
	THREAD_UNLOCK(&event_thr->event.tb_mutex);
}
示例#14
0
char *
getlogin(void)
{
	char	*result;
	int	status;

	THREAD_LOCK();
	result = getlogin_basic(&status);
	THREAD_UNLOCK();
	return (result);
}
示例#15
0
int random_get_state_wrapper(void)
  {
  int	stateid;	/* State handle. */

  THREAD_LOCK(state_table_lock);
  if (!state_table) state_table=table_new();

  stateid = table_add(state_table, (vpointer) current_state);	/* FIXME: Need to copy state. */
  THREAD_UNLOCK(state_table_lock);

  return stateid;
  }
示例#16
0
/* xo_set_logmask -- set the log mask level */
int
xo_set_logmask (int pmask)
{
    int omask;

    THREAD_LOCK();
    omask = xo_logmask;
    if (pmask != 0)
        xo_logmask = pmask;
    THREAD_UNLOCK();
    return (omask);
}
示例#17
0
void
xo_close_log (void) 
{
    THREAD_LOCK();
    if (xo_logfile != -1) {
        (void) close(xo_logfile);
        xo_logfile = -1;
    }
    xo_logtag = NULL;
    xo_status = NOCONN;
    THREAD_UNLOCK();
}
示例#18
0
/* setlogmask -- set the log mask level */
int
setlogmask(int pmask)
{
	int omask;

	THREAD_LOCK();
	omask = LogMask;
	if (pmask != 0)
		LogMask = pmask;
	THREAD_UNLOCK();
	return (omask);
}
示例#19
0
文件: timer_util.c 项目: aaasz/SHP
void timer_free_slang(int *t_handle)
  {
  chrono_t       *t;

  THREAD_LOCK(chrono_table_lock);
  t = table_remove_index(chrono_table, *t_handle);
  THREAD_UNLOCK(chrono_table_lock);

  s_free(t);

  return;
  }
示例#20
0
文件: timer_util.c 项目: aaasz/SHP
int timer_new_slang(void)
  {
  chrono_t	*t=s_malloc(sizeof(chrono_t));
  int		t_handle;

  THREAD_LOCK(chrono_table_lock);
  if (chrono_table==NULL) chrono_table=table_new();

  t_handle = table_add(chrono_table, (vpointer) t);
  THREAD_UNLOCK(chrono_table_lock);

  return (int) t_handle;
  }
示例#21
0
static void event_disable_readwrite(ACL_EVENT *eventp, ACL_VSTREAM *stream)
{
	const char *myname = "event_disable_readwrite";
	EVENT_POLL_THR *event_thr = (EVENT_POLL_THR *) eventp;
	ACL_EVENT_FDTABLE *fdp;
	ACL_SOCKET sockfd;

	sockfd = ACL_VSTREAM_SOCK(stream);
	fdp = (ACL_EVENT_FDTABLE *) stream->fdp;
	if (fdp == NULL) {
		acl_msg_error("%s(%d): fdp null", myname, __LINE__);
		return;
	}

	if ((fdp->flag & (EVENT_FDTABLE_FLAG_READ
		| EVENT_FDTABLE_FLAG_WRITE)) == 0)
	{
		acl_msg_error("%s(%d): sockfd(%d) not be set",
			myname, __LINE__, sockfd);
		return;
	}
	if (fdp->fdidx == -1)
		acl_msg_fatal("%s(%d): fdidx(%d) invalid",
			myname, __LINE__, fdp->fdidx);

	THREAD_LOCK(&event_thr->event.tb_mutex);

	if (eventp->maxfd == sockfd)
		eventp->maxfd = ACL_SOCKET_INVALID;

	if (eventp->fdtabs[fdp->fdidx] != fdp)
		acl_msg_fatal("%s(%d): fdidx(%d)'s fdp invalid",
			myname, __LINE__, fdp->fdidx);

	if (fdp->fdidx < --eventp->fdcnt) {
		eventp->fdtabs[fdp->fdidx] = eventp->fdtabs[eventp->fdcnt];
		eventp->fdtabs[fdp->fdidx]->fdidx = fdp->fdidx;
		event_thr->fds[fdp->fdidx] = event_thr->fds[eventp->fdcnt];
	}

	acl_fdmap_del(event_thr->fdmap, sockfd);

	THREAD_UNLOCK(&event_thr->event.tb_mutex);

	if (fdp->flag & EVENT_FDTABLE_FLAG_READ)
		stream->nrefer--;
	if (fdp->flag & EVENT_FDTABLE_FLAG_WRITE)
		stream->nrefer--;

	event_fdtable_reset(fdp);
}
示例#22
0
u_int32_t
arc4random(void)
{
	u_int32_t rnd;

	THREAD_LOCK();
	arc4_check_init();
	arc4_check_stir();
	rnd = arc4_getword();
	arc4_count -= 4;
	THREAD_UNLOCK();

	return (rnd);
}
示例#23
0
void random_set_state_wrapper(int stateid)
  {
  random_state	state;	/* State to restore. */

  THREAD_LOCK(state_table_lock);
  state = table_get_data(state_table, stateid);
  THREAD_UNLOCK(state_table_lock);

  if (!state) die("Unmatched state handle.");

  random_set_state(state);

  return;
  }
示例#24
0
void
arc4random_buf(void *_buf, size_t n)
{
	u_char *buf = (u_char *)_buf;

	THREAD_LOCK();
	arc4_check_init();
	while (n--) {
		arc4_check_stir();
		buf[n] = arc4_getbyte();
		arc4_count--;
	}
	THREAD_UNLOCK();
}
示例#25
0
static AVLNode *avltree_node_new(AVLKey key, vpointer data)
  {
  AVLNode *node;

  THREAD_LOCK(avltree_node_buffer_lock);
/*
 * Find an unused node.  Look for unused node in current buffer, then
 * in the free node list, then allocate new buffer.
 */
  if (num_used < AVL_NODE_BUFFER_SIZE)
    {
    node = &(node_buffers[buffer_num][num_used]);
    num_used++;
    }
  else
    {
    if (node_free_list!=NULL)
      {
      node = node_free_list;
      node_free_list = node->right;
      }
    else
      {
      buffer_num++;

      if (buffer_num == num_buffers)
        {
        num_buffers += AVL_NODE_BUFFER_NUM_INCR;
        node_buffers = s_realloc(node_buffers, sizeof(AVLNode *)*num_buffers);
        }

      if ( !(node_buffers[buffer_num] = s_malloc(sizeof(AVLNode)*AVL_NODE_BUFFER_SIZE)) )
        die("Unable to allocate memory");

      node = node_buffers[buffer_num];
      num_used = 1;
      }
    }
  THREAD_UNLOCK(avltree_node_buffer_lock);

  node->balance = 0;
  node->left = NULL;
  node->right = NULL;
  node->key = key;
  node->data = data;

  return node;
  }
示例#26
0
GAULFUNC void avltree_delete(AVLTree *tree)
  {
  if (!tree) return;

  avltree_node_delete(tree->root);

  s_free(tree);

  AVLnum_trees--;

  THREAD_LOCK(avltree_node_buffer_lock);
  if (AVLnum_trees == 0)
    _destroy_buffers();
  THREAD_UNLOCK(avltree_node_buffer_lock);

  return;
  }
示例#27
0
int
getlogin_r(char *logname, int namelen)
{
	char	*result;
	int	len;
	int	status;
	
	THREAD_LOCK();
	result = getlogin_basic(&status);
	if (status == 0) {
		if ((len = strlen(result) + 1) > namelen)
			status = ERANGE;
		else
			strncpy(logname, result, len);
	}
	THREAD_UNLOCK();
	return (status);
}
示例#28
0
/*\ client sends request message to server
\*/
int armci_send_req_msg(int proc, void *buf, int bytes)
{
    int cluster = armci_clus_id(proc);
    request_header_t* msginfo = (request_header_t*)buf;
    int idx, rc;

    THREAD_LOCK(armci_user_threads.net_lock);

    /* mark sockets as active (only if reply is expected?) */
    idx = _armci_buf_to_index(msginfo);
    _armci_active_socks->socks[idx] = SRV_sock[cluster];

    rc = (armci_WriteToSocket(SRV_sock[cluster], buf, bytes) < 0);

    THREAD_UNLOCK(armci_user_threads.net_lock);

    return rc;
}
示例#29
0
GAULFUNC unsigned int random_rand(void)
  {
  unsigned int val;

  if (!is_initialised) die("Neither random_init() or random_seed() have been called.");

  THREAD_LOCK(random_state_lock);

  val = (current_state.v[current_state.j]+current_state.v[current_state.k])
        & RANDOM_RAND_MAX;

  current_state.x = (current_state.x+1) % RANDOM_NUM_STATE_VALS;
  current_state.j = (current_state.j+1) % RANDOM_NUM_STATE_VALS;
  current_state.k = (current_state.k+1) % RANDOM_NUM_STATE_VALS;
  current_state.v[current_state.x] = val;

  THREAD_UNLOCK(random_state_lock);

  return val;
  } 
示例#30
0
GAULFUNC void avltree_destroy(AVLTree *tree, AVLDestructorFunc free_func)
  {
  if (!tree) return;

  if (free_func!=NULL)
    avltree_node_destroy(tree->root, free_func);
  else
    avltree_node_delete(tree->root);

  s_free(tree);

  AVLnum_trees--;

  THREAD_LOCK(avltree_node_buffer_lock);
  if (AVLnum_trees == 0)
    _destroy_buffers();
  THREAD_UNLOCK(avltree_node_buffer_lock);

  return;
  }