Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. struct ThreadOperationStruct _THREADIO;
  2.  
  3. int main(int argc, char** argv)
  4. {
  5. // threads get created here...
  6. }
  7.  
  8. void DecompressLogFile::Wait()
  9. {
  10. while (!_THREADIO.EndEvent)
  11. {
  12. pthread_mutex_lock(&Lock);
  13. size_t QueueSize = _THREADIO.DecompressLogQueue.size();
  14.  
  15. if (!QueueSize)
  16. {
  17. // Prevent further thread execution
  18. fprintf(stdout, "DecompressLogFile() thread sleeping...n");
  19. pthread_mutex_unlock(&Lock);
  20. pthread_cond_wait(&_THREADIO.DecompressQueueNotify, &Lock);
  21. } else {
  22. thread_mutex_lock(&Lock);
  23. fprintf(stdout, "Processing compressed log files. Queue size is now %lun", QueueSize);
  24. /*
  25. * Async tasks need to go here...
  26. */
  27. //BZIP2_DecompressFile();
  28. _THREADIO.DecompressLogQueue.pop();
  29. }
  30. }
  31.  
  32. fprintf(stdout, "Wait() endn");
  33. }
  34.  
  35. _THREADIO.DecompressLogQueue.push(NewLog);
  36. pthread_cond_signal(&_THREADIO.DecompressQueueNotify);
  37.  
  38. struct ThreadOperationStruct
  39. {
  40. std::queue<std::string> DecompressLogQueue;
  41. std::queue<std::string> ProcessLogQueue;
  42.  
  43. void NotifyDecompressThread()
  44. {
  45. fprintf(stdout, "notifying..n");
  46. pthread_cond_signal(&this->DecompressQueueNotify);
  47. }
  48.  
  49. pthread_cond_t DecompressQueueNotify;
  50. pthread_cond_t ProcessQueueNotify;
  51. bool EndEvent = false;
  52. };
  53.  
  54. extern ThreadOperationStruct _THREADIO;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement