Changeset d600e18 in git


Ignore:
Timestamp:
Nov 5, 2013, 12:51:24 PM (9 years ago)
Author:
Andreas Steenpass <steenpass@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '2234726c50d679d6664181a5c72f75a6fd64a787')
Children:
2fa80a36c041e00aa30582d92c55f22cc3fe47d8
Parents:
659a7af613781bb070ab2564b6aff1c52a070df4
git-author:
Andreas Steenpass <steenpass@mathematik.uni-kl.de>2013-11-05 12:51:24+01:00
git-committer:
Andreas Steenpass <steenpass@mathematik.uni-kl.de>2013-11-06 13:33:11+01:00
Message:
chg: release acquired semaphores before shutdown
(cherry picked from commit 0f27f90c69fc9952c3df5edb6dff0b57fd8ff826)

Signed-off-by: Andreas Steenpass <steenpass@mathematik.uni-kl.de>

Conflicts:
	Singular/links/semaphore.c
	Singular/misc_ip.cc
Location:
Singular
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Singular/links/semaphore.c

    r659a7a rd600e18  
    99# include "simpleipc.h"
    1010
     11#include <Singular/cntrlc.h>
    1112#include <Singular/si_signals.h>
    1213
     
    2324// but are supported more widely.
    2425
    25 static sem_t *semaphore[SIPC_MAX_SEMAPHORES];
     26sem_t *semaphore[SIPC_MAX_SEMAPHORES];
     27int sem_acquired[SIPC_MAX_SEMAPHORES];
    2628
    2729/* return 1 on success,
     
    7476{
    7577  if ((id<0) || (id >= SIPC_MAX_SEMAPHORES) || (semaphore[id]==NULL))  return -1;
     78  defer_shutdown++;
    7679  si_sem_wait(semaphore[id]);
     80  sem_acquired[id]++;
     81  defer_shutdown--;
     82  if (!defer_shutdown && do_shutdown) m2_end(1);
    7783  return 1;
    7884}
     
    8187{
    8288  if ((id<0) || (id >= SIPC_MAX_SEMAPHORES) || (semaphore[id]==NULL))  return -1;
    83   return !si_sem_trywait(semaphore[id]);
     89  defer_shutdown++;
     90  int trywait = si_sem_trywait(semaphore[id]);
     91  if (!trywait)
     92  {
     93    sem_acquired[id]++;
     94  }
     95  defer_shutdown--;
     96  if (!defer_shutdown && do_shutdown) m2_end(1);
     97  return !trywait;
    8498}
    8599
     
    87101{
    88102  if ((id<0) || (id >= SIPC_MAX_SEMAPHORES) || (semaphore[id]==NULL))  return -1;
     103  defer_shutdown++;
    89104  sem_post(semaphore[id]);
     105  sem_acquired[id]--;
     106  defer_shutdown--;
     107  if (!defer_shutdown && do_shutdown) m2_end(1);
    90108  return 1;
    91109}
  • Singular/links/simpleipc.h

    r659a7a rd600e18  
     1#include <semaphore.h>
     2
    13#ifndef _SIMPLEIPC_H
    24#define _SIMPLEIPC_H
     
    911
    1012#define USE_SEM_INIT 0
     13
     14extern sem_t *semaphore[SIPC_MAX_SEMAPHORES];
     15extern int sem_acquired[SIPC_MAX_SEMAPHORES];
    1116
    1217int sipc_semaphore_init(int id, int count);
  • Singular/links/ssiLink.cc

    r659a7a rd600e18  
    805805          }
    806806          ssiToBeClosed->next=NULL;
     807#ifdef HAVE_SIMPLEIPC
     808          memset(sem_acquired, 0, SIPC_MAX_SEMAPHORES*sizeof(sem_acquired[0]));
     809#endif   // HAVE_SIMPLEIPC
    807810          si_close(pc[1]); si_close(cp[0]);
    808811          d->f_write=fdopen(cp[1],"w");
  • Singular/misc_ip.cc

    r659a7a rd600e18  
    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
     
    10551059  {
    10561060    m2_end_called = TRUE;
     1061#ifdef HAVE_SIMPLEIPC
     1062    for (int i = SIPC_MAX_SEMAPHORES; i >= 0; i--)
     1063    {
     1064      if (semaphore[i] != NULL)
     1065      {
     1066        while (sem_acquired[i] > 0)
     1067        {
     1068          sem_post(semaphore[i]);
     1069          sem_acquired[i]--;
     1070        }
     1071      }
     1072    }
     1073#endif   // HAVE_SIMPLEIPC
    10571074    fe_reset_input_mode();
    10581075#ifdef PAGE_TEST
Note: See TracChangeset for help on using the changeset viewer.