• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <pthread.h>
17 #include <threads.h>
18 #include "functionalext.h"
19 
20 mtx_t mtx;
21 cnd_t cnd;
cnd_waitfirst(void * arg)22 void cnd_waitfirst(void *arg)
23 {
24     int res = -1;
25     mtx_lock(&mtx);
26     res = cnd_wait(&cnd, &mtx);
27     EXPECT_EQ("cnd_wait_0100", res, thrd_success);
28     mtx_unlock(&mtx);
29 }
30 
31 /**
32  * @tc.name      : cnd_wait_0100
33  * @tc.desc      : The parameter is valid and can block the calling thread and release the specified mutex
34  * @tc.level     : Level 0
35  */
cnd_wait_0100(void)36 void cnd_wait_0100(void)
37 {
38     thrd_t id1;
39     int ret;
40     cnd_init(&cnd);
41     mtx_init(&mtx, 0);
42     ret = thrd_create(&id1, (thrd_start_t)cnd_waitfirst, (void *)1);
43     EXPECT_EQ("cnd_wait_0100", ret, 0);
44     sleep(2);
45     mtx_lock(&mtx);
46     cnd_signal(&cnd);
47     mtx_unlock(&mtx);
48     thrd_join(id1, NULL);
49     cnd_destroy(&cnd);
50     mtx_destroy(&mtx);
51 }
52 
main(int argc,char * argv[])53 int main(int argc, char *argv[])
54 {
55     cnd_wait_0100();
56     return t_status;
57 }