Exemple #1
0
void thread2(void *v)
{
    fprintf(stderr, "thread2 started up\n");

    ta_lock(&mutex);
    ta_yield();
    fprintf(stderr, "thread2 not updating value, signalling thread1\n");
    ta_signal(&condv);
    ta_unlock(&mutex);

    ta_yield();

    ta_lock(&mutex);
    ta_yield();
    fprintf(stderr, "thread2 IS updating value, signalling thread1\n");
    value = -1;
    ta_signal(&condv);
    ta_unlock(&mutex);

    fprintf(stderr, "thread2 exiting\n");
}
Exemple #2
0
void reader(void *arg)
{
    int tid = (int)arg;
    int val = 0;
    while (!stop) {
        ta_sem_wait(&writersem);
        ta_lock(&wmutex);
        int loc = readerloc;
        readerloc = (readerloc+1) % datalen;
        ta_unlock(&wmutex);
        val = data[loc];
        ta_sem_post(&readersem);
        fprintf(stderr, "reader %d read location %d\n", tid, loc);

        if (random() % 2 == 0)
            ta_yield();
    }
}
Exemple #3
0
void thread1(void *v)
{
    fprintf(stderr, "thread1 started up\n");

    ta_lock(&mutex);
    ta_yield();
    while (value == 0)
    {
        fprintf(stderr, "thread1 going into cond_wait()\n");
        ta_wait(&condv, &mutex);
    }
   
    fprintf(stderr, "thread1 emerged from cond_wait()\n");
    value = 42;

    ta_yield();
    ta_unlock(&mutex);
    fprintf(stderr, "thread1 exiting\n");
}
void ta_wait(talock_t *mutex, tacond_t *cond) {

	assert(mutex != NULL);
	assert(cond != NULL);

	cond->partner_lock = mutex;
	struct node *current_thread = list_pop(ready);
	assert(current_thread != NULL);
	list_append_node(current_thread, mutex->binary_sem.queue);
	ta_unlock(mutex);

	if(!list_empty(ready)){
		swapcontext(current_thread->threadContext, list_last(ready)->threadContext);
	}
	else{
		swapcontext(current_thread->threadContext, &mainthread);
	}
	ta_lock(mutex);
}
Exemple #5
0
void writer(void *arg)
{
    fprintf(stderr,"in writer\n");
    int tid = (int)arg;
    int val = 1000000;
    int writerloc = 0;
    while (!stop) {
        ta_sem_wait(&readersem);
        ta_lock(&rmutex);
        int loc = writerloc;
        writerloc = (writerloc+1) % datalen;
        ta_unlock(&rmutex);
        data[loc] = val++;
        ta_sem_post(&writersem);
        fprintf(stderr, "writer %d wrote location %d\n", tid, loc);

        if (random() % 2 == 0)
            ta_yield();
    }
}
Exemple #6
0
/* Box points mapping
 * 12
 * 34
 */
void draw_box4(float x1, float y1, float x2, float y2, float z,
	       float a1, float r1, float g1, float b1,
	       float a2, float r2, float g2, float b2,
	       float a3, float r3, float g3, float b3,
	       float a4, float r4, float g4, float b4)
{
  float w,h;

  /* Clip out */
  if (x1 >= current_gc->clipbox.x2 || y1 >= current_gc->clipbox.y2 ||
      x2 <= current_gc->clipbox.x1 || y2 <= current_gc->clipbox.y1) {
    return;
  }

  /* Clip tiny or negative box */
  w = x2 - x1;
  h = y2 - y1;
  if (w < 1E-5 || h < 1E-5) {
    return;
  }

#define CLIPME(A,X,Y) A##X = A##Y * f1 + A##X * f2
#define CLIPIT(X,Y) \
 CLIPME(a,X,Y);\
 CLIPME(r,X,Y);\
 CLIPME(g,X,Y);\
 CLIPME(b,X,Y)

  /* Left clip */
  if (x1 < current_gc->clipbox.x1) {
    float f1 = (current_gc->clipbox.x1 - x1) / w;
    float f2 = 1.0f - f1;
    x1 = current_gc->clipbox.x1;
    w = x2 - x1;
    if (w < 1E-5) {
      return;
    }
    CLIPIT(1,2);
    CLIPIT(3,4);
  }

  /* Top clip */
  if (y1 < current_gc->clipbox.y1) {
    float f1 = (current_gc->clipbox.y1 - y1) / h;
    float f2 = 1.0f - f1;
    y1 = current_gc->clipbox.y1;
    h = y2 - y1;
    if (h < 1E-5) {
      return;
    }
    CLIPIT(1,3);
    CLIPIT(2,4);
  }

  /* Right clip */
  if (x2 > current_gc->clipbox.x2) {
    float f1 = (x2 - current_gc->clipbox.x2) / w;
    float f2 = 1.0f - f1;
    x2 = current_gc->clipbox.x2;
    CLIPIT(2,1);
    CLIPIT(4,3);
  }

  /* Bottom clip */
  if (y2 > current_gc->clipbox.y2) {
    float f1 = (y2 - current_gc->clipbox.y2) / h;
    float f2 = 1.0f - f1;
    y2 = current_gc->clipbox.y2;
    CLIPIT(3,1);
    CLIPIT(4,2);
  }

  DRAW_SET_FLAGS(DRAW_NO_TEXTURE|DRAW_TRANSLUCENT|DRAW_NO_FILTER);

  HW_COL_VTX->flags = TA_VERTEX_NORMAL;
  HW_COL_VTX->x = x1;
  HW_COL_VTX->y = y2;
  HW_COL_VTX->z = z;
  HW_COL_VTX->a = a3;
  HW_COL_VTX->r = r3;
  HW_COL_VTX->g = g3;
  HW_COL_VTX->b = b3;
  ta_lock();
  ta_commit32_nocopy();

  HW_COL_VTX->y = y1;
  HW_COL_VTX->a = a1;
  HW_COL_VTX->r = r1;
  HW_COL_VTX->g = g1;
  HW_COL_VTX->b = b1;
  ta_commit32_nocopy();
	
  HW_COL_VTX->x = x2;
  HW_COL_VTX->y = y2;
  HW_COL_VTX->a = a4;
  HW_COL_VTX->r = r4;
  HW_COL_VTX->g = g4;
  HW_COL_VTX->b = b4;
  ta_commit32_nocopy();

  HW_COL_VTX->flags = TA_VERTEX_EOL;
  HW_COL_VTX->y = y1;
  HW_COL_VTX->a = a2;
  HW_COL_VTX->r = r2;
  HW_COL_VTX->g = g2;
  HW_COL_VTX->b = b2;
  ta_commit32_nocopy();
  ta_unlock();
}