Cygwin: strptime: add release note
[newlib-cygwin.git] / winsup / cygwin / sem.cc
blobfc23cfb083a885c49354e97bda8a4a0988ced997
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
7 details. */
9 #include "winsup.h"
10 #include <unistd.h>
12 #include "sigproc.h"
14 #include "cygserver_sem.h"
15 #include "cygtls.h"
18 * client_request_sem Constructors
21 client_request_sem::client_request_sem (int semid,
22 int semnum,
23 int cmd,
24 union semun *arg)
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,
39 int nsems,
40 int semflg)
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,
54 struct sembuf *sops,
55 size_t nsops)
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.
72 extern "C" int
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)
79 va_list ap;
80 va_start (ap, cmd);
81 arg = va_arg (ap, union semun);
82 va_end (ap);
84 syscall_printf ("semctl (semid = %d, semnum = %d, cmd = %d, arg = %p)",
85 semid, semnum, cmd, arg.buf);
86 __try
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 ());
93 __leave;
95 return request.retval ();
97 __except (EFAULT) {}
98 __endtry
99 return -1;
102 extern "C" int
103 semget (key_t key, int nsems, int semflg)
105 syscall_printf ("semget (key = %U, nsems = %d, semflg = %y)",
106 key, nsems, semflg);
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 ());
112 return -1;
114 return request.retval ();
117 extern "C" int
118 semop (int semid, struct sembuf *sops, size_t nsops)
120 syscall_printf ("semop (semid = %d, sops = %p, nsops = %ld)",
121 semid, sops, nsops);
122 __try
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 ());
129 __leave;
131 return request.retval ();
133 __except (EFAULT) {}
134 __endtry
135 return -1;