Ejemplo n.º 1
0
void* XMLPlatformUtils::makeMutex()
{
    pthread_mutex_t* mutex = new pthread_mutex_t;
    pthread_mutexattr_t*  attr = new pthread_mutexattr_t;

#if defined(XML_USE_DCE)
    pthread_mutexattr_create(attr);
    pthread_mutexattr_setkind_np(attr, MUTEX_RECURSIVE_NP);
    if (pthread_mutex_init(mutex, *attr))
    {
        ThrowXMLwithMemMgr(XMLPlatformUtilsException,
                 XMLExcepts::Mutex_CouldNotCreate, fgMemoryManager);
    }
    pthread_mutexattr_delete(attr);
#else
    pthread_mutexattr_init(attr);
    pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE);
    if (pthread_mutex_init(mutex, attr))
    {
        ThrowXMLwithMemMgr(XMLPlatformUtilsException,
                 XMLExcepts::Mutex_CouldNotCreate, fgMemoryManager);
    }
    pthread_mutexattr_destroy(attr);
#endif
    delete attr;

    return (void*) mutex;
}
Ejemplo n.º 2
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void ThreadSetupLock(void)
{
	pthread_mutexattr_t mattrib;

	Log_Print("pthread multi-threading\n");

	if (!my_mutex)
	{
		my_mutex = GetMemory(sizeof(*my_mutex));
		if (pthread_mutexattr_create (&mattrib) == -1)
			Error ("pthread_mutex_attr_create failed");
		if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
			Error ("pthread_mutexattr_setkind_np failed");
		if (pthread_mutex_init (my_mutex, mattrib) == -1)
			Error ("pthread_mutex_init failed");
	}

	if (pthread_attr_create (&attrib) == -1)
		Error ("pthread_attr_create failed");
	if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
		Error ("pthread_attr_setstacksize failed");

	threaded = true;
	currentnumthreads = 0;
	currentthreadid = 0;
} //end of the function ThreadInitLock
Ejemplo n.º 3
0
void InitThreads (int wantthreads, size_t needstack)
{
	pthread_mutexattr_t	mattrib;

	if (needstack != 0)
		stacksiz = needstack;
	else	stacksiz = DEFAULT_STACKSIZ;

	numthreads = wantthreads;
	if (numthreads < 0)
		numthreads = 4;
	if (numthreads < 1)
		numthreads = 1;
	if (numthreads > MAX_THREADS)
		numthreads = MAX_THREADS;

	printf ("Setup for %d threads, 0x%x stack size\n",
			numthreads, (unsigned int)stacksiz);
	if (numthreads <= 1)
		return;

	my_mutex = (pthread_mutex_t *) SafeMalloc (sizeof(*my_mutex));
	if (pthread_mutexattr_create (&mattrib) == -1)
		COM_Error ("pthread_mutex_attr_create failed");
	if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
		COM_Error ("pthread_mutexattr_setkind_np failed");
	if (pthread_mutex_init (my_mutex, mattrib) == -1)
		COM_Error ("pthread_mutex_init failed");
}
void* XMLPlatformUtils::makeMutex(MemoryManager* manager)
{
    MutexHolderType* const  holder = new (manager) MutexHolderType;

    pthread_mutexattr_t     attr;

#if defined(XML_USE_DCE)
    pthread_mutexattr_create(&attr);
    pthread_mutexattr_setkind_np(&attr, MUTEX_RECURSIVE_NP);
    if (pthread_mutex_init(&holder->fInstance, attr))
    {
        delete holder;

        panic(PanicHandler::Panic_MutexErr);
    }
    pthread_mutexattr_delete(&attr);
#else
    pthread_mutexattr_init(&attr);
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
    if (pthread_mutex_init(&holder->fInstance, &attr))
    {
        delete holder;

        panic(PanicHandler::Panic_MutexErr);
    }
    pthread_mutexattr_destroy(&attr);
#endif

    return holder;
}
Ejemplo n.º 5
0
void plc_inittimer (
  plc_sThread *tp
)
{

#if 0
  /* Create the timer mutex */
#ifdef OS_ELN
  {
    int	sts;
    ELN$CREATE_MUTEX(tp->timer_mutex, &sts);
    if (EVEN(sts))
      pwr_Bugcheck(sts, "Cannot create timer_mutex");
  }
#elif defined OS_POSIX
  {
    pthread_mutexattr_t attr;

    pthread_mutexattr_create(&attr);
    if (pthread_mutex_init(&tp->timer_mutex, attr) == -1) 
      pwr_Bugcheck(errno, "Cannot create timer_mutex");
    pthread_mutexattr_delete(&attr);
  }
#endif
#endif
}
Ejemplo n.º 6
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void RunThreadsOn(int workcnt, qboolean showpacifier, void(*func)(int))
{
	int		i;
	pthread_t	work_threads[MAX_THREADS];
	pthread_addr_t	status;
	pthread_attr_t	attrib;
	pthread_mutexattr_t	mattrib;
	int		start, end;

	Log_Print("pthread multi-threading\n");

	start = I_FloatTime ();
	dispatch = 0;
	workcount = workcnt;
	oldf = -1;
	pacifier = showpacifier;
	threaded = true;

	if (numthreads < 1 || numthreads > MAX_THREADS) numthreads = 1;

	if (pacifier)
		setbuf (stdout, NULL);

	if (!my_mutex)
	{
		my_mutex = GetMemory(sizeof(*my_mutex));
		if (pthread_mutexattr_create (&mattrib) == -1)
			Error ("pthread_mutex_attr_create failed");
		if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
			Error ("pthread_mutexattr_setkind_np failed");
		if (pthread_mutex_init (my_mutex, mattrib) == -1)
			Error ("pthread_mutex_init failed");
	}

	if (pthread_attr_create (&attrib) == -1)
		Error ("pthread_attr_create failed");
	if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
		Error ("pthread_attr_setstacksize failed");
	
	for (i=0 ; i<numthreads ; i++)
	{
  		if (pthread_create(&work_threads[i], attrib
		, (pthread_startroutine_t)func, (pthread_addr_t)i) == -1)
			Error ("pthread_create failed");
	}
		
	for (i=0 ; i<numthreads ; i++)
	{
		if (pthread_join (work_threads[i], &status) == -1)
			Error ("pthread_join failed");
	}

	threaded = false;

	end = I_FloatTime ();
	if (pacifier)
		printf (" (%i)\n", end-start);
} //end of the function RunThreadsOn
Ejemplo n.º 7
0
/*
=============
_RunThreadsOn
=============
*/
void _RunThreadsOn (int workcnt, qboolean showpacifier, void(*func)(int))
{
	int		i;
	pthread_t	work_threads[MAX_THREADS];
	pthread_addr_t	status;
	pthread_attr_t	attrib;
	pthread_mutexattr_t	mattrib;
	int		start, end;

	start = I_FloatTime ();
	dispatch = 0;
	workcount = workcnt;
	oldf = -1;
	pacifier = showpacifier;

	if (pacifier)
		setbuf (stdout, NULL);

	if (!my_mutex)
	{
		my_mutex = safe_malloc (sizeof(*my_mutex));
		if (pthread_mutexattr_create (&mattrib) == -1)
			Error ("pthread_mutex_attr_create failed");
		if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
			Error ("pthread_mutexattr_setkind_np failed");
		if (pthread_mutex_init (my_mutex, mattrib) == -1)
			Error ("pthread_mutex_init failed");
	}

	if (pthread_attr_create (&attrib) == -1)
		Error ("pthread_attr_create failed");
	if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
		Error ("pthread_attr_setstacksize failed");
	
	for (i=0 ; i<numthreads ; i++)
	{
  		if (pthread_create(&work_threads[i], attrib
		, (pthread_startroutine_t)func, (pthread_addr_t)i) == -1)
			Error ("pthread_create failed");
	}
		
	for (i=0 ; i<numthreads ; i++)
	{
		if (pthread_join (work_threads[i], &status) == -1)
			Error ("pthread_join failed");
	}

	end = I_FloatTime ();
	if (pacifier)
		Sys_Printf (" (%i)\n", end-start);
}
Ejemplo n.º 8
0
void InitThreads (void)
{
#ifdef __alpha
	pthread_mutexattr_t	mattrib;

	my_mutex = malloc (sizeof(*my_mutex));
	if (pthread_mutexattr_create (&mattrib) == -1)
		Error ("pthread_mutex_attr_create failed");
	if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
		Error ("pthread_mutexattr_setkind_np failed");
	if (pthread_mutex_init (my_mutex, mattrib) == -1)
		Error ("pthread_mutex_init failed");
#endif
}
Ejemplo n.º 9
0
mutex_t *MutexAlloc(void)
{
	pthread_mutex_t	*my_mutex;
	pthread_mutexattr_t	mattrib;

	if (numthreads == 1)
		return NULL;
	my_mutex = malloc (sizeof(*my_mutex));
	if (pthread_mutexattr_create (&mattrib) == -1)
		Error ("pthread_mutex_attr_create failed");
	if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
		Error ("pthread_mutexattr_setkind_np failed");
	if (pthread_mutex_init (my_mutex, mattrib) == -1)
		Error ("pthread_mutex_init failed");
	return (void *) my_mutex;
}
Ejemplo n.º 10
0
int
createMutex(Mutex_t& handle)
{
	pthread_mutexattr_t attr;
	int res = pthread_mutexattr_create(&attr);
	assert(res == 0);
	if (res != 0)
	{
		return -1;
	}

#if defined(BLOCXX_HAVE_PTHREAD_MUTEXATTR_SETTYPE)
	res = pthread_mutexattr_setkind_np(&attr, MUTEX_RECURSIVE_NP);
	assert(res == 0);
	if (res != 0)
	{
		pthread_mutexattr_delete(&attr);
		return -1;
	}
#endif

	res = pthread_mutex_init(&handle.mutex, attr);

	pthread_mutexattr_delete(&attr);
	if (res != 0)
	{
		return -1;
	}

#if !defined(BLOCXX_HAVE_PTHREAD_MUTEXATTR_SETTYPE)
	res = pthread_cond_init(&handle.unlocked, PTHREAD_COND_ATTR_DEFAULT);
	if (res != 0)
	{
		pthread_mutex_destroy(&handle.mutex);
		return -1;
	}

	handle.valid_id = false;
	handle.count = 0;
#endif
	return 0;
}
Ejemplo n.º 11
0
/*
==================
CalcPortalVis
==================
*/
void CalcPortalVis (void)
{
	int		i;

// fastvis just uses mightsee for a very loose bound
	if (fastvis)
	{
		for (i=0 ; i<numportals*2 ; i++)
		{
			portals[i].visbits = portals[i].mightsee;
			portals[i].status = stat_done;
		}
		return;
	}
	
	leafon = 0;
	
#ifdef __alpha
{
	pthread_t	work_threads[MAX_THREADS];
	pthread_addr_t	status;
	pthread_attr_t	attrib;
	pthread_mutexattr_t	mattrib;
	int		i;
	
	my_mutex = malloc (sizeof(*my_mutex));
	if (pthread_mutexattr_create (&mattrib) == -1)
		Error ("pthread_mutex_attr_create failed");
	if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
		Error ("pthread_mutexattr_setkind_np failed");
	if (pthread_mutex_init (my_mutex, mattrib) == -1)
		Error ("pthread_mutex_init failed");

	if (pthread_attr_create (&attrib) == -1)
		Error ("pthread_attr_create failed");
	if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
		Error ("pthread_attr_setstacksize failed");
	
	for (i=0 ; i<numthreads ; i++)
	{
  		if (pthread_create(&work_threads[i], attrib
		, LeafThread, (pthread_addr_t)i) == -1)
			Error ("pthread_create failed");
	}
		
	for (i=0 ; i<numthreads ; i++)
	{
		if (pthread_join (work_threads[i], &status) == -1)
			Error ("pthread_join failed");
	}

	if (pthread_mutex_destroy (my_mutex) == -1)
			Error ("pthread_mutex_destroy failed");
}
#else
	LeafThread (0);
#endif

	if (verbose)
	{
		printf ("portalcheck: %i  portaltest: %i  portalpass: %i\n",c_portalcheck, c_portaltest, c_portalpass);
		printf ("c_vistest: %i  c_mighttest: %i\n",c_vistest, c_mighttest);
	}

}
Ejemplo n.º 12
0
/*
 *  The main thread must call this function to convert itself into a thread.
 */
thread_t *
thread_initial (unsigned long stack_size)
{
  int rc;
  thread_t *thr = NULL;

  if (_main_thread)
    return _main_thread;

  /*
   *  Initialize pthread key
   */
#ifndef OLD_PTHREADS
  rc = pthread_key_create (&_key_current, NULL);
#else
  rc = pthread_keycreate (&_key_current, NULL);
#endif
  CKRET (rc);

  /*
   *  Start off with a value of NULL
   */
  rc = pthread_setspecific (_key_current, NULL);
  CKRET (rc);

  /*
   *  Initialize default thread/mutex attributes
   */
#ifndef OLD_PTHREADS
  /* attribute for thread creation */
  rc = pthread_attr_init (&_thread_attr);
  CKRET (rc);

  /* attribute for mutex creation */
  rc = pthread_mutexattr_init (&_mutex_attr);
  CKRET (rc);
#else
  rc = pthread_attr_create (&_thread_attr);
  CKRET (rc);

  rc = pthread_mutexattr_create (&_mutex_attr);
  CKRET (rc);
#endif

#if defined (PTHREAD_PROCESS_PRIVATE) && !defined(oldlinux) && !defined(__FreeBSD__)
  rc = pthread_mutexattr_setpshared (&_mutex_attr, PTHREAD_PROCESS_PRIVATE);
  CKRET (rc);
#endif

#if defined (MUTEX_FAST_NP) && !defined (_AIX)
  rc = pthread_mutexattr_setkind_np (&_mutex_attr, MUTEX_FAST_NP);
  CKRET (rc);
#endif

#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
  rc = pthread_mutexattr_settype (&_mutex_attr, PTHREAD_MUTEX_ADAPTIVE_NP);
  CKRET (rc);
#endif

  /*
   *  Allocate a thread structure
   */
  thr = (thread_t *) dk_alloc (sizeof (thread_t));
  memset (thr, 0, sizeof (thread_t));

  assert (_main_thread == NULL);
  _main_thread = thr;

  _sched_init ();

  if (stack_size == 0)
    stack_size = MAIN_STACK_SIZE;

#if (SIZEOF_VOID_P == 8)
  stack_size *= 2;
#endif
#if defined (__x86_64 ) && defined (SOLARIS)
  /*GK: the LDAP on that platform requires that */
  stack_size *= 2;
#endif


  stack_size = ((stack_size / 8192) + 1) * 8192;

  thr->thr_stack_size = stack_size;
  thr->thr_status = RUNNING;
  thr->thr_cv = _alloc_cv ();
  thr->thr_sem = semaphore_allocate (0);
  thr->thr_schedule_sem = semaphore_allocate (0);
  if (thr->thr_cv == NULL)
    goto failed;
  _thread_init_attributes (thr);
  thread_set_priority (thr, NORMAL_PRIORITY);

  rc = pthread_setspecific (_key_current, thr);
  CKRET (rc);

  return thr;

failed:
  if (thr)
    {
      _thread_free_attributes (thr);
      dk_free (thr, sizeof (thread_t));
    }
  return NULL;
}
Ejemplo n.º 13
0
static gdb_sLocal *
mapLocalDb (
  pwr_tStatus		*sts
)
{

#if defined OS_LYNX || defined OS_LINUX
  pthread_mutexattr_t	mattr;
#endif

  gdb_AssumeLocked;

  if (gdbroot->db->version != gdb_cVersion)
    pwr_Return(NULL, sts, GDH__REVLEVEL);

#ifdef	OS_ELN
  ELN$CREATE_MUTEX(gdbroot->thread_lock, NULL);

#elif defined(OS_LINUX) || defined(OS_LYNX) && !defined(PWR_LYNX_30)
  pthread_mutexattr_init(&mattr);
  if (pthread_mutex_init(&gdbroot->thread_lock, &mattr) == -1) {
    perror("mapLocalDb: pthread_mutex_init, ");
    pwr_Return(NULL, sts, GDB__MUTEXINIT);
  }

#elif defined OS_LYNX
  pthread_mutexattr_create(&mattr);
  if (pthread_mutex_init(&gdbroot->thread_lock, mattr) == -1) {
    perror("mapLocalDb: pthread_mutex_init, ");
    pwr_Return(NULL, sts, GDB__MUTEXINIT);
  }
#endif

  /* Map hash tables.  */

  gdbroot->oid_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.oid_ht, &gdbroot->db->h.oid_ht, NULL, NULL);
  if (gdbroot->oid_ht == NULL) errh_Bugcheck(*sts, "initiating oid hash table");

  gdbroot->vid_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.vid_ht, &gdbroot->db->h.vid_ht, NULL, NULL);
  if (gdbroot->vid_ht == NULL) errh_Bugcheck(*sts, "initiating vid hash table");

  gdbroot->vn_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.vn_ht, &gdbroot->db->h.vn_ht, NULL, NULL);
  if (gdbroot->vn_ht == NULL) errh_Bugcheck(*sts, "initiating vn hash table");

  gdbroot->nid_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.nid_ht, &gdbroot->db->h.nid_ht, NULL, NULL);
  if (gdbroot->nid_ht == NULL) errh_Bugcheck(*sts, "initiating nid hash table");

  gdbroot->cid_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.cid_ht, &gdbroot->db->h.cid_ht, NULL, NULL);
  if (gdbroot->cid_ht == NULL) errh_Bugcheck(*sts, "initiating cid hash table");

  gdbroot->tid_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.tid_ht, &gdbroot->db->h.tid_ht, NULL, NULL);
  if (gdbroot->tid_ht == NULL) errh_Bugcheck(*sts, "initiating tid hash table");

  gdbroot->family_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.family_ht, &gdbroot->db->h.family_ht, NULL, NULL);
  if (gdbroot->family_ht == NULL) errh_Bugcheck(*sts, "initiating family hash table");

  gdbroot->ms_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.ms_ht, &gdbroot->db->h.ms_ht, NULL, NULL);
  if (gdbroot->ms_ht == NULL) errh_Bugcheck(*sts, "initiating mount server hash table");

  gdbroot->as_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.as_ht, &gdbroot->db->h.as_ht, NULL, NULL);
  if (gdbroot->as_ht == NULL) errh_Bugcheck(*sts, "initiating alias server hash table");

  gdbroot->subc_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.subc_ht, &gdbroot->db->h.subc_ht, NULL, NULL);
  if (gdbroot->subc_ht == NULL) errh_Bugcheck(*sts, "initiating subscription client hash table");

  gdbroot->subs_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.subs_ht, &gdbroot->db->h.subs_ht, NULL, NULL);
  if (gdbroot->subs_ht == NULL) errh_Bugcheck(*sts, "initiating subscription server hash table");

  gdbroot->sans_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.sans_ht, &gdbroot->db->h.sans_ht, NULL, NULL);
  if (gdbroot->sans_ht == NULL) errh_Bugcheck(*sts, "initiating subscribed alarm notification server hash table");

  gdbroot->ccvol_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.ccvol_ht, &gdbroot->db->h.ccvol_ht, NULL, NULL);
  if (gdbroot->ccvol_ht == NULL) errh_Bugcheck(*sts, "initiating cached class volume hash table");

  gdbroot->cclass_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.cclass_ht, &gdbroot->db->h.cclass_ht, NULL, NULL);
  if (gdbroot->cclass_ht == NULL) errh_Bugcheck(*sts, "initiating cached class hash table");

  gdbroot->sc_ht = hash_Create(sts, gdbroot->pool, &gdbroot->h.sc_ht, &gdbroot->db->h.sc_ht, NULL, NULL);
  if (gdbroot->sc_ht == NULL) errh_Bugcheck(*sts, "initiating sub class object hash table");

  gdbroot->catt_tt = ptree_Create(sts, gdbroot->pool, &gdbroot->t.catt_tt, &gdbroot->db->t.catt_tt,
				  compCatt);
  if (gdbroot->catt_tt == NULL) errh_Bugcheck(*sts, "initiating class attribute tree table");

  if (offsetof(sub_sClient, sid) != offsetof(sub_sServer, sid))
    errh_Bugcheck(GDH__WEIRD, "offset id: client - server");
  if (offsetof(sub_sClient, sid) != offsetof(dl_sLink, dlid))
    errh_Bugcheck(GDH__WEIRD, "offset id: client - dlink");
  if (offsetof(sub_sClient, subc_htl) != offsetof(sub_sServer, subs_htl))
    errh_Bugcheck(GDH__WEIRD, "offset htl: client - server");
  if (offsetof(sub_sClient, subc_htl) != offsetof(dl_sLink, subc_htl))
    errh_Bugcheck(GDH__WEIRD, "offset htl: client - dlink");
  if ((offsetof(gdb_sNobject, flags) - offsetof(gdb_sNobject, cid_ll)) 
      != (offsetof(gdb_sScObject, flags) - offsetof(gdb_sScObject, cid_ll)))
    errh_Bugcheck(GDH__WEIRD, "offset between cid_ll and flags in gdb_sNobject and gdb_sScObject");
  if (gdb_mNo_isSc != gdb_mSc_isSc)
    errh_Bugcheck(GDH__WEIRD, "gdb_mNo_isSubClass != gdb_mSc_isSubClass");

  return gdbroot;  
}