2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * NaCl Service Runtime. Condition Variable Descriptor / Handle abstraction.
36 #include "native_client/include/portability.h"
44 #include "native_client/service_runtime/nacl_config.h"
45 #include "native_client/service_runtime/nacl_log.h"
46 #include "native_client/service_runtime/nacl_desc_base.h"
47 #include "native_client/service_runtime/nacl_desc_mutex.h"
49 #include "native_client/service_runtime/include/sys/errno.h"
50 #include "native_client/service_runtime/include/sys/fcntl.h"
51 #include "native_client/service_runtime/include/sys/mman.h"
53 #include "native_client/intermodule_comm/nacl_imc_c.h"
56 * This file contains the implementation for the NaClDescCondVar subclass
59 * NaClDescCondVar is the subclass that wraps host-OS condition
60 * variable abstractions
63 int NaClDescCondVarCtor(struct NaClDescCondVar
*self
)
65 struct NaClDesc
*basep
= (struct NaClDesc
*) self
;
67 if (!NaClDescCtor(basep
)) {
70 if (!NaClIntrCondVarCtor(&self
->cv
)) {
75 basep
->vtbl
= &kNaClDescCondVarVtbl
;
79 void NaClDescCondVarDtor(struct NaClDesc
*vself
)
81 struct NaClDescCondVar
*self
= (struct NaClDescCondVar
*) vself
;
83 NaClLog(4, "NaClDescCondVarDtor(0x%08x).\n",
85 NaClIntrCondVarDtor(&self
->cv
);
87 NaClDescDtor(&self
->base
);
90 int NaClDescCondVarClose(struct NaClDesc
*vself
,
91 struct NaClDescEffector
*effp
)
99 int NaClDescCondVarWait(struct NaClDesc
*vself
,
100 struct NaClDescEffector
*effp
,
101 struct NaClDesc
*mutex
)
103 struct NaClDescCondVar
*self
= (struct NaClDescCondVar
*) vself
;
104 struct NaClDescMutex
*mutex_desc
;
105 NaClSyncStatus status
;
107 if (mutex
->vtbl
->typeTag
!= NACL_DESC_MUTEX
) {
108 return -NACL_ABI_EINVAL
;
110 mutex_desc
= (struct NaClDescMutex
*)mutex
;
111 status
= NaClIntrCondVarWait(&self
->cv
,
114 return -NaClXlateNaClSyncStatus(status
);
117 int NaClDescCondVarTimedWaitAbs(struct NaClDesc
*vself
,
118 struct NaClDescEffector
*effp
,
119 struct NaClDesc
*mutex
,
120 struct nacl_abi_timespec
*ts
)
122 struct NaClDescCondVar
*self
= (struct NaClDescCondVar
*) vself
;
123 struct NaClDescMutex
*mutex_desc
;
124 NaClSyncStatus status
;
126 if (mutex
->vtbl
->typeTag
!= NACL_DESC_MUTEX
) {
127 return -NACL_ABI_EINVAL
;
129 mutex_desc
= (struct NaClDescMutex
*) mutex
;
131 status
= NaClIntrCondVarWait(&self
->cv
,
134 return -NaClXlateNaClSyncStatus(status
);
137 int NaClDescCondVarSignal(struct NaClDesc
*vself
,
138 struct NaClDescEffector
*effp
)
140 struct NaClDescCondVar
*self
= (struct NaClDescCondVar
*) vself
;
142 NaClSyncStatus status
= NaClIntrCondVarSignal(&self
->cv
);
143 return -NaClXlateNaClSyncStatus(status
);
146 int NaClDescCondVarBroadcast(struct NaClDesc
*vself
,
147 struct NaClDescEffector
*effp
)
149 struct NaClDescCondVar
*self
= (struct NaClDescCondVar
*) vself
;
151 NaClSyncStatus status
= NaClIntrCondVarBroadcast(&self
->cv
);
152 return -NaClXlateNaClSyncStatus(status
);
155 struct NaClDescVtbl
const kNaClDescCondVarVtbl
= {
157 NaClDescMapNotImplemented
,
158 NaClDescUnmapUnsafeNotImplemented
,
159 NaClDescUnmapNotImplemented
,
160 NaClDescReadNotImplemented
,
161 NaClDescWriteNotImplemented
,
162 NaClDescSeekNotImplemented
,
163 NaClDescIoctlNotImplemented
,
164 NaClDescFstatNotImplemented
,
165 NaClDescCondVarClose
,
166 NaClDescGetdentsNotImplemented
,
168 NaClDescExternalizeSizeNotImplemented
,
169 NaClDescExternalizeNotImplemented
,
170 NaClDescLockNotImplemented
,
171 NaClDescTryLockNotImplemented
,
172 NaClDescUnlockNotImplemented
,
174 NaClDescCondVarTimedWaitAbs
,
175 NaClDescCondVarSignal
,
176 NaClDescCondVarBroadcast
,
177 NaClDescSendMsgNotImplemented
,
178 NaClDescRecvMsgNotImplemented
,
179 NaClDescConnectAddrNotImplemented
,
180 NaClDescAcceptConnNotImplemented
,
181 NaClDescPostNotImplemented
,
182 NaClDescSemWaitNotImplemented
,
183 NaClDescGetValueNotImplemented
,
186 int NaClDescCondVarInternalize(struct NaClDesc
**baseptr
,
187 struct NaClDescXferState
*xfer
)
189 NaClLog(LOG_ERROR
, "NaClDescCondVarInternalize: not shared yet\n");
190 return -NACL_ABI_EINVAL
;