+#define PTHRW_RFU_64BIT 124 /* 31 * sizeof(uint32_t) */
+#define PTHRW_RFU_32BIT 72 /* 18 * sizeof(uint32_t) */
+
+#define _PTHREAD_RWLOCK_T
+typedef struct {
+ long sig;
+ pthread_lock_t lock;
+#if defined(__LP64__)
+ int reserv;
+ volatile uint32_t rw_seq[4];
+ pthread_t rw_owner;
+#else /* __LP64__ */
+ volatile uint32_t rw_seq[4];
+ pthread_t rw_owner;
+ int reserv;
+#endif /* __LP64__ */
+ volatile uint32_t * rw_lcntaddr;
+ volatile uint32_t * rw_seqaddr;
+ volatile uint32_t * rw_ucntaddr;
+ uint32_t rw_flags;
+ int misalign;
+#if defined(__LP64__)
+ char rfu[PTHRW_RFU_64BIT];
+#else /* __LP64__ */
+ char rfu[PTHRW_RFU_32BIT];
+#endif /* __LP64__ */
+ int pshared;
+} npthread_rwlock_t;
+
+/* flags for rw_flags */
+#define PTHRW_KERN_PROCESS_SHARED 0x10
+#define PTHRW_KERN_PROCESS_PRIVATE 0x20
+#define PTHRW_KERN_PROCESS_FLAGS_MASK 0x30
+#define _PTHREAD_RWLOCK_UPGRADE_TRY 0x10000
+
+/* New model bits on Lword */
+#define PTH_RWL_KBIT 0x01 /* users cannot acquire in user mode */
+#define PTH_RWL_EBIT 0x02 /* exclusive lock in progress */
+#define PTH_RWL_WBIT 0x04 /* write waiters pending in kernel */
+#define PTH_RWL_PBIT 0x04 /* prepost (cv) pending in kernel */
+#define PTH_RWL_YBIT 0x08 /* yielding write waiters pending in kernel */
+#define PTH_RWL_RETRYBIT 0x08 /* mutex retry wait */
+#define PTH_RWL_LBIT 0x10 /* long read in progress */
+#define PTH_RWL_MTXNONE 0x10 /* indicates the cvwait does not have mutex held */
+#define PTH_RWL_UBIT 0x20 /* upgrade request pending */
+#define PTH_RWL_MTX_WAIT 0x20 /* in cvar in mutex wait */
+#define PTH_RWL_RBIT 0x40 /* reader pending in kernel(not used) */
+#define PTH_RWL_MBIT 0x40 /* overlapping grants from kernel */
+#define PTH_RWL_TRYLKBIT 0x40 /* sets try lock attempt */
+#define PTH_RWL_IBIT 0x80 /* lock reset, held untill first succeesful unlock */
+
+/* UBIT values for mutex, cvar */
+#define PTH_RWU_SBIT 0x01
+#define PTH_RWU_BBIT 0x02
+
+#define PTHRW_RWL_INIT PTH_RWL_IBIT /* reset on the lock bits (U)*/
+#define PTHRW_RWLOCK_INIT (PTH_RWL_IBIT | PTH_RWL_RBIT) /* reset on the lock bits (U)*/
+#define PTH_RWLOCK_RESET_RBIT 0xffffffbf
+
+#define PTHRW_INC 0x100
+#define PTHRW_BIT_MASK 0x000000ff
+
+#define PTHRW_UN_BIT_MASK 0x000000bf /* remove overlap bit */
+
+
+/* New model bits on Sword */
+#define PTH_RWS_SBIT 0x01 /* kernel transition seq not set yet*/
+#define PTH_RWS_IBIT 0x02 /* Sequence is not set on return from kernel */
+
+#define PTH_RWS_CV_CBIT PTH_RWS_SBIT /* kernel has cleared all info w.r.s.t CV */
+#define PTH_RWS_CV_PBIT PTH_RWS_IBIT /* kernel has prepost/fake structs only,no waiters */
+#define PTH_RWS_CV_BITSALL (PTH_RWS_CV_CBIT | PTH_RWS_CV_PBIT)
+#define PTH_RWS_CV_MBIT PTH_RWL_MBIT /* to indicate prepost return from kernel */
+#define PTH_RWS_CV_RESET_PBIT 0xfffffffd
+
+#define PTH_RWS_WSVBIT 0x04 /* save W bit */
+#define PTH_RWS_USVBIT 0x08 /* save U bit */
+#define PTH_RWS_YSVBIT 0x10 /* save Y bit */
+#define PTHRW_RWS_INIT PTH_RWS_SBIT /* reset on the lock bits (U)*/
+#define PTHRW_RWS_SAVEMASK (PTH_RWS_WSVBIT|PTH_RWS_USVBIT|PTH_RWS_YSVBIT) /*save bits mask*/
+#define PTHRW_SW_Reset_BIT_MASK 0x000000fe /* remove S bit and get rest of the bits */
+
+#define PTHRW_COUNT_SHIFT 8
+#define PTHRW_COUNT_MASK 0xffffff00
+#define PTHRW_MAX_READERS 0xffffff00
+
+
+#define PTHREAD_MTX_TID_SWITCHING (uint64_t)-1
+
+/* new L word defns */
+#define can_rwl_readinuser(x) ((((x) & (PTH_RWL_UBIT | PTH_RWL_WBIT | PTH_RWL_KBIT)) == 0)||(((x) & PTH_RWL_LBIT) != 0))
+#define can_rwl_longreadinuser(x) (((x) & (PTH_RWL_UBIT | PTH_RWL_WBIT | PTH_RWL_KBIT | PTH_RWL_YBIT)) == 0)
+#define is_rwl_ebit_set(x) (((x) & PTH_RWL_EBIT) != 0)
+#define is_rwl_eubit_set(x) (((x) & (PTH_RWL_EBIT | PTH_RWL_UBIT)) != 0)
+#define is_rwl_wbit_set(x) (((x) & PTH_RWL_WBIT) != 0)
+#define is_rwl_lbit_set(x) (((x) & PTH_RWL_LBIT) != 0)
+#define is_rwl_ebit_clear(x) (((x) & PTH_RWL_EBIT) == 0)
+#define is_rwl_lbit_clear(x) (((x) & PTH_RWL_LBIT) == 0)
+#define is_rwl_readoverlap(x) (((x) & PTH_RWL_MBIT) != 0)
+
+/* S word checks */
+#define is_rws_setseq(x) (((x) & PTH_RWS_SBIT))
+#define is_rws_setunlockinit(x) (((x) & PTH_RWS_IBIT))
+
+/* is x lower than Y */
+static inline int is_seqlower(uint32_t x, uint32_t y) {
+ if (x < y) {
+ if ((y-x) < (PTHRW_MAX_READERS/2))
+ return(1);
+ } else {
+ if ((x-y) > (PTHRW_MAX_READERS/2))
+ return(1);
+ }
+ return(0);
+}
+
+/* is x lower than or eq Y */
+static inline int is_seqlower_eq(uint32_t x, uint32_t y) {
+ if (x==y)
+ return(1);
+ else
+ return(is_seqlower(x,y));
+}
+
+/* is x greater than Y */
+static inline int is_seqhigher(uint32_t x, uint32_t y) {
+ if (x > y) {
+ if ((x-y) < (PTHRW_MAX_READERS/2))
+ return(1);
+ } else {
+ if ((y-x) > (PTHRW_MAX_READERS/2))
+ return(1);
+ }
+ return(0);
+}
+
+static inline int diff_genseq(uint32_t x, uint32_t y) {
+ if (x == y) {
+ return(0);
+ } else if (x > y) {
+ return(x-y);
+ } else {
+ return((PTHRW_MAX_READERS - y) + x + PTHRW_INC);
+ }
+}
+