Browse code

- possible signal interruptions treated for sysv sems

Andrei Pelinescu-Onciul authored on 17/03/2003 17:04:12
Showing 1 changed files
... ...
@@ -39,6 +39,7 @@
39 39
  *              the locking.h<->shm_mem.h interdependency) (andrei)
40 40
  *  2003-03-10  lock set support added also for PTHREAD_MUTEX & POSIX_SEM
41 41
  *               (andrei)
42
+ *  2003-03-17  possible signal interruptions treated for sysv (andrei)
42 43
  *
43 44
 Implements:
44 45
 
... ...
@@ -164,7 +165,16 @@ inline static void lock_get(gen_lock_t* lock)
164 165
 	sop.sem_num=0;
165 166
 	sop.sem_op=-1; /* down */
166 167
 	sop.sem_flg=0; 
167
-	semop(*lock, &sop, 1);
168
+tryagain:
169
+	if (semop(*lock, &sop, 1)==-1){
170
+		if (errno==EINTR){
171
+			DBG("lock_get: signal received while waiting for on a mutex\n");
172
+			goto tryagain;
173
+		}else{
174
+			LOG(L_CRIT, "ERROR: lock_get sysv: %s (%d)\n", strerror(errno),
175
+						errno);
176
+		}
177
+	}
168 178
 }
169 179
 
170 180
 inline static void lock_release(gen_lock_t* lock)
... ...
@@ -174,7 +184,17 @@ inline static void lock_release(gen_lock_t* lock)
174 184
 	sop.sem_num=0;
175 185
 	sop.sem_op=1; /* up */
176 186
 	sop.sem_flg=0; 
177
-	semop(*lock, &sop, 1);
187
+tryagain:
188
+	if (semop(*lock, &sop, 1)==-1){
189
+		if (errno==EINTR){
190
+			/* very improbable*/
191
+			DBG("lock_release: signal received while releasing a mutex\n");
192
+			goto tryagain;
193
+		}else{
194
+			LOG(L_CRIT, "ERROR: lock_release sysv: %s (%d)\n",
195
+					strerror(errno), errno);
196
+		}
197
+	}
178 198
 }
179 199
 
180 200
 
... ...
@@ -250,7 +270,16 @@ inline static void lock_set_get(lock_set_t* s, int n)
250 270
 	sop.sem_num=n;
251 271
 	sop.sem_op=-1; /* down */
252 272
 	sop.sem_flg=0;
253
-	semop(s->semid, &sop, 1);
273
+tryagain:
274
+	if (semop(s->semid, &sop, 1)==-1){
275
+		if (errno==EINTR){
276
+			DBG("lock_set_get: signal received while waiting on a mutex\n");
277
+			goto tryagain;
278
+		}else{
279
+			LOG(L_CRIT, "ERROR: lock_set_get sysv: %s (%d)\n",
280
+					strerror(errno), errno);
281
+		}
282
+	}
254 283
 }
255 284
 
256 285
 inline static void lock_set_release(lock_set_t* s, int n)
... ...
@@ -259,7 +288,17 @@ inline static void lock_set_release(lock_set_t* s, int n)
259 288
 	sop.sem_num=n;
260 289
 	sop.sem_op=1; /* up */
261 290
 	sop.sem_flg=0;
262
-	semop(s->semid, &sop, 1);
291
+tryagain:
292
+	if (semop(s->semid, &sop, 1)==-1){
293
+		if (errno==EINTR){
294
+			/* very improbable */
295
+			DBG("lock_set_release: signal received while releasing mutex\n");
296
+			goto tryagain;
297
+		}else{
298
+			LOG(L_CRIT, "ERROR: lock_set_release sysv: %s (%d)\n",
299
+					strerror(errno), errno);
300
+		}
301
+	}
263 302
 }
264 303
 #else 
265 304
 #error "no lock set method selected"