Changeset 872


Ignore:
Timestamp:
Nov 23, 2003, 3:41:33 AM (22 years ago)
Author:
bird
Message:

Added deadlock and termination checks to the semaphore waiting to avoid stupid hangs.

Location:
trunk/src/emx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/sys/fmutex.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r871 r872  
    3434typedef struct
    3535{
    36   unsigned long hev;            /* HEV */
    37   __volatile__ signed char fs;  /* Status */
     36    /** Handle to event semaphore. */
     37    unsigned long hev;
     38    /** Semaphore status. */
     39    __volatile__ signed char fs;
     40    /** Semaphore create flags. (_FMC_SHARED) */
     41    unsigned char flags;
     42    /** padding the struct to 8 bytes. */
     43    unsigned char padding[2];
    3844} _fmutex;
    3945#pragma pack()
  • trunk/src/emx/src/lib/process/fmutex.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r871 r872  
    2020  FS_VAR();
    2121  sem->fs = _FMS_AVAILABLE;
     22  sem->flags = flags;
     23  sem->padding[0] = 'f';
     24  sem->padding[1] = 'm';
    2225  FS_SAVE_LOAD();
    2326  rc = DosCreateEventSem (NULL, (PHEV)&sem->hev,
     
    5558{
    5659  ULONG rc, count;
     60  PTIB  pTib;
     61  PPIB  pPib;
    5762
    5863  if (fs == _FMS_UNINIT)
     
    7984      if (__cxchg (&sem->fs, _FMS_OWNED_HARD) == _FMS_AVAILABLE)
    8085        return 0;
     86      FS_SAVE_LOAD();
     87
    8188      do
    8289        {
    83           FS_SAVE_LOAD();
    84           rc = DosWaitEventSem (sem->hev, SEM_INDEFINITE_WAIT);
    85           FS_RESTORE();
    86         } while (rc == ERROR_INTERRUPT && (flags & _FMR_IGNINT));
     90          rc = DosWaitEventSem (sem->hev, sem->flags & _FMC_SHARED ? SEM_INDEFINITE_WAIT : 3000);
     91          if (rc == ERROR_INTERRUPT)
     92            {
     93              /*
     94               * An interrupt occured, this might be a bug in the wait, or
     95               * more likely someone is killing us. If we're dying/exiting or
     96               * something along those lines, we return to the caller no matter
     97               * what flags it specified.
     98               */
     99              if (!(flags & _FMR_IGNINT))
     100                  break;
     101              DosGetInfoBlocks(&pTib, &pPib);
     102              if (pPib->pib_flstatus & (0x40/*dying*/ | 0x04/*exiting all*/ | 0x02/*Exiting Thread 1*/ | 0x01/* ExitList */))
     103                  break;
     104              rc = ERROR_TIMEOUT;
     105            }
     106          if (rc == ERROR_TIMEOUT && !(sem->flags & _FMC_SHARED))
     107            {
     108              /*
     109               * Deadlock detection - if this is the only thread of the
     110               * process we should just kill our selves.
     111               * ASSUME thread ids are reused and upper thread limit or 4k.
     112               */
     113              int iThread;
     114              DosGetInfoBlocks(&pTib, &pPib);
     115              for (iThread = 1; iThread < 4096; iThread++)
     116                {
     117                  if (   iThread != pTib->tib_ptib2->tib2_ultid
     118                      && !DosVerifyPidTid(pPib->pib_ulpid, iThread))
     119                      break;
     120                }
     121              if (iThread >= 4096)
     122                { /* No other threads! */
     123                  ULONG ul;
     124                  DosWrite((HFILE)2/*stderr*/, "\r\n!!!deadlock!!!\r\r", 18, &ul);
     125                  __asm__ __volatile__ ("movl $0xdead10cc, %%eax; movl $0xdead10cc, %%edx; movl %0, %%ecx; int $3" : : "m" (sem) : "%eax", "%edx", "%ecx");
     126                  rc = ERROR_SEM_OWNER_DIED;
     127                  break;
     128                }
     129            }
     130        } while (rc == ERROR_TIMEOUT);
     131      FS_RESTORE();
    87132      if (rc != 0)
    88133        return rc;
Note: See TracChangeset for help on using the changeset viewer.