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 basep
->vtbl
= (struct NaClDescVtbl
*) NULL
;
68 if (!NaClDescCtor(basep
)) {
71 if (!NaClIntrCondVarCtor(&self
->cv
)) {
76 basep
->vtbl
= &kNaClDescCondVarVtbl
;
80 void NaClDescCondVarDtor(struct NaClDesc
*vself
)
82 struct NaClDescCondVar
*self
= (struct NaClDescCondVar
*) vself
;
84 NaClLog(4, "NaClDescCondVarDtor(0x%08"PRIxPTR
").\n",
86 NaClIntrCondVarDtor(&self
->cv
);
88 vself
->vtbl
= (struct NaClDescVtbl
*) NULL
;
89 NaClDescDtor(&self
->base
);
92 int NaClDescCondVarClose(struct NaClDesc
*vself
,
93 struct NaClDescEffector
*effp
)
101 int NaClDescCondVarWait(struct NaClDesc
*vself
,
102 struct NaClDescEffector
*effp
,
103 struct NaClDesc
*mutex
)
105 struct NaClDescCondVar
*self
= (struct NaClDescCondVar
*) vself
;
106 struct NaClDescMutex
*mutex_desc
;
107 NaClSyncStatus status
;
109 if (mutex
->vtbl
->typeTag
!= NACL_DESC_MUTEX
) {
110 return -NACL_ABI_EINVAL
;
112 mutex_desc
= (struct NaClDescMutex
*)mutex
;
113 status
= NaClIntrCondVarWait(&self
->cv
,
116 return -NaClXlateNaClSyncStatus(status
);
119 int NaClDescCondVarTimedWaitAbs(struct NaClDesc
*vself
,
120 struct NaClDescEffector
*effp
,
121 struct NaClDesc
*mutex
,
122 struct nacl_abi_timespec
*ts
)
124 struct NaClDescCondVar
*self
= (struct NaClDescCondVar
*) vself
;
125 struct NaClDescMutex
*mutex_desc
;
126 NaClSyncStatus status
;
128 if (mutex
->vtbl
->typeTag
!= NACL_DESC_MUTEX
) {
129 return -NACL_ABI_EINVAL
;
131 mutex_desc
= (struct NaClDescMutex
*) mutex
;
133 status
= NaClIntrCondVarWait(&self
->cv
,
136 return -NaClXlateNaClSyncStatus(status
);
139 int NaClDescCondVarSignal(struct NaClDesc
*vself
,
140 struct NaClDescEffector
*effp
)
142 struct NaClDescCondVar
*self
= (struct NaClDescCondVar
*) vself
;
144 NaClSyncStatus status
= NaClIntrCondVarSignal(&self
->cv
);
145 return -NaClXlateNaClSyncStatus(status
);
148 int NaClDescCondVarBroadcast(struct NaClDesc
*vself
,
149 struct NaClDescEffector
*effp
)
151 struct NaClDescCondVar
*self
= (struct NaClDescCondVar
*) vself
;
153 NaClSyncStatus status
= NaClIntrCondVarBroadcast(&self
->cv
);
154 return -NaClXlateNaClSyncStatus(status
);
157 struct NaClDescVtbl
const kNaClDescCondVarVtbl
= {
159 NaClDescMapNotImplemented
,
160 NaClDescUnmapUnsafeNotImplemented
,
161 NaClDescUnmapNotImplemented
,
162 NaClDescReadNotImplemented
,
163 NaClDescWriteNotImplemented
,
164 NaClDescSeekNotImplemented
,
165 NaClDescIoctlNotImplemented
,
166 NaClDescFstatNotImplemented
,
167 NaClDescCondVarClose
,
168 NaClDescGetdentsNotImplemented
,
170 NaClDescExternalizeSizeNotImplemented
,
171 NaClDescExternalizeNotImplemented
,
172 NaClDescLockNotImplemented
,
173 NaClDescTryLockNotImplemented
,
174 NaClDescUnlockNotImplemented
,
176 NaClDescCondVarTimedWaitAbs
,
177 NaClDescCondVarSignal
,
178 NaClDescCondVarBroadcast
,
179 NaClDescSendMsgNotImplemented
,
180 NaClDescRecvMsgNotImplemented
,
181 NaClDescConnectAddrNotImplemented
,
182 NaClDescAcceptConnNotImplemented
,
183 NaClDescPostNotImplemented
,
184 NaClDescSemWaitNotImplemented
,
185 NaClDescGetValueNotImplemented
,
188 int NaClDescCondVarInternalize(struct NaClDesc
**baseptr
,
189 struct NaClDescXferState
*xfer
)
191 NaClLog(LOG_ERROR
, "NaClDescCondVarInternalize: not shared yet\n");
192 return -NACL_ABI_EINVAL
;