Changeset 2fa80a in git for Singular/misc_ip.cc


Ignore:
Timestamp:
Nov 6, 2013, 6:07:39 PM (9 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'f875bbaccd0831e36aaed09ff6adeb3eb45aeb94')
Children:
823679a657c538153cba3a477bf92e2c9102c451
Parents:
2ea781ea236dc6d65399e46b262e9954538749a1d600e1863951bfc5135d0138b61badb20b1ec70a
Message:
Merge pull request #414 from steenpass/resources_sw

release acquired semaphores before shutdown
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/misc_ip.cc

    r2ea781 r2fa80a  
    2323#define SI_DONT_HAVE_GLOBAL_VARS
    2424#include <factory/factory.h>
     25#endif
     26
     27#ifdef HAVE_SIMPLEIPC
     28#include <Singular/links/simpleipc.h>
    2529#endif
    2630
     
    10481052*/
    10491053extern "C" {
     1054/* Note: We cannot use a mutex here because mutexes are not async-safe, but
     1055 * m2_end is called by sig_term_hdl(). Anyway, the race condition in the first
     1056 * few lines of m2_end() should not matter.
     1057 */
     1058volatile BOOLEAN m2_end_called = FALSE;
    10501059
    10511060void m2_end(int i)
    10521061{
    1053   fe_reset_input_mode();
    1054   #ifdef PAGE_TEST
    1055   mmEndStat();
    1056   #endif
    1057   fe_reset_input_mode();
    1058   if (ssiToBeClosed_inactive)
    1059   {
    1060     link_list hh=ssiToBeClosed;
    1061     while(hh!=NULL)
    1062     {
    1063       //Print("close %s\n",hh->l->name);
    1064       slPrepClose(hh->l);
    1065       hh=(link_list)hh->next;
    1066     }
    1067     ssiToBeClosed_inactive=FALSE;
    1068 
    1069     idhdl h = currPack->idroot;
    1070     while(h != NULL)
    1071     {
    1072       if(IDTYP(h) == LINK_CMD)
    1073       {
    1074         idhdl hh=h->next;
    1075         //Print("kill %s\n",IDID(h));
    1076         killhdl(h, currPack);
    1077         h = hh;
     1062  if (!m2_end_called)
     1063  {
     1064    m2_end_called = TRUE;
     1065#ifdef HAVE_SIMPLEIPC
     1066    for (int i = SIPC_MAX_SEMAPHORES; i >= 0; i--)
     1067    {
     1068      if (semaphore[i] != NULL)
     1069      {
     1070        while (sem_acquired[i] > 0)
     1071        {
     1072          sem_post(semaphore[i]);
     1073          sem_acquired[i]--;
     1074        }
     1075      }
     1076    }
     1077#endif   // HAVE_SIMPLEIPC
     1078    fe_reset_input_mode();
     1079#ifdef PAGE_TEST
     1080    mmEndStat();
     1081#endif
     1082    fe_reset_input_mode();
     1083    if (ssiToBeClosed_inactive)
     1084    {
     1085      link_list hh=ssiToBeClosed;
     1086      while(hh!=NULL)
     1087      {
     1088        //Print("close %s\n",hh->l->name);
     1089        slPrepClose(hh->l);
     1090        hh=(link_list)hh->next;
     1091      }
     1092      ssiToBeClosed_inactive=FALSE;
     1093
     1094      idhdl h = currPack->idroot;
     1095      while(h != NULL)
     1096      {
     1097        if(IDTYP(h) == LINK_CMD)
     1098        {
     1099          idhdl hh=h->next;
     1100          //Print("kill %s\n",IDID(h));
     1101          killhdl(h, currPack);
     1102          h = hh;
     1103        }
     1104        else
     1105        {
     1106          h = h->next;
     1107        }
     1108      }
     1109      hh=ssiToBeClosed;
     1110      while(hh!=NULL)
     1111      {
     1112        //Print("close %s\n",hh->l->name);
     1113        slClose(hh->l);
     1114        hh=ssiToBeClosed;
     1115      }
     1116    }
     1117    if (!singular_in_batchmode)
     1118    {
     1119      if (i<=0)
     1120      {
     1121        if (TEST_V_QUIET)
     1122        {
     1123          if (i==0)
     1124            printf("Auf Wiedersehen.\n");
     1125          else
     1126            printf("\n$Bye.\n");
     1127        }
     1128        //#ifdef sun
     1129        //  #ifndef __svr4__
     1130        //    _cleanup();
     1131        //    _exit(0);
     1132        //  #endif
     1133        //#endif
     1134        i=0;
    10781135      }
    10791136      else
    10801137      {
    1081         h = h->next;
    1082       }
    1083     }
    1084     hh=ssiToBeClosed;
    1085     while(hh!=NULL)
    1086     {
    1087       //Print("close %s\n",hh->l->name);
    1088       slClose(hh->l);
    1089       hh=ssiToBeClosed;
    1090     }
    1091   }
    1092   if (!singular_in_batchmode)
    1093   {
    1094     if (i<=0)
    1095     {
    1096       if (TEST_V_QUIET)
    1097       {
    1098         if (i==0)
    1099           printf("Auf Wiedersehen.\n");
    1100         else
    1101           printf("\n$Bye.\n");
    1102       }
    1103       //#ifdef sun
    1104       //  #ifndef __svr4__
    1105       //    _cleanup();
    1106       //    _exit(0);
    1107       //  #endif
    1108       //#endif
    1109       i=0;
    1110     }
    1111     else
    1112     {
    11131138        printf("\nhalt %d\n",i);
    1114     }
    1115   }
    1116   exit(i);
     1139      }
     1140    }
     1141    exit(i);
     1142  }
    11171143}
    11181144}
Note: See TracChangeset for help on using the changeset viewer.