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 164
 	sop.sem_num=0;
165 165
 	sop.sem_op=-1; /* down */
166 166
 	sop.sem_flg=0; 
167
-	semop(*lock, &sop, 1);
167
+tryagain:
168
+	if (semop(*lock, &sop, 1)==-1){
169
+		if (errno==EINTR){
170
+			DBG("lock_get: signal received while waiting for on a mutex\n");
171
+			goto tryagain;
172
+		}else{
173
+			LOG(L_CRIT, "ERROR: lock_get sysv: %s (%d)\n", strerror(errno),
174
+						errno);
175
+		}
176
+	}
168 177
 }
169 178
 
170 179
 inline static void lock_release(gen_lock_t* lock)
... ...
@@ -174,7 +184,17 @@ inline static void lock_release(gen_lock_t* lock)
174 174
 	sop.sem_num=0;
175 175
 	sop.sem_op=1; /* up */
176 176
 	sop.sem_flg=0; 
177
-	semop(*lock, &sop, 1);
177
+tryagain:
178
+	if (semop(*lock, &sop, 1)==-1){
179
+		if (errno==EINTR){
180
+			/* very improbable*/
181
+			DBG("lock_release: signal received while releasing a mutex\n");
182
+			goto tryagain;
183
+		}else{
184
+			LOG(L_CRIT, "ERROR: lock_release sysv: %s (%d)\n",
185
+					strerror(errno), errno);
186
+		}
187
+	}
178 188
 }
179 189
 
180 190
 
... ...
@@ -250,7 +270,16 @@ inline static void lock_set_get(lock_set_t* s, int n)
250 250
 	sop.sem_num=n;
251 251
 	sop.sem_op=-1; /* down */
252 252
 	sop.sem_flg=0;
253
-	semop(s->semid, &sop, 1);
253
+tryagain:
254
+	if (semop(s->semid, &sop, 1)==-1){
255
+		if (errno==EINTR){
256
+			DBG("lock_set_get: signal received while waiting on a mutex\n");
257
+			goto tryagain;
258
+		}else{
259
+			LOG(L_CRIT, "ERROR: lock_set_get sysv: %s (%d)\n",
260
+					strerror(errno), errno);
261
+		}
262
+	}
254 263
 }
255 264
 
256 265
 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 259
 	sop.sem_num=n;
260 260
 	sop.sem_op=1; /* up */
261 261
 	sop.sem_flg=0;
262
-	semop(s->semid, &sop, 1);
262
+tryagain:
263
+	if (semop(s->semid, &sop, 1)==-1){
264
+		if (errno==EINTR){
265
+			/* very improbable */
266
+			DBG("lock_set_release: signal received while releasing mutex\n");
267
+			goto tryagain;
268
+		}else{
269
+			LOG(L_CRIT, "ERROR: lock_set_release sysv: %s (%d)\n",
270
+					strerror(errno), errno);
271
+		}
272
+	}
263 273
 }
264 274
 #else 
265 275
 #error "no lock set method selected"