File: fio_shared_sem.c

package info (click to toggle)
fio 3.41-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,012 kB
  • sloc: ansic: 82,290; python: 9,862; sh: 6,067; makefile: 813; yacc: 204; lex: 184
file content (42 lines) | stat: -rw-r--r-- 1,003 bytes parent folder | download
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
/*
 * Separate out the two helper functions for fio_sem from "fio_sem.c".
 * These two functions depend on fio shared memory. Other fio_sem
 * functions in "fio_sem.c" are used for fio shared memory. This file
 * separation is required to avoid build failures caused by circular
 * dependency.
 */

#include <stdio.h>

#include "fio_sem.h"
#include "smalloc.h"

/*
 * Allocate and initialize fio_sem lock object in the same manner as
 * fio_sem_init(), except the lock object is allocated from the fio
 * shared memory. This allows the parent process to free the lock
 * allocated by child processes.
 */
struct fio_sem *fio_shared_sem_init(int value)
{
	struct fio_sem *sem;

	sem = smalloc(sizeof(struct fio_sem));
	if (!sem)
		return NULL;

	if (!__fio_sem_init(sem, value))
		return sem;

	fio_shared_sem_remove(sem);
	return NULL;
}

/*
 * Free the fio_sem lock object allocated by fio_shared_sem_init().
 */
void fio_shared_sem_remove(struct fio_sem *sem)
{
	__fio_sem_remove(sem);
	sfree(sem);
}