Exemple #1
0
static void test_parallel(void)
{
	sthread_t st[2];
	sc_t sc[2];
	int p[2];
	void *ret;

	if (pipe(p) == -1)
		err(1, "pipe()");

	sc_init(&sc[0]);
	sc_fd_add(&sc[0], p[0], PROT_READ | PROT_WRITE);

	if (sthread_create(&st[0], &sc[0], parallel_read, (void*) (long) p[0]))
		err(1, "sthread_create()");

	sc_init(&sc[1]);
	sc_fd_add(&sc[1], p[1], PROT_READ | PROT_WRITE);

	if (sthread_create(&st[1], &sc[1], parallel_write, (void*) (long) p[1]))
		err(1, "sthread_create()");

	if (sthread_join(st[0], &ret) == -1)
		err(1, "sthread_join()");

	if (sthread_join(st[1], NULL) == -1)
		err(1, "sthread_join()");

	if (ret != (void*) 0x666)
		errx(1, "ret is %p", ret);

	close(p[0]);
	close(p[1]);
}
int main(int argc, char **argv)
{
  int counter0 = 0;
  int c1, c2;


  sthread_init();

  if (sthread_create(thread_1, (void*)0, 10) == NULL) {
    printf("sthread_create failed\n");
    exit(1);
  }

  if (sthread_create(thread_2, (void*)0, 1) == NULL) {
    printf("sthread_create failed\n");
    exit(1);
  }

  printf("created threads\n");

  for(; counter0 < 30000000; counter0++);

  c1 = counter1;
  c2 = counter2;
  printf("1: %i, 2: %i\n", c1, c2);
  printf("2/1: %f\n", ((float)c2)/c1);

  if (c2/c1 >= 6 && c2/c1 <= 14)
    printf("PASSED\n");

  return 0;
}
int main(int argc, char **argv)
{
  printf("Testing sthread_create, impl: %s\n",
	 (sthread_get_impl() == STHREAD_PTHREAD_IMPL) ? "pthread" : "user");
	
  sthread_init();
    
  if (sthread_create(thread1, (void*)1, 10) == NULL) {
    printf("sthread_create failed\n");
    exit(-1);
  }
    
  if (sthread_create(thread2, (void*)1, 10) == NULL) {
    printf("sthread_create failed\n");
    exit(-1);
  }

  printf("in main\n");
  sthread_sleep(10000);
  
  printf("\ntwo threads runqueue active in priority 10\n");
  sthread_dump();
  sthread_sleep(10000);

  printf("\ntwo threads runqueue active in priority 10\n");
  sthread_dump();

  printf("out main\n");

  return 0;
}
int main(int argc, char **argv)
{
  int j;

   int count = argc > 1 ? atoi(argv[1]) : 100;
   printf("Testing time slice and mutexes, impl: %s\n",
      (sthread_get_impl() == STHREAD_PTHREAD_IMPL) ? "pthread" : "user");

   sthread_init();

   if (sthread_create(thread_1, (void*)count, 1) == NULL) {
      printf("sthread_create failed\n");
      exit(1);
   }

   if (sthread_create(thread_2, (void*)count, 1) == NULL) {
      printf("sthread_create failed\n");
      exit(1);
   }
   printf("created two threads\n");

   printf("if this is the last line of output, time slices aren't working!\n");

   while(!t1_complete || !t2_complete);

   printf("PASSED\n");
   return 0;
}
Exemple #5
0
int main(void)
{
        printf("executing main function yeasss!!!!!!!\n");
        sthread_t p,q,r;
        sthread_mutex_init(&m);
        sthread_create(&p,f1,NULL);
        sthread_create(&q,f2,NULL);
        sthread_create(&r,f3,NULL);
        sthread_join(-1);
        printf("\nmain finished ans: %d \n",sum);
        return 0;
}
Exemple #6
0
/*
 * The main function starts the two producers and the consumer,
 * the starts the thread scheduler.
 */
int main(int argc, char **argv) {
    queue = new_bounded_buffer(DEFAULT_BUFFER_LENGTH);
    sthread_create(producer, (void *) 0);
    sthread_create(producer, (void *) 1);
    sthread_create(consumer, (void *) 0);

    /*
     * Start the thread scheduler.  By default, the timer is
     * not started.  Change the argument to 1 to start the timer.
     */
    sthread_start(1);
    return 0;
}
Exemple #7
0
/*
 * Runs four different threads that return at different times in order
 * to ensure that they all terminate properly without error.
 */
int main(int argc, char **argv) {
    int a = 1;
    int b = 2;
    int c = 3;
    int d = 4;
    /* Running threads */
    sthread_create(test, &a);
    sthread_create(test, &b);
    sthread_create(test, &c);
    sthread_create(test, &d);
    sthread_start();
    return 0;
}
int main(int argc, char **argv)
{
  void *ret;
  int i;

  printf("Testing sthreads, impl: %s\n",
	 (sthread_get_impl() == STHREAD_PTHREAD_IMPL) ? "pthread" : "user");
	
  sthread_init();

  mon1 = sthread_monitor_init();
  mon2 = sthread_monitor_init();

    
  if (sthread_create(thread0, (void*)1, 10) == NULL) {
    printf("sthread_create failed\n");
    exit(-1);
  }

  sthread_monitor_enter(mon1);
  for (i = 0; i < NUMBER; i++){
    if ((thr[i] = sthread_create(thread1, (void*)i, 10)) == NULL) {
      printf("sthread_create failed\n");
      exit(-1);
    }
    sthread_yield();
  }
  for (i = 0; i < NUMBER; i++){
    sthread_monitor_wait(mon1);
  }
    
  printf("in main\n");
  
  sthread_monitor_exit(mon1);
  
  sthread_sleep(10000);

  sthread_monitor_enter(mon2);
  sthread_monitor_signalall(mon2);
  sthread_monitor_exit(mon2);
  
  for (i = 0; i < NUMBER; i++){
    sthread_join(thr[i], &ret);
  }
  printf("\nSUCCESS in creating %i threads\n", NUMBER);
  printf("out main\n");

  return 0;
}
Exemple #9
0
static void rarch_main_data_thread_init(void)
{
   data_runloop_t *runloop  = rarch_main_data_get_ptr();

   if (!runloop)
      return;

   runloop->lock            = slock_new();
   runloop->cond_lock       = slock_new();
   runloop->overlay_lock    = slock_new();
   runloop->cond            = scond_new();

   runloop->thread    = sthread_create(data_thread_loop, runloop);

   if (!runloop->thread)
      goto error;

   slock_lock(runloop->lock);
   runloop->thread_inited   = true;
   runloop->alive           = true;
   runloop->thread_code     = THREAD_CODE_ALIVE;
   slock_unlock(runloop->lock);

   return;

error:
   slock_free(runloop->lock);
   slock_free(runloop->cond_lock);
   slock_free(runloop->overlay_lock);
   scond_free(runloop->cond);
}
Exemple #10
0
int main(int argc, char **argv)
{
    int i;
    long ret;
    sthread_t testers[NTHREADS];

    srand(0);	/* init the workload generator */
    cacheinit();  /* init the buffer */

    /* init blocks */
    for (i = 0; i < NBLOCKS; i++) {
        memcpy(blockData[i], (char *) &i, BLOCKSIZE);
    }

    /* start the testers */
    for(i = 0; i < NTHREADS; i++) {
        sthread_create(&(testers[i]), &tester, i);
    }
    /* wait for everyone to finish */
    for(i = 0; i < NTHREADS; i++) {
        ret = sthread_join(testers[i]);
    }
    printf("Main thread done.\n");
    return ret;
}
Exemple #11
0
int main(int argc, char **argv)
{
	int checks;
	
	printf("Testing sthread_mutex_*, impl: %s\n",
		   (sthread_get_impl() == STHREAD_PTHREAD_IMPL) ? "pthread" : "user");
	
	sthread_init();
	
	mutex = sthread_mutex_init();
	sthread_mutex_lock(mutex);
	
	if (sthread_create(thread_start, (void*)1, 1) == NULL) {
		printf("sthread_create failed\n");
		exit(1);
	}
	
	/* Wait until the other thread has at least started,
	 * to give it a chance at getting through the mutex incorrectly. */
	while (ran_thread == 0) {
		sthread_yield();
	}

   sthread_dump();
	
	/* The other thread has run, but shouldn't have been
	 * able to affect counter (note that this is not a great test
	 * for preemptive scheduler, since the other thread's sequence
	 * is not atomic). */   
	assert(counter == 0);
	
	/* This should let the other thread run at some point. */
	sthread_mutex_unlock(mutex);
	
	/* Allow up to 100 checks in case the scheduler doesn't
	 * decide to run the other thread for a really long time. */
	checks = 100;
	while (checks > 0) {
		sthread_mutex_lock(mutex);
		if (counter != 0) {
			/* The other thread ran, got the lock,
			 * and incrmented the counter: test passes. */
			checks = -1;
		} else {
			checks--;
		}
		sthread_mutex_unlock(mutex);
		
		/* Nudge the scheduler to run the other thread: */
		sthread_yield();
	}
	
	if (checks == -1) {
		printf("sthread_mutex passed\n");
	} else {
		printf("*** sthread_mutex failed\n");
	}
	sthread_mutex_free(mutex);
	return 0;
}
Exemple #12
0
int main(int argc, char **argv) {
  int arg = 1;
  printf("Testing sthread_mutex_*, impl: %s\n",
      (sthread_get_impl() == STHREAD_PTHREAD_IMPL) ? "pthread" : "user");
  
  sthread_init();

  mon = sthread_monitor_init();
  
  sthread_monitor_enter(mon);
  if (sthread_create(thread_start, (void*)&arg, 1) == NULL) {
    printf("sthread_create failed\n");
    exit(1);
  }
  printf("thread principal vai bloquear-se\n");
  sthread_monitor_wait(mon);
  printf("thread principal desbloqueada\n");
  i = 2;
  printf("i=2\n");
  sthread_monitor_exit(mon);
  if (i==2) {
    printf("\nSUCESSO!\n");
  } else {
    printf("\nteste falhado...\n");
  }
  return 1;
}
Exemple #13
0
async_job_t *async_job_new(void)
{
   async_job_t *ajob = (async_job_t*)calloc(1, sizeof(*ajob));
   
   if (!ajob)
      return NULL;

   ajob->lock   = slock_new();

   if (!ajob->lock)
      goto error;

   ajob->sem = ssem_new(0);

   if (!ajob->sem)
      goto error;

   ajob->thread = sthread_create(async_job_processor, (void*)ajob);

   if (!ajob->thread)
      goto error;

   return ajob;

error:
   if (ajob->lock)
      slock_free(ajob->lock);
   ajob->lock = NULL;
   if (ajob->sem)
      ssem_free(ajob->sem);
   if (ajob)
      free((void*)ajob);
   return NULL;
}
Exemple #14
0
static void rarch_main_data_thread_init(void)
{
   if (!g_data_runloop.thread_inited)
      return;

   g_data_runloop.lock            = slock_new();
   g_data_runloop.cond_lock       = slock_new();
   g_data_runloop.cond            = scond_new();

#ifdef HAVE_OVERLAY
   rarch_main_data_overlay_thread_init();
#endif

   g_data_runloop.thread    = sthread_create(data_thread_loop, &g_data_runloop);

   if (!g_data_runloop.thread)
      goto error;

   slock_lock(g_data_runloop.lock);
   g_data_runloop.thread_inited   = true;
   g_data_runloop.alive           = true;
   g_data_runloop.thread_code     = THREAD_CODE_ALIVE;
   slock_unlock(g_data_runloop.lock);

   return;

error:
   data_runloop_thread_deinit();
}
static bool thread_init(thread_video_t *thr, const video_info_t *info, const input_driver_t **input,
      void **input_data)
{
   thr->lock = slock_new();
   thr->alpha_lock = slock_new();
   thr->frame.lock = slock_new();
   thr->cond_cmd = scond_new();
   thr->cond_thread = scond_new();
   thr->input = input;
   thr->input_data = input_data;
   thr->info = *info;
   thr->alive = true;
   thr->focus = true;

   size_t max_size = info->input_scale * RARCH_SCALE_BASE;
   max_size *= max_size;
   max_size *= info->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t);
   thr->frame.buffer = (uint8_t*)malloc(max_size);
   if (!thr->frame.buffer)
      return false;

   memset(thr->frame.buffer, 0x80, max_size);

   thr->target_frame_time = (retro_time_t)roundf(1000000LL / g_settings.video.refresh_rate);
   thr->last_time = rarch_get_time_usec();

   thr->thread = sthread_create(thread_loop, thr);
   if (!thr->thread)
      return false;
   thread_send_cmd(thr, CMD_INIT);
   thread_wait_reply(thr, CMD_INIT);

   return thr->cmd_data.b;
}
Exemple #16
0
static void test_fd(void)
{
	int p[2];
	sc_t sc;
	char buf[1024];
	int rc;
	sthread_t st;

	if (pipe(p) == -1)
		err(1, "pipe()");

	sc_init(&sc);
	sc_fd_add(&sc, p[1], PROT_WRITE);

	if (sthread_create(&st, &sc, fd_st, (void*) (long) p[1]))
		err(1, "sthread_create()");

	if (sthread_join(st, NULL))
		err(1, "sthread_join()");

	rc = read(p[0], buf, sizeof(buf) - 1);
	if (rc <= 0)
		err(1, "read()");

	buf[rc] = 0;

	if (strcmp(buf, "bye") != 0)
		errx(1, "buf is %s", buf);

	close(p[0]);
	close(p[1]);
}
Exemple #17
0
/**
 * autosave_new:
 * @path            : path to autosave file
 * @data            : pointer to buffer
 * @size            : size of @data buffer
 * @interval        : interval at which saves should be performed.
 *
 * Create and initialize autosave object.
 *
 * Returns: pointer to new autosave_t object if successful, otherwise
 * NULL.
 **/
autosave_t *autosave_new(const char *path, const void *data, size_t size,
      unsigned interval)
{
   autosave_t *handle = (autosave_t*)calloc(1, sizeof(*handle));
   if (!handle)
      return NULL;

   handle->bufsize      = size;
   handle->interval     = interval;
   handle->path         = path;
   handle->buffer       = malloc(size);
   handle->retro_buffer = data;

   if (!handle->buffer)
   {
      free(handle);
      return NULL;
   }
   memcpy(handle->buffer, handle->retro_buffer, handle->bufsize);

   handle->lock         = slock_new();
   handle->cond_lock    = slock_new();
   handle->cond         = scond_new();

   handle->thread       = sthread_create(autosave_thread, handle);

   return handle;
}
Exemple #18
0
static void rarch_main_data_thread_init(void)
{
   data_runloop_t *runloop  = rarch_main_data_get_ptr();

   if (!runloop)
      return;

   runloop->lock            = slock_new();
   runloop->cond_lock       = slock_new();
   runloop->cond            = scond_new();

#ifdef HAVE_OVERLAY
   rarch_main_data_overlay_thread_init();
#endif

   runloop->thread    = sthread_create(data_thread_loop, runloop);

   if (!runloop->thread)
      goto error;

   slock_lock(runloop->lock);
   runloop->thread_inited   = true;
   runloop->alive           = true;
   runloop->thread_code     = THREAD_CODE_ALIVE;
   slock_unlock(runloop->lock);

   return;

error:
   data_runloop_thread_deinit(runloop);
}
Exemple #19
0
static void test_syscall(void)
{
	sc_t sc;
	tag_t t;
	char *buf;
	sthread_t st;

	t = tag_new();
	buf = smalloc(t, 1024);
	assert(buf);

	sc_init(&sc);
	sc_mem_add(&sc, t, PROT_READ | PROT_WRITE);
	sc_sys_add(&sc, SYS_open);
	sc_sys_add(&sc, SYS_close);

	if (sthread_create(&st, &sc, sys_st, buf))
		err(1, "sthread_create()");

	if (sthread_join(st, NULL))
		err(1, "sthread_join()");

	if (strncmp(buf, "root", 4) != 0)
		errx(1, "buf is %s", buf);
}
static void *sunxi_gfx_init(const video_info_t *video,
      const input_driver_t **input, void **input_data)
{
   struct sunxi_video *_dispvars = (struct sunxi_video*)
      calloc(1, sizeof(struct sunxi_video));

   if (!_dispvars)
      return NULL;

   _dispvars->src_bytes_per_pixel = video->rgb32 ? 4 : 2;
   _dispvars->sunxi_disp          = sunxi_disp_init("/dev/fb0");

   /* Blank text console and disable cursor blinking. */
   sunxi_blank_console(_dispvars);

   _dispvars->pages = (struct sunxi_page*)calloc(NUMPAGES, sizeof (struct sunxi_page));

   if (!_dispvars->pages)
      goto error;

   _dispvars->dst_pitch           = _dispvars->sunxi_disp->xres * _dispvars->sunxi_disp->bits_per_pixel / 8;
   /* Considering 4 bytes per pixel since we will be in 32bpp on the CB/CB2/CT for hw scalers to work. */
   _dispvars->dst_pixels_per_line = _dispvars->dst_pitch / 4;
   _dispvars->pageflip_pending    = false;
   _dispvars->nextPage            = &_dispvars->pages[0];
   _dispvars->keep_vsync          = true;
   _dispvars->menu_active         = false;
   _dispvars->bytes_per_pixel     = video->rgb32 ? 4 : 2;

   switch (_dispvars->bytes_per_pixel)
   {
      case 2:
         pixman_blit = pixman_composite_src_0565_8888_asm_neon;
         break;
      case 4:
         pixman_blit = pixman_composite_src_8888_8888_asm_neon;
         break;
      default:
         goto error;
   }

   _dispvars->pending_mutex    = slock_new();
   _dispvars->vsync_condition  = scond_new();

   if (input && input_data)
      *input = NULL;

   /* Launching vsync thread */
   _dispvars->vsync_thread     = sthread_create(sunxi_vsync_thread_func, _dispvars);

   return _dispvars;

error:
   if (_dispvars)
      free(_dispvars);
   return NULL;
}
Exemple #21
0
void Test1(){
    sthread_mutex_init(mut_ptr);
    sthread_t thr1,thr2,thr3;

    if (sthread_init() == -1){}

    printf("Creating Thread 1\n");

    if (sthread_create(&thr1, threadmain, (void *)1) == -1){}

    sleep(2);
    printf("Creating Thread 2\n");
    if (sthread_create(&thr2, threadmain, (void *)2) == -1){}

    sleep(2);
    printf("Creating Thread 3\n");
    if (sthread_create(&thr3, threadmain, (void *)3) == -1){}

}
Exemple #22
0
int main(int argc, char **argv)
{
	sthread_t threads[NUM_TC];
	sthread_t prodthr;
	int i;
	available_reqs = 0;
	
	// initialize sthread lib	
	sthread_init();
	
	//initialize filesystem
	snfs_init(argc, argv);
		
   	// initialize SNFS layer
       struct sockaddr_un servaddr;
                	
	// initialize communications
	srv_init_socket(&servaddr);
			
	// initialize  monitor
        mon = sthread_monitor_init();
        
	// create thread_consumer threads
	for(i = 0; i < NUM_TC; i++) {
		threads[i] = sthread_create(thread_consumer, (void*) NULL,1);
		if (threads[i] == NULL) {
			printf("Error while creating threads. Terminating...\n");
			exit(-1);
		}
	}
	
	// create producer thread
	prodthr = sthread_create(thread_producer, (void*) NULL,1);
	
	
	sthread_join(prodthr, (void**)NULL);
	for(i = 0; i < NUM_TC; i++)
		sthread_join(threads[i], (void **)NULL);

	return 0;
}
Exemple #23
0
static bool dsound_start_thread(dsound_t *ds)
{
   if (!ds->thread)
   {
      ds->thread_alive = true;
      ds->thread = sthread_create(dsound_thread, ds);
      if (!ds->thread)
         return false;
   }

   return true;
}
Exemple #24
0
static void retro_task_threaded_init(void)
{
   running_lock  = slock_new();
   finished_lock = slock_new();
   worker_cond   = scond_new();

   slock_lock(running_lock);
   worker_continue = true;
   slock_unlock(running_lock);

   worker_thread = sthread_create(threaded_worker, NULL);
}
int main(int argc, char **argv)
{
  int ii;

  for(ii = 0; ii < NTHREADS; ii++){
    sthread_create(&(threads[ii]), &go, ii);
  }
  for(ii = 0; ii < NTHREADS; ii++){
    long ret = sthread_join(threads[ii]);
    printf("Thread %d returned %ld\n", ii, ret);
  }
  printf("Main thread done.\n");
  return 0;
}
Exemple #26
0
int main(int argc, char *argv[])
{
  sthread_t thr1, thr2;

  if (sthread_init() == -1)
    fprintf(stderr, "%s: sthread_init: %s\n", argv[0], strerror(errno));

  if (sthread_create(&thr1, threadmain, (void *)1) == -1)
    fprintf(stderr, "%s: sthread_create: %s\n", argv[0], strerror(errno));

  if (sthread_create(&thr2, threadmain, (void *)2) == -1)
    fprintf(stderr, "%s: sthread_create: %s\n", argv[0], strerror(errno));

  sleep(1);
  sthread_wake(thr1);
  sleep(1);
  sthread_wake(thr2);
  sleep(1);
  sthread_wake(thr1);
  sthread_wake(thr2);
  sleep(1);

  return 0;
}
int main(int argc, char **argv) {
    sthread_t thread = NULL;
    int * res = (int *) malloc(sizeof(int));

    printf("Testing sthread_mutex_*, impl: %s\n",
           (sthread_get_impl() == STHREAD_PTHREAD_IMPL) ? "pthread" : "user");

    sthread_init();
    if ((thread = sthread_create(thread_start, (void *) NULL, 1)) == NULL) {
        printf("sthread_create failed\n");
        exit(1);
    }
    sthread_join(thread, (void**)&res);
    printf("\nteste concluido: consultar dump*.tsv\n");
    return 1;
}
Exemple #28
0
static void *launch_sthread(stcb_t cb, void *arg)
{
	sc_t sc;
	sthread_t st;
	void *ret;

	sc_init(&sc);

	if (sthread_create(&st, &sc, cb, arg))
		err(1, "sthread_create()");

	if (sthread_join(st, &ret))
		err(1, "sthread_join()");

	return ret;
}
Exemple #29
0
static void btstack_set_poweron(bool on)
{
   if (!btstack_try_load())
      return;

   if (on && !btstack_thread)
      btstack_thread = sthread_create(btstack_thread_func, NULL);
   else if (!on && btstack_thread && btstack_quit_source)
   {
#ifdef __APPLE__
      CFRunLoopSourceSignal(btstack_quit_source);
#endif
      sthread_join(btstack_thread);
      btstack_thread = NULL;
   }
}
CDIF_MT::CDIF_MT(CDAccess *cda) : disc_cdaccess(cda), CDReadThread(NULL), SBMutex(NULL), SBCond(NULL)
{
   try
   {
      CDIF_Message msg;
      RTS_Args s;

      SBMutex            = slock_new();
      SBCond             = scond_new();
      UnrecoverableError = false;

      s.cdif_ptr = this;

      CDReadThread = sthread_create((void (*)(void*))ReadThreadStart_C, &s);
      EmuThreadQueue.Read(&msg);
   }
   catch(...)
   {
      if(CDReadThread)
      {
         sthread_join((sthread_t*)CDReadThread);
         CDReadThread = NULL;
      }

      if(SBMutex)
      {
         slock_free((slock_t*)SBMutex);
         SBMutex = NULL;
      }

      if(SBCond)
      {
         scond_free((scond_t*)SBCond);
         SBCond = NULL;
      }

      if(disc_cdaccess)
      {
         delete disc_cdaccess;
         disc_cdaccess = NULL;
      }

      throw;
   }
}