1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <threads.h>
17 #include "functionalext.h"
18
19 mtx_t mtx;
20 cnd_t cndPut;
cnd_timedwaitfirst(void * arg)21 void cnd_timedwaitfirst(void *arg)
22 {
23 int res = -1;
24 struct timespec ts;
25 mtx_lock(&mtx);
26 res = cnd_timedwait(&cndPut, &mtx, &ts);
27 mtx_unlock(&mtx);
28 }
29
30 /**
31 * @tc.name : cnd_signal_0100
32 * @tc.desc : The parameter is valid, among any number of threads waiting for the specified condition
33 * variable, wake up one of the threads.
34 * @tc.level : Level 0
35 */
cnd_signal_0100(void)36 void cnd_signal_0100(void)
37 {
38 thrd_t id1;
39 int ret;
40 int res = -1;
41 cnd_init(&cndPut);
42 mtx_init(&mtx, 0);
43 ret = thrd_create(&id1, (thrd_start_t)cnd_timedwaitfirst, (void *)1);
44 EXPECT_EQ("cnd_signal_0100", ret, 0);
45
46 sleep(2);
47 mtx_lock(&mtx);
48 res = cnd_signal(&cndPut);
49 EXPECT_EQ("cnd_signal_0100", res, thrd_success);
50 mtx_unlock(&mtx);
51 thrd_join(id1, NULL);
52 cnd_destroy(&cndPut);
53 mtx_destroy(&mtx);
54 }
55
main(int argc,char * argv[])56 int main(int argc, char *argv[])
57 {
58 cnd_signal_0100();
59 return t_status;
60 }