Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void* renderLines(void* pArg){
- while(true){
- //Synchronize
- pthread_mutex_lock(&frame_mutex);
- pthread_cond_wait(&frame_cond, &frame_mutex);
- pthread_mutex_unlock(&frame_mutex);
- renderLinesArgs* arg = (renderLinesArgs*)pArg;
- for(int y = arg->y1; y < arg->y2; y++){
- for(int x = 0; x < arg->width; x++){
- Color C = arg->scene->renderPixel(x, y);
- putPixel(arg->screen, x, y, C);
- }
- }
- sem_post(&frame_rendered);
- }
- }
- //Signal a new frame
- pthread_mutex_lock(&frame_mutex);
- pthread_cond_broadcast(&frame_cond);
- pthread_mutex_unlock(&frame_mutex);
- //Wait for workers to be done
- sem_wait(&frame_rendered);
- sem_wait(&frame_rendered);
- //Unlock SDL surface and flip it...
- $uname -a
- Linux jopsen-laptop 2.6.27-14-generic #1 SMP Fri Mar 13 18:00:20 UTC 2009 i686 GNU/Linux
- pthread_mutex_lock(&frame_mutex);
- pthread_cond_wait(&frame_cond, &frame_mutex);
- pthread_mutex_unlock(&frame_mutex);
- pthread_mutex_lock(&mutex);
- new_frame = 1;
- pthread_cond_signal(&cond);
- pthread_mutex_unlock(&mutex);
- pthread_mutex_lock(&mutex);
- while(new_frame == 0)
- pthread_cond_wait(&cond, &mutex);
- /* Here new_frame != 0, do things with the frame*/
- pthread_mutex_unlock(&mutex);
- pthread_mutex_lock(&frame_mutex);
- pthread_cond_wait(&frame_cond, &frame_mutex);
- pthread_mutex_unlock(&frame_mutex);
Add Comment
Please, Sign In to add comment