| 712 | |
| 713 | |
| 714 | int SharedMemoryBase::eventWait(event_t* event, const SLONG value, const SLONG micro_seconds) |
| 715 | { |
| 716 | /************************************** |
| 717 | * |
| 718 | * I S C _ e v e n t _ w a i t |
| 719 | * |
| 720 | ************************************** |
| 721 | * |
| 722 | * Functional description |
| 723 | * Wait on an event. |
| 724 | * |
| 725 | **************************************/ |
| 726 | |
| 727 | fb_assert(event->event_pid == getpid()); |
| 728 | |
| 729 | // If we're not blocked, the rest is a gross waste of time |
| 730 | |
| 731 | if (!event_blocked(event, value)) { |
| 732 | return FB_SUCCESS; |
| 733 | } |
| 734 | |
| 735 | #if defined(WIN_NT) |
| 736 | |
| 737 | // Go into wait loop |
| 738 | |
| 739 | const DWORD timeout = (micro_seconds > 0) ? micro_seconds / 1000 : INFINITE; |
| 740 | |
| 741 | for (;;) |
| 742 | { |
| 743 | if (!event_blocked(event, value)) |
| 744 | return FB_SUCCESS; |
| 745 | |
| 746 | const DWORD status = WaitForSingleObject(event->event_handle, timeout); |
| 747 | |
| 748 | if (status != WAIT_OBJECT_0) |
| 749 | return FB_FAILURE; |
| 750 | } |
| 751 | |
| 752 | #else // pthread-based event |
| 753 | |
| 754 | // Set up timers if a timeout period was specified. |
| 755 | |
| 756 | struct timespec timer; |
| 757 | if (micro_seconds > 0) |
| 758 | { |
| 759 | #if defined(HAVE_CLOCK_GETTIME) |
| 760 | clock_gettime(CLOCK_REALTIME, &timer); |
| 761 | #elif defined(HAVE_GETTIMEOFDAY) |
| 762 | struct timeval tp; |
| 763 | GETTIMEOFDAY(&tp); |
| 764 | timer.tv_sec = tp.tv_sec; |
| 765 | timer.tv_nsec = tp.tv_usec * 1000; |
| 766 | #else |
| 767 | struct timeb time_buffer; |
| 768 | ftime(&time_buffer); |
| 769 | timer.tv_sec = time_buffer.time; |
| 770 | timer.tv_nsec = time_buffer.millitm * 1000000; |
| 771 | #endif |
no test coverage detected