| 771 | } |
| 772 | |
| 773 | void setup() |
| 774 | { |
| 775 | if (sharedMemory) |
| 776 | return; |
| 777 | MutexLockGuard gLocal(initMutex, FB_FUNCTION); |
| 778 | if (sharedMemory) |
| 779 | return; |
| 780 | |
| 781 | AutoSharedMemory tempSharedMemory; |
| 782 | try |
| 783 | { |
| 784 | tempSharedMemory.reset(FB_NEW_POOL(*getDefaultMemoryPool()) |
| 785 | SharedMemory<MappingHeader>(USER_MAP_FILE, DEFAULT_SIZE, this)); |
| 786 | } |
| 787 | catch (const Exception& ex) |
| 788 | { |
| 789 | iscLogException("MappingIpc: Cannot initialize the shared memory region", ex); |
| 790 | throw; |
| 791 | } |
| 792 | |
| 793 | MappingHeader* sMem = tempSharedMemory->getHeader(); |
| 794 | checkHeader(sMem); |
| 795 | |
| 796 | Guard gShared(tempSharedMemory); |
| 797 | |
| 798 | process = sMem->processes; |
| 799 | for (unsigned idx = 0; idx < sMem->processes; ++idx) |
| 800 | { |
| 801 | MappingHeader::Process& p = sMem->process[idx]; |
| 802 | |
| 803 | if (p.id == processId) |
| 804 | { |
| 805 | if (p.flags & MappingHeader::FLAG_ACTIVE) { |
| 806 | MAP_DEBUG(fprintf(stderr, "MappingIpc::setup: found existing entry for pid %d", processId)); |
| 807 | } |
| 808 | |
| 809 | process = idx; |
| 810 | continue; |
| 811 | } |
| 812 | |
| 813 | if ((p.flags & MappingHeader::FLAG_ACTIVE) && !ISC_check_process_existence(p.id)) |
| 814 | { |
| 815 | MAP_DEBUG(fprintf(stderr, "MappingIpc::setup: dead process found %d", p.id)); |
| 816 | |
| 817 | p.flags = 0; |
| 818 | tempSharedMemory->eventFini(&p.notifyEvent); |
| 819 | tempSharedMemory->eventFini(&p.callbackEvent); |
| 820 | } |
| 821 | |
| 822 | if (!(p.flags & MappingHeader::FLAG_ACTIVE)) |
| 823 | { |
| 824 | if (process == sMem->processes) |
| 825 | process = idx; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | if (process >= sMem->processes) |
| 830 | { |
no test coverage detected