1 /* sem.cc: XSI IPC interface for Cygwin.
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
14 #include "cygserver_sem.h"
18 * client_request_sem Constructors
21 client_request_sem::client_request_sem (int semid
,
25 : client_request (CYGSERVER_REQUEST_SEM
, &_parameters
, sizeof (_parameters
))
27 _parameters
.in
.semop
= SEMOP_semctl
;
28 ipc_set_proc_info (_parameters
.in
.ipcblk
);
30 _parameters
.in
.ctlargs
.semid
= semid
;
31 _parameters
.in
.ctlargs
.semnum
= semnum
;
32 _parameters
.in
.ctlargs
.cmd
= cmd
;
33 _parameters
.in
.ctlargs
.arg
= arg
;
35 msglen (sizeof (_parameters
.in
));
38 client_request_sem::client_request_sem (key_t key
,
41 : client_request (CYGSERVER_REQUEST_SEM
, &_parameters
, sizeof (_parameters
))
43 _parameters
.in
.semop
= SEMOP_semget
;
44 ipc_set_proc_info (_parameters
.in
.ipcblk
);
46 _parameters
.in
.getargs
.key
= key
;
47 _parameters
.in
.getargs
.nsems
= nsems
;
48 _parameters
.in
.getargs
.semflg
= semflg
;
50 msglen (sizeof (_parameters
.in
));
53 client_request_sem::client_request_sem (int semid
,
56 : client_request (CYGSERVER_REQUEST_SEM
, &_parameters
, sizeof (_parameters
))
58 _parameters
.in
.semop
= SEMOP_semop
;
59 ipc_set_proc_info (_parameters
.in
.ipcblk
);
61 _parameters
.in
.opargs
.semid
= semid
;
62 _parameters
.in
.opargs
.sops
= sops
;
63 _parameters
.in
.opargs
.nsops
= nsops
;
65 msglen (sizeof (_parameters
.in
));
69 * XSI semaphore API. These are exported by the DLL.
73 semctl (int semid
, int semnum
, int cmd
, ...)
75 union semun arg
= {0};
76 if (cmd
== IPC_STAT
|| cmd
== IPC_SET
|| cmd
== IPC_INFO
|| cmd
== SEM_INFO
77 || cmd
== GETALL
|| cmd
== SETALL
|| cmd
== SETVAL
)
81 arg
= va_arg (ap
, union semun
);
84 syscall_printf ("semctl (semid = %d, semnum = %d, cmd = %d, arg = %p)",
85 semid
, semnum
, cmd
, arg
.buf
);
88 client_request_sem
request (semid
, semnum
, cmd
, &arg
);
89 if (request
.make_request () == -1 || request
.retval () == -1)
91 syscall_printf ("-1 [%d] = semctl ()", request
.error_code ());
92 set_errno (request
.error_code ());
95 return request
.retval ();
103 semget (key_t key
, int nsems
, int semflg
)
105 syscall_printf ("semget (key = %U, nsems = %d, semflg = %y)",
107 client_request_sem
request (key
, nsems
, semflg
);
108 if (request
.make_request () == -1 || request
.retval () == -1)
110 syscall_printf ("-1 [%d] = semget ()", request
.error_code ());
111 set_errno (request
.error_code ());
114 return request
.retval ();
118 semop (int semid
, struct sembuf
*sops
, size_t nsops
)
120 syscall_printf ("semop (semid = %d, sops = %p, nsops = %ld)",
124 client_request_sem
request (semid
, sops
, nsops
);
125 if (request
.make_request () == -1 || request
.retval () == -1)
127 syscall_printf ("-1 [%d] = semop ()", request
.error_code ());
128 set_errno (request
.error_code ());
131 return request
.retval ();