Beispiel #1
1
//-------------------------------------------------------------------------
//
// Create a new thread and run the message pump in there
//
//-------------------------------------------------------------------------
void nsToolkit::CreateUIThread()
{
  PRMonitor *monitor = ::PR_NewMonitor();
	
  PR_EnterMonitor(monitor);
	
  ThreadInitInfo *ti = new ThreadInitInfo();
  if (ti)
  {
    ti->monitor = monitor;
    ti->toolkit = this;
  
    // create a gui thread
    mGuiThread = PR_CreateThread(PR_SYSTEM_THREAD,
                                   RunPump,
                                   (void*)ti,
                                   PR_PRIORITY_HIGH,
                                   PR_LOCAL_THREAD,
                                   PR_UNJOINABLE_THREAD,
                                   0);

    // wait for the gui thread to start
    while(gThreadState == PR_FALSE)
    {
      PR_Wait(monitor, PR_INTERVAL_NO_TIMEOUT);
    }
  }
    
  image_info iinfo;
  int32 cookie = 0;
  char *leaf = NULL;
  do {
    if (get_next_image_info(0, &cookie, &iinfo) == B_OK &&
        strlen(iinfo.name) > 0 &&
        (leaf = strrchr(iinfo.name, '/')) != NULL)
    {
      leaf++;
      mGUIThreadID = find_thread(leaf);
    }
    else
    {
      mGUIThreadID = find_thread(0);
    }    
  } while(iinfo.type != B_APP_IMAGE);
  // at this point the thread is running
  PR_ExitMonitor(monitor);
  PR_DestroyMonitor(monitor);
}
Beispiel #2
0
/*
 * The write-thread is spawned on a timeout(which is reset with every write). This
 * can avoid a slow shutdown. After writing out the cache, the zipreader is
 * reloaded on the worker thread.
 */
void
StartupCache::WriteTimeout(nsITimer *aTimer, void *aClosure)
{
  gStartupCache->mWriteThread = PR_CreateThread(PR_USER_THREAD,
                                                StartupCache::ThreadedWrite,
                                                NULL,
                                                PR_PRIORITY_NORMAL,
                                                PR_LOCAL_THREAD,
                                                PR_JOINABLE_THREAD,
                                                0);
}
Beispiel #3
0
nsresult
ClosingService::StartInternal()
{
    mThread = PR_CreateThread(PR_USER_THREAD, ThreadFunc, this,
                              PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
                              PR_JOINABLE_THREAD, 32 * 1024);
    if (!mThread) {
        return NS_ERROR_FAILURE;
    }
    return NS_OK;
}
Beispiel #4
0
PRIntn main ()
{
    PRUint32 elapsed;
    PRThread *thread;
	struct timeval timein, timeout;
    PRInt32 onePercent = 3000000UL / 100UL;

	fprintf (stderr, "First sleep will sleep 3 seconds.\n");
	fprintf (stderr, "   sleep 1 begin\n");
    (void)GTOD(&timein);
	sleep (3);
    (void)GTOD(&timeout);
	fprintf (stderr, "   sleep 1 end\n");
    elapsed = 1000000UL * (timeout.tv_sec - timein.tv_sec);
    elapsed += (timeout.tv_usec - timein.tv_usec);
    fprintf(stderr, "elapsed %u usecs\n", elapsed);
    if (labs(elapsed - 3000000UL) > onePercent) rv = 1;

	PR_Init (PR_USER_THREAD, PR_PRIORITY_NORMAL, 100);
    PR_STDIO_INIT();

	fprintf (stderr, "Second sleep should do the same (does it?).\n");
	fprintf (stderr, "   sleep 2 begin\n");
    (void)GTOD(&timein);
	sleep (3);
    (void)GTOD(&timeout);
	fprintf (stderr, "   sleep 2 end\n");
    elapsed = 1000000UL * (timeout.tv_sec - timein.tv_sec);
    elapsed += (timeout.tv_usec - timein.tv_usec);
    fprintf(stderr, "elapsed %u usecs\n", elapsed);
    if (labs(elapsed - 3000000UL) > onePercent) rv = 1;

	fprintf (stderr, "What happens to other threads?\n");
	fprintf (stderr, "You should see dots every quarter second.\n");
	fprintf (stderr, "If you don't, you're probably running on classic NSPR.\n");
    thread = PR_CreateThread(
        PR_USER_THREAD, Other, NULL, PR_PRIORITY_NORMAL,
        PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
	fprintf (stderr, "   sleep 2 begin\n");
    (void)GTOD(&timein);
	sleep (3);
    (void)GTOD(&timeout);
	fprintf (stderr, "   sleep 2 end\n");
    PR_Interrupt(thread);
    PR_JoinThread(thread);
    elapsed = 1000000UL * (timeout.tv_sec - timein.tv_sec);
    elapsed += (timeout.tv_usec - timein.tv_usec);
    fprintf(stderr, "elapsed %u usecs\n", elapsed);
    if (labs(elapsed - 3000000UL) > onePercent) rv = 1;
    fprintf(stderr, "%s\n", (0 == rv) ? "PASSED" : "FAILED");
    return rv;
}
Beispiel #5
0
thread_t thread_create(thread_proc_t start, void *param) {
  thread_t *rv;
  return (thread_t)PR_CreateThread(
    PR_USER_THREAD,
    start,
    param,
    PR_PRIORITY_LOW,
    PR_GLOBAL_THREAD,
    PR_JOINABLE_THREAD,
    0
    );
  return rv;
}
static void T1CMon(void)
{
    PRStatus rv;
    PRThread *t2, *t3;

    PR_fprintf(err, "\n**********************************\n");
    PR_fprintf(err, "         CACHED MONITORS\n");
    PR_fprintf(err, "**********************************\n");

    base =  PR_IntervalNow();

    PR_CEnterMonitor(&sharedCM.o1);
    LogNow("T1 waiting 3 seconds on o1", PR_SUCCESS);
    rv = PR_CWait(&sharedCM.o1, PR_SecondsToInterval(3));
    if (PR_SUCCESS == rv) LogNow("T1 resuming on o1", rv);
    else LogNow("T1 wait on o1 failed", rv);
    PR_CExitMonitor(&sharedCM.o1);

    LogNow("T1 creating T2", PR_SUCCESS);
    t2 = PR_CreateThread(
        PR_USER_THREAD, T2CMon, &sharedCM, PR_PRIORITY_NORMAL,
        PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);

    LogNow("T1 creating T3", PR_SUCCESS);
    t3 = PR_CreateThread(
        PR_USER_THREAD, T3CMon, &sharedCM, PR_PRIORITY_NORMAL,
        PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);

    PR_CEnterMonitor(&sharedCM.o2);
    LogNow("T1 waiting forever on o2", PR_SUCCESS);
    rv = PR_CWait(&sharedCM.o2, PR_INTERVAL_NO_TIMEOUT);
    if (PR_SUCCESS == rv) LogNow("T1 resuming on o2", rv);
    else LogNow("T1 wait on o2 failed", rv);
    PR_CExitMonitor(&sharedCM.o2);

    (void)PR_JoinThread(t2);
    (void)PR_JoinThread(t3);

}  /* T1CMon */
Beispiel #7
0
/*
 * eq_start: start the event queue system. 
 * 
 * This should be called exactly once. It will start a
 * thread which wakes up periodically and schedules events.
 */
void
eq_start()
{
	PR_ASSERT(eq_initialized);
	eq_running = 1;
	if ((eq_loop_tid = PR_CreateThread(PR_USER_THREAD, (VFP)eq_loop,
			NULL, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD,
			SLAPD_DEFAULT_THREAD_STACKSIZE)) == NULL) {
		slapi_log_error(SLAPI_LOG_FATAL, NULL, "eq_init PR_CreateThread failed\n");
		exit(1);
	}
	slapi_log_error(SLAPI_LOG_HOUSE, NULL, "event queue services have started\n");
}
Beispiel #8
0
GraphRunner::GraphRunner(MediaStreamGraphImpl* aGraph)
    : mMonitor("GraphRunner::mMonitor"),
      mGraph(aGraph),
      mStateEnd(0),
      mStillProcessing(true),
      mThreadState(ThreadState::Wait),
      // Note that mThread needs to be initialized last, as it may pre-empt the
      // thread running this ctor and enter Run() with uninitialized members.
      mThread(PR_CreateThread(PR_SYSTEM_THREAD, &Start, this,
                              PR_PRIORITY_URGENT, PR_GLOBAL_THREAD,
                              PR_JOINABLE_THREAD, 0)) {
  MOZ_COUNT_CTOR(GraphRunner);
}
Beispiel #9
0
/*
 * add a job to the work queue
 */
static void
add_to_jobq(PRThreadPool *tp, PRJob *jobp)
{
	/*
	 * add to jobq
	 */
#ifdef OPT_WINNT
	PR_Lock(tp->jobq.lock);
	tp->jobq.cnt++;
	PR_Unlock(tp->jobq.lock);
	/*
	 * notify worker thread(s)
	 */
	PostQueuedCompletionStatus(tp->jobq.nt_completion_port, 0,
            FALSE, &jobp->nt_notifier.overlapped);
#else
	PR_Lock(tp->jobq.lock);
	PR_APPEND_LINK(&jobp->links,&tp->jobq.list);
	tp->jobq.cnt++;
	if ((tp->idle_threads < tp->jobq.cnt) &&
					(tp->current_threads < tp->max_threads)) {
		wthread *wthrp;
		/*
		 * increment thread count and unlock the jobq lock
		 */
		tp->current_threads++;
		PR_Unlock(tp->jobq.lock);
		/* create new worker thread */
		wthrp = PR_NEWZAP(wthread);
		if (wthrp) {
			wthrp->thread = PR_CreateThread(PR_USER_THREAD, wstart,
						tp, PR_PRIORITY_NORMAL,
						PR_GLOBAL_THREAD,PR_JOINABLE_THREAD,tp->stacksize);
			if (NULL == wthrp->thread) {
				PR_DELETE(wthrp);  /* this sets wthrp to NULL */
			}
		}
		PR_Lock(tp->jobq.lock);
		if (NULL == wthrp) {
			tp->current_threads--;
		} else {
			PR_APPEND_LINK(&wthrp->links, &tp->jobq.wthreads);
		}
	}
	/*
	 * wakeup a worker thread
	 */
	PR_NotifyCondVar(tp->jobq.cv);
	PR_Unlock(tp->jobq.lock);
#endif
}
BackgroundHangManager::BackgroundHangManager()
  : mShutdown(false)
  , mLock("BackgroundHangManager")
  , mIntervalNow(0)
{
  // Lock so we don't race against the new monitor thread
  MonitorAutoLock autoLock(mLock);
  mHangMonitorThread = PR_CreateThread(
    PR_USER_THREAD, MonitorThread, this,
    PR_PRIORITY_LOW, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);

  MOZ_ASSERT(mHangMonitorThread,
    "Failed to create monitor thread");
}
static PRTime
CalculateProcessCreationTimestamp()
{
 PRThread *thread = PR_CreateThread(PR_USER_THREAD,
                                    ThreadedCalculateProcessCreationTimestamp,
                                    NULL,
                                    PR_PRIORITY_NORMAL,
                                    PR_LOCAL_THREAD,
                                    PR_JOINABLE_THREAD,
                                    0);

  PR_JoinThread(thread);
  return gProcessCreationTimestamp;
}
Beispiel #12
0
nsresult
VideoSourceCanvas::Start(nsIDOMCanvasRenderingContext2D *ctx)
{
    if (!g2g)
        return NS_ERROR_FAILURE;

    vCanvas = ctx;
    running = PR_TRUE;
    sampler = PR_CreateThread(
        PR_SYSTEM_THREAD, VideoSourceCanvas::Grabber, this,
        PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0
    );
    return NS_OK;
}
Beispiel #13
0
NPError
nsPluginInstance::DestroyStream(NPStream *stream, NPError reason)
{
    DBG("nsPluginInstance::DestroyStream\n");
    DBG("stream->url: %s\n", stream->url);

    // N.B. We can only support one Gnash VM/thread right now. 
    if (!_thread) {
        _thread = PR_CreateThread(PR_USER_THREAD, playerThread, this,
                PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
    }

    return NPERR_NO_ERROR;
}
uint64_t
TimeStamp::ComputeProcessUptime()
{
  uint64_t uptime = 0;
  PRThread *thread = PR_CreateThread(PR_USER_THREAD,
                                     ComputeProcessUptimeThread,
                                     &uptime,
                                     PR_PRIORITY_NORMAL,
                                     PR_LOCAL_THREAD,
                                     PR_JOINABLE_THREAD,
                                     0);

  PR_JoinThread(thread);

  return uptime / kNsPerUs;
}
Beispiel #15
0
void NeverStops(void *unused)
{
    int i = 0;

    printf("The child sproc has pid %d.\n", getpid());
    printf("The child sproc won't stop on its own.\n");
    fflush(stdout);

    /* create the grandchild sproc */
    PR_CreateThread(PR_USER_THREAD, SegFault, NULL,
	    PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);

    while (1) {
	i++;
    }
}
JD_METHOD_(void*)  CNSAdapter_NSPR::JD_CreateThread(JDThreadType type,
						     void (*start)(void* arg),
						     void* arg,
						     JDThreadPriority priority,
						     JDThreadScope    scope,
						     JDThreadState    state,
						     JDUint32 stackSize)
{
  return PR_CreateThread((PRThreadType)type,
			 start,
			 arg,
			 (PRThreadPriority)priority,
			 (PRThreadScope)scope,
			 (PRThreadState)state,
			 (PRUint32)stackSize);
}
void
thread_test(PRInt32 scope, PRInt32 num_threads)
{
    PRInt32 index;
    PRThread *thr;
    PRLock *dead_lock;
    PRCondVar *dead_cv;
    PRInt32 alive;

    if (debug_mode) printf("IO Timeout test started with %d threads\n", num_threads);

    dead_lock = PR_NewLock();
    dead_cv = PR_NewCondVar(dead_lock);
    alive = num_threads;
    
    for (index = 0; index < num_threads; index++) {
        threadInfo *info = (threadInfo *)malloc(sizeof(threadInfo));

        info->id = index;
        info->dead_lock = dead_lock;
        info->dead_cv = dead_cv;
        info->alive = &alive;
        info->accept_timeout = DEFAULT_ACCEPT_TIMEOUT;
        
        thr = PR_CreateThread( PR_USER_THREAD,
                               thread_main,
                               (void *)info,
                               PR_PRIORITY_NORMAL,
                               scope,
                               PR_UNJOINABLE_THREAD,
                               0);

        if (!thr) {
            PR_Lock(dead_lock);
            alive--;
            PR_Unlock(dead_lock);
        }
    }

    PR_Lock(dead_lock);
    while(alive) {
        if (debug_mode) printf("main loop awake; alive = %d\n", alive);
        PR_WaitCondVar(dead_cv, PR_INTERVAL_NO_TIMEOUT);
    }
    PR_Unlock(dead_lock);
}
Beispiel #18
0
int main(int argc, const char *argv[]) {
    if(argc == 1) {
        printf("Usage: threads count");
        return 1;
    }

    GLOBAL_STATE = atoi(argv[1]);
    RUN_THREADED = atoi(argv[2]);
    NUM_THREADS = atoi(argv[3]);

    int i;
    thread_info* threads[NUM_THREADS];

    START_TIME

    for(i=0; i<NUM_THREADS; i++) {
        thread_info *ti = (thread_info*)malloc(sizeof(thread_info));
        ti->n = i;

        ti->thread = PR_CreateThread(PR_USER_THREAD, run, (void*)ti, 1000,
                                     PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);

        if(!RUN_THREADED) {
            PR_JoinThread(ti->thread);
        }

        threads[i] = ti;
    }

    for(i=0; i<NUM_THREADS; i++) {
        thread_info *ti = threads[i];

        if(RUN_THREADED) {
            PR_JoinThread(ti->thread);
        }

        free(ti);
        threads[i] = NULL;
    }

    END_TIME
    printf("%d\n", TIMER);

    return 0;
}
Beispiel #19
0
bool InitEventTracing()
{
    // Initialize the widget backend.
    if (!InitWidgetTracing())
        return false;

    // Create a thread that will fire events back at the
    // main thread to measure responsiveness.
    NS_ABORT_IF_FALSE(!sTracerThread, "Event tracing already initialized!");
    sTracerThread = PR_CreateThread(PR_USER_THREAD,
                                    TracerThread,
                                    NULL,
                                    PR_PRIORITY_NORMAL,
                                    PR_GLOBAL_THREAD,
                                    PR_JOINABLE_THREAD,
                                    0);
    return sTracerThread != NULL;
}
static
void *XpuPrintToFile( Display *pdpy, XPContext pcontext, const char *filename )
{
  MyPrintFileData *mpfd; /* warning: shared between threads !! */
         
  if( (mpfd = malloc(sizeof(MyPrintFileData))) == NULL )
    return(NULL);
  
  mpfd->parent_pdpy = pdpy;
  mpfd->displayname = XDisplayString(pdpy);
  mpfd->pdpy        = NULL;
  mpfd->pcontext    = pcontext;
  mpfd->file_name   = filename;
  mpfd->file        = NULL;      
  mpfd->status      = XPGetDocError;
  
  /* make sure we can open the file for writing */
  if( (mpfd->file = fopen(mpfd->file_name, "w")) == NULL ) 
  {
    /* fopen() error */
    free(mpfd);
    return(NULL);
  }
  
  /* its important to flush before we start the consumer thread, 
   * to make sure that the XpStartJob gets through first in the parent
   */
  XFlush(pdpy);
#ifdef XPU_USE_NSPR
  if( (mpfd->prthread = PR_CreateThread(PR_SYSTEM_THREAD, PrintToFile_Consumer, mpfd, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0)) == NULL )
#else    
  if( pthread_create(&(mpfd->tid), NULL, PrintToFile_Consumer, mpfd) != 0 ) 
#endif
  {
    /* pthread_create() error */
    fclose(mpfd->file);
    free(mpfd);
    return(NULL);
  }
  
  /* we're still in the parent */
  XPU_DEBUG_ONLY(printf("### parent started consumer thread.\n" ));
  return(mpfd);
}
Beispiel #21
0
int main(PRIntn argc, const char **argv)
{
    PRThread *thread;

    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    PR_STDIO_INIT();

#ifndef XP_MAC
    if (argc > 1)
    {
        if (!PR_SetLogFile(argv[1]))
        {
            Error("Access: Cannot create log file");
            goto exit;
        }
    }
#else
	SetupMacPrintfLog("logger.log");
#endif

    /* Start logging something here */
    PR_LogPrint("%s logging into %s\n", argv[0], argv[1]);

    PR_LogPrint("%s creating new thread\n", argv[0]);

    /*
    ** Now change buffering.
    */
    PR_SetLogBuffering( 65500 );    
	thread = PR_CreateThread(
	    PR_USER_THREAD, forked, (void*)argv[0], PR_PRIORITY_NORMAL,
	    PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
    PR_LogPrint("%s joining thread\n", argv[0]);

    UserLogStuff();

    PR_JoinThread(thread);

    PR_LogFlush();
    return 0;

exit:
    return -1;
}
Beispiel #22
0
static void Server(void)
{
    PRStatus rv;
    PRNetAddr server_address, client_address;
    PRFileDesc *xport = PR_Socket(domain, PR_SOCK_STREAM, protocol);

    if (NULL == xport)
    {
        PL_FPrintError(err, "PR_Socket");
        return;
    }

    rv = PR_InitializeNetAddr(PR_IpAddrAny, PORT_NUMBER, &server_address);
    if (PR_FAILURE == rv) PL_FPrintError(err, "PR_InitializeNetAddr");
    else
    {
        rv = PR_Bind(xport, &server_address);
        if (PR_FAILURE == rv) PL_FPrintError(err, "PR_Bind");
        else
        {
            PRFileDesc *client;
            rv = PR_Listen(xport, 10);
            PR_fprintf(err, "Server listening on ");
            (void)PrintAddress(&server_address);
            do
            {
                client = PR_Accept(
                    xport, &client_address, PR_INTERVAL_NO_TIMEOUT);
                if (NULL == client) PL_FPrintError(err, "PR_Accept");
                else
                {
                    PR_fprintf(err, "Server accepting from ");
                    (void)PrintAddress(&client_address);
                    shared->threads += 1;
                    (void)PR_CreateThread(
                        PR_USER_THREAD, Servette, client,
                        PR_PRIORITY_NORMAL, thread_scope,
                        PR_UNJOINABLE_THREAD, 8 * 1024);
                }
            } while (PR_TRUE);

        }
    }
}  /* Server */
Beispiel #23
0
/*
 * The write-thread is spawned on a timeout(which is reset with every write). This
 * can avoid a slow shutdown. After writing out the cache, the zipreader is
 * reloaded on the worker thread.
 */
void
StartupCache::WriteTimeout(nsITimer *aTimer, void *aClosure)
{
  /*
   * It is safe to use the pointer passed in aClosure to reference the
   * StartupCache object because the timer's lifetime is tightly coupled to
   * the lifetime of the StartupCache object; this timer is canceled in the
   * StartupCache destructor, guaranteeing that this function runs if and only
   * if the StartupCache object is valid.
   */
  StartupCache* startupCacheObj = static_cast<StartupCache*>(aClosure);
  startupCacheObj->mWriteThread = PR_CreateThread(PR_USER_THREAD,
                                                  StartupCache::ThreadedWrite,
                                                  startupCacheObj,
                                                  PR_PRIORITY_NORMAL,
                                                  PR_GLOBAL_THREAD,
                                                  PR_JOINABLE_THREAD,
                                                  0);
}
Beispiel #24
0
/*
 * End recording
 */
NS_IMETHODIMP
MediaRecorder::EndRecording()
{
    if (!a_rec && !v_rec) {
        NS_DispatchToMainThread(new MediaCallback(
            observer, "error", "no recording in progress"
        ));
        return NS_ERROR_FAILURE;
    }
    
    PR_CreateThread(
        PR_SYSTEM_THREAD,
        MediaRecorder::EndRecordingThread, this,
        PR_PRIORITY_NORMAL,
        PR_GLOBAL_THREAD,
        PR_JOINABLE_THREAD, 0
    );
    return NS_OK;
}
Beispiel #25
0
int main()
{
    int i= 0;

    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);

    printf("The parent sproc has pid %d.\n", getpid());
    printf("The parent sproc won't stop on its own.\n");
    fflush(stdout);

    /* create the child sproc */
    PR_CreateThread(PR_USER_THREAD, NeverStops, NULL,
	    PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);

    while (1) {
	i++;
    }
    return 0;
}
void HRTFDatabaseLoader::loadAsynchronously()
{
    MOZ_ASSERT(NS_IsMainThread());
    MOZ_ASSERT(m_refCnt, "Must not be called before a reference is added");

    // Add a reference so that the destructor won't run and wait for the
    // loader thread, until load() has completed.
    AddRef();

    MutexAutoLock locker(m_threadLock);
    
    MOZ_ASSERT(!m_hrtfDatabase.get() && !m_databaseLoaderThread,
               "Called twice");
    // Start the asynchronous database loading process.
    m_databaseLoaderThread =
        PR_CreateThread(PR_USER_THREAD, databaseLoaderEntry, this,
                        PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
                        PR_JOINABLE_THREAD, 0);
}
Beispiel #27
0
static PRStatus TimerInit(void)
{
    tm_vars.ml = PR_NewLock();
    if (NULL == tm_vars.ml)
    {
        goto failed;
    }
    tm_vars.new_timer = PR_NewCondVar(tm_vars.ml);
    if (NULL == tm_vars.new_timer)
    {
        goto failed;
    }
    tm_vars.cancel_timer = PR_NewCondVar(tm_vars.ml);
    if (NULL == tm_vars.cancel_timer)
    {
        goto failed;
    }
    PR_INIT_CLIST(&tm_vars.timer_queue);
    tm_vars.manager_thread = PR_CreateThread(
        PR_SYSTEM_THREAD, TimerManager, NULL, PR_PRIORITY_NORMAL,
        PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
    if (NULL == tm_vars.manager_thread)
    {
        goto failed;
    }
    return PR_SUCCESS;

failed:
    if (NULL != tm_vars.cancel_timer)
    {
        PR_DestroyCondVar(tm_vars.cancel_timer);
    }
    if (NULL != tm_vars.new_timer)
    {
        PR_DestroyCondVar(tm_vars.new_timer);
    }
    if (NULL != tm_vars.ml)
    {
        PR_DestroyLock(tm_vars.ml);
    }
    return PR_FAILURE;
}
Beispiel #28
0
static PRUint32 ContentiousMonitor(PRUint32 loops)
{
    PRStatus status;
    PRThread *thread = NULL;
    MonitorContentious_t * contention;
    PRIntervalTime rv, overhead, timein = PR_IntervalNow();

    contention = PR_NEWZAP(MonitorContentious_t);
    contention->loops = loops;
    contention->overhead = 0;
    contention->ml = PR_NewMonitor();
    contention->interval = contention_interval;
    thread = PR_CreateThread(
        PR_USER_THREAD, MonitorContender, contention,
        PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
    PR_ASSERT(thread != NULL);

    overhead = PR_IntervalNow() - timein;

    while (contention->loops-- > 0)
    {
        PR_EnterMonitor(contention->ml);
        PR_ASSERT_CURRENT_THREAD_IN_MONITOR(contention->ml);
        contention->contentious+= 1;
        contention->overhead += contention->interval;
        PR_Sleep(contention->interval);
        PR_ASSERT_CURRENT_THREAD_IN_MONITOR(contention->ml);
        PR_ExitMonitor(contention->ml);
    }

    timein = PR_IntervalNow();
    status = PR_JoinThread(thread);
    PR_DestroyMonitor(contention->ml);
    overhead += (PR_IntervalNow() - timein);
    rv = overhead + contention->overhead;
    if (verbosity)
        PR_fprintf(
            std_err, "Access ratio: %u to %u\n",
            contention->contentious, contention->contender);
    PR_Free(contention);
    return rv;
}  /* ContentiousMonitor */
Beispiel #29
0
int main(int argc, char **argv)
{
    PRThread *thread;
    PRIntervalTime start, end;
    PRUint32 elapsed_ms;

    lock1 = PR_NewLock();
    PR_ASSERT(NULL != lock1);
    cv1 = PR_NewCondVar(lock1);
    PR_ASSERT(NULL != cv1);
    lock2 = PR_NewLock();
    PR_ASSERT(NULL != lock2);
    cv2 = PR_NewCondVar(lock2);
    PR_ASSERT(NULL != cv2);
    start = PR_IntervalNow();
    thread = PR_CreateThread(
            PR_USER_THREAD,
            ThreadFunc,
            NULL,
            PR_PRIORITY_NORMAL,
            PR_LOCAL_THREAD,
            PR_JOINABLE_THREAD,
            0);
    PR_ASSERT(NULL != thread);
    PR_Lock(lock2);
    PR_WaitCondVar(cv2, PR_MillisecondsToInterval(LONG_TIMEOUT));
    PR_Unlock(lock2);
    PR_JoinThread(thread);
    end = PR_IntervalNow();
    elapsed_ms = PR_IntervalToMilliseconds((PRIntervalTime)(end - start));
    /* Allow 100ms imprecision */
    if (elapsed_ms < LONG_TIMEOUT - 100 || elapsed_ms > LONG_TIMEOUT + 100) {
        printf("Elapsed time should be %u ms but is %u ms\n",
                LONG_TIMEOUT, elapsed_ms);
        printf("FAIL\n");
        exit(1);
    }
	printf("Elapsed time: %u ms, expected time: %u ms\n",
               LONG_TIMEOUT, elapsed_ms);
    printf("PASS\n");
    return 0;
}
Beispiel #30
0
int main()
{
    int *p = 0;

    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);

    printf("The parent sproc has pid %d.\n", getpid());
    printf("The parent sproc will first create a child sproc.\n");
    printf("Then the parent sproc will get a segmentation fault and die.\n");
    printf("The child sproc should be killed after the parent sproc dies.\n");
    printf("Use 'ps' to make sure this is so.\n");
    fflush(stdout);

    PR_CreateThread(PR_USER_THREAD, NeverStops, NULL,
	    PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);

    /* Force a segmentation fault */
    *p = 0;
    return 0;
}