• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2022-11-15
13  * Description: 读写锁模块内部头文件。
14  */
15 #ifndef PRT_RWLOCK_INTERNAL_H
16 #define PRT_RWLOCK_INTERNAL_H
17 
18 #include "prt_buildef.h"
19 #include "prt_typedef.h"
20 #include "prt_list_external.h"
21 
22 #define RWLOCK_COUNT_MASK 0x0000FFFFU
23 #define RWLOCK_MAGIC_NUM  0xFDCAU
24 
25 enum RwlockMode {
26     RWLOCK_NONE_MODE,
27     RWLOCK_READ_MODE,
28     RWLOCK_WRITE_MODE,
29     RWLOCK_READFIRST_MODE,
30     RWLOCK_WRITEFIRST_MODE
31 };
32 
33 enum RwlockType {
34     RWLOCK_RD,
35     RWLOCK_TRYRD,
36     RWLOCK_TIMERD,
37     RWLOCK_WR,
38     RWLOCK_TRYWR,
39     RWLOCK_TIMEWR
40 };
41 
42 #if defined(OS_POSIX_TYPE_NEWLIB)
43 typedef struct prt_pthread_rwlock_s {
44     U32 rw_magic : 16;
45     U32 index : 16;
46     int rw_count;
47     void *rw_owner;
48     struct prt_pthread_rwlock_s *next;
49     struct TagListObject rw_write;
50     struct TagListObject rw_read;
51 } prt_pthread_rwlock_t;
52 #else
53 typedef pthread_rwlock_t prt_pthread_rwlock_t;
54 #endif
55 
56 extern U32 OsRwLockRdPend(prt_pthread_rwlock_t *rwl, U32 timeout, U32 rwType);
57 extern U32 OsRwLockWrPend(prt_pthread_rwlock_t *rwl, U32 timeout, U32 rwType);
58 extern U32 OsRwLockUnlock(prt_pthread_rwlock_t *rwl, bool *needSched);
59 
60 #endif /* PRT_RWLOCK_INTERNAL_H */
61