File: signal_queue.c

package info (click to toggle)
gridengine 6.2u5-7.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 57,216 kB
  • sloc: ansic: 438,030; java: 66,252; sh: 36,399; jsp: 7,757; xml: 5,850; makefile: 5,520; csh: 4,571; cpp: 2,848; perl: 2,401; tcl: 692; lisp: 669; yacc: 668; ruby: 642; lex: 344
file content (215 lines) | stat: -rw-r--r-- 5,129 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
 *
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 *
 *  Sun Microsystems Inc., March, 2001
 *
 *
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2001 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 ************************************************************************/
/*___INFO__MARK_END__*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <stdio.h>
#include <ctype.h>

#include "signal_queue.h"
#include "err_trace.h"
#include "sge_signal.h"


#define SGE_MAXSIG 100

/* ring buffer to queue signals */
static int sig_queue[SGE_MAXSIG];
static int n_sigs = 0;
static int next_sig = 0;
static int free_sig = 0; 


#define NEXT_INDEX(i) (((i+1)>SGE_MAXSIG-1)?0:(i+1))

#ifdef DEBUG
void report_signal_queue()
{
   char str[256];
   int n, i;
 
   if (n_sigs==0) {
      shepherd_trace("no signals in queue");
      return;
   }

   i=next_sig;

   for (n=n_sigs; n; n--) {
      sprintf(str, "%d. %d", i, sig_queue[i]); 
      shepherd_trace(str);
      i = NEXT_INDEX(i);
   }

   return;
}
#endif

int shepherd_sys_str2signal(char *override_signal)
{
   if (!isdigit(override_signal[0]))
      override_signal = &override_signal[3];
   return sge_sys_str2signal(override_signal);
}

/****** shepherd/signal/queue/add_signal() ************************************
*  NAME
*     add_signal() -- store signal in queue 
*
*  SYNOPSIS
*     int add_signal(int signal) 
*
*  FUNCTION
*     Store an additional signal in queue. 
*
*  INPUTS
*     int signal - sginal number 
*
*  RESULT
*     int - error state
*        0 - successfull
*       -1 - buffer is full 
*******************************************************************************/
int add_signal(int signal)
{
   int ret = -1;

   if (n_sigs != SGE_MAXSIG) {
      char err_str[256];
      ret = 0;

      n_sigs++;
      sig_queue[free_sig] = signal;
      free_sig = NEXT_INDEX(free_sig);

      sprintf(err_str, "queued signal %s", sge_sys_sig2str(signal));
      shepherd_trace(err_str);
   } 
   return ret;
}  

/****** shepherd/signal_queue/get_signal() ************************************
*  NAME
*     get_signal() -- get signal from queue 
*
*  SYNOPSIS
*     int get_signal() 
*
*  FUNCTION
*     Get signal from queue. If tehre are no more signals return -1.
*
*  INPUTS
*
*  RESULT
*     int - 
*        >0 - signal number
*        -1 - There are no more signals 
*******************************************************************************/
int get_signal(void)
{
   int signal = -1;

   if (n_sigs != 0) {
      n_sigs--;
      signal = sig_queue[next_sig];
      next_sig = NEXT_INDEX(next_sig);
   }

   return signal;
}

/****** shepherd/signal_queue/pending_sig() ***********************************
*  NAME
*     pending_sig() -- look for given signal in queue 
*
*  SYNOPSIS
*     int pending_sig(int sig) 
*
*  FUNCTION
*     Try to find signal in queue.
*
*  INPUTS
*     int sig - signal number 
*
*  RESULT
*     int - result
*        0 - not found
*        1 - found 
*******************************************************************************/
int pending_sig(int sig) 
{
   int ret = 0;
   int n, i;

   for (n = n_sigs, i = next_sig; n; n--, i = NEXT_INDEX(i)) {
      if (sig_queue[i] == sig) {
         ret = 1;
         break;
      }
   }
   return ret;
}

/****** shepherd/signal_queue/get_n_sigs() ************************************
*  NAME
*     get_n_sigs() -- return number of queues signals 
*
*  SYNOPSIS
*     int get_n_sigs(void) 
*
*  FUNCTION
*     Return number of queues signals 
*
*  RESULT
*     int - number of signals
*******************************************************************************/
int get_n_sigs(void)
{
   return n_sigs; 
}

/****** shepherd/signal_queue/clear_queued_signals() **************************
*  NAME
*     clear_queued_signals() -- clear signal queue 
*
*  SYNOPSIS
*     void clear_queued_signals(void) 
*
*  FUNCTION
*     Clear signal queue 
*******************************************************************************/
void clear_queued_signals(void)
{
   n_sigs = next_sig = free_sig = 0; 
}