Guest User

Untitled

a guest
Jun 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. void* renderLines(void* pArg){
  2. while(true){
  3. //Synchronize
  4. pthread_mutex_lock(&frame_mutex);
  5. pthread_cond_wait(&frame_cond, &frame_mutex);
  6. pthread_mutex_unlock(&frame_mutex);
  7.  
  8. renderLinesArgs* arg = (renderLinesArgs*)pArg;
  9. for(int y = arg->y1; y < arg->y2; y++){
  10. for(int x = 0; x < arg->width; x++){
  11. Color C = arg->scene->renderPixel(x, y);
  12. putPixel(arg->screen, x, y, C);
  13. }
  14. }
  15.  
  16. sem_post(&frame_rendered);
  17. }
  18. }
  19.  
  20. //Signal a new frame
  21. pthread_mutex_lock(&frame_mutex);
  22. pthread_cond_broadcast(&frame_cond);
  23. pthread_mutex_unlock(&frame_mutex);
  24.  
  25. //Wait for workers to be done
  26. sem_wait(&frame_rendered);
  27. sem_wait(&frame_rendered);
  28.  
  29. //Unlock SDL surface and flip it...
  30.  
  31. $uname -a
  32. Linux jopsen-laptop 2.6.27-14-generic #1 SMP Fri Mar 13 18:00:20 UTC 2009 i686 GNU/Linux
  33.  
  34. pthread_mutex_lock(&frame_mutex);
  35. pthread_cond_wait(&frame_cond, &frame_mutex);
  36. pthread_mutex_unlock(&frame_mutex);
  37.  
  38. pthread_mutex_lock(&mutex);
  39. new_frame = 1;
  40. pthread_cond_signal(&cond);
  41. pthread_mutex_unlock(&mutex);
  42.  
  43. pthread_mutex_lock(&mutex);
  44. while(new_frame == 0)
  45. pthread_cond_wait(&cond, &mutex);
  46. /* Here new_frame != 0, do things with the frame*/
  47. pthread_mutex_unlock(&mutex);
  48.  
  49. pthread_mutex_lock(&frame_mutex);
  50. pthread_cond_wait(&frame_cond, &frame_mutex);
  51. pthread_mutex_unlock(&frame_mutex);
Add Comment
Please, Sign In to add comment