MCPcopy Create free account
hub / github.com/F-Stack/f-stack / semundo_adjust

Function semundo_adjust

freebsd/kern/sysv_sem.c:444–515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

442 */
443
444static int
445semundo_adjust(struct thread *td, struct sem_undo **supptr, int semid,
446 int semseq, int semnum, int adjval)
447{
448 struct proc *p = td->td_proc;
449 struct sem_undo *suptr;
450 struct undo *sunptr;
451 int i;
452
453 SEMUNDO_LOCKASSERT(MA_OWNED);
454 /* Look for and remember the sem_undo if the caller doesn't provide
455 it */
456
457 suptr = *supptr;
458 if (suptr == NULL) {
459 LIST_FOREACH(suptr, &semu_list, un_next) {
460 if (suptr->un_proc == p) {
461 *supptr = suptr;
462 break;
463 }
464 }
465 if (suptr == NULL) {
466 if (adjval == 0)
467 return(0);
468 suptr = semu_alloc(td);
469 if (suptr == NULL)
470 return (ENOSPC);
471 *supptr = suptr;
472 }
473 }
474
475 /*
476 * Look for the requested entry and adjust it (delete if adjval becomes
477 * 0).
478 */
479 sunptr = &suptr->un_ent[0];
480 for (i = 0; i < suptr->un_cnt; i++, sunptr++) {
481 if (sunptr->un_id != semid || sunptr->un_num != semnum)
482 continue;
483 if (adjval != 0) {
484 adjval += sunptr->un_adjval;
485 if (adjval > seminfo.semaem || adjval < -seminfo.semaem)
486 return (ERANGE);
487 }
488 sunptr->un_adjval = adjval;
489 if (sunptr->un_adjval == 0) {
490 suptr->un_cnt--;
491 if (i < suptr->un_cnt)
492 suptr->un_ent[i] =
493 suptr->un_ent[suptr->un_cnt];
494 if (suptr->un_cnt == 0)
495 semu_try_free(suptr);
496 }
497 return (0);
498 }
499
500 /* Didn't find the right entry - create it */
501 if (adjval == 0)

Callers 1

sys_semopFunction · 0.85

Calls 2

semu_allocFunction · 0.85
semu_try_freeFunction · 0.85

Tested by

no test coverage detected