This source file includes following definitions.
- rf_init_mcpair
- rf_clean_mcpair
- rf_ShutdownMCPair
- rf_ConfigureMCPair
- rf_AllocMCPair
- rf_FreeMCPair
- rf_MCPairWakeupFunc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 #include "rf_types.h"
38 #include "rf_threadstuff.h"
39 #include "rf_mcpair.h"
40 #include "rf_debugMem.h"
41 #include "rf_freelist.h"
42 #include "rf_shutdown.h"
43
44 #include <sys/proc.h>
45
46 static RF_FreeList_t *rf_mcpair_freelist;
47
48 #define RF_MAX_FREE_MCPAIR 128
49 #define RF_MCPAIR_INC 16
50 #define RF_MCPAIR_INITIAL 24
51
52 int rf_init_mcpair(RF_MCPair_t *);
53 void rf_clean_mcpair(RF_MCPair_t *);
54 void rf_ShutdownMCPair(void *);
55
56
57 int
58 rf_init_mcpair(RF_MCPair_t *t)
59 {
60 int rc;
61
62 rc = rf_mutex_init(&t->mutex);
63 if (rc) {
64 RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n",
65 __FILE__, __LINE__, rc);
66 return (rc);
67 }
68 rc = rf_cond_init(&t->cond);
69 if (rc) {
70 RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n",
71 __FILE__, __LINE__, rc);
72 rf_mutex_destroy(&t->mutex);
73 return (rc);
74 }
75 return (0);
76 }
77
78 void
79 rf_clean_mcpair(RF_MCPair_t *t)
80 {
81 rf_mutex_destroy(&t->mutex);
82 rf_cond_destroy(&t->cond);
83 }
84
85 void
86 rf_ShutdownMCPair(void *ignored)
87 {
88 RF_FREELIST_DESTROY_CLEAN(rf_mcpair_freelist, next, (RF_MCPair_t *),
89 rf_clean_mcpair);
90 }
91
92 int
93 rf_ConfigureMCPair(RF_ShutdownList_t **listp)
94 {
95 int rc;
96
97 RF_FREELIST_CREATE(rf_mcpair_freelist, RF_MAX_FREE_MCPAIR,
98 RF_MCPAIR_INC, sizeof(RF_MCPair_t));
99 rc = rf_ShutdownCreate(listp, rf_ShutdownMCPair, NULL);
100 if (rc) {
101 RF_ERRORMSG3("Unable to add to shutdown list file %s line %d"
102 " rc=%d\n", __FILE__, __LINE__, rc);
103 rf_ShutdownMCPair(NULL);
104 return (rc);
105 }
106 RF_FREELIST_PRIME_INIT(rf_mcpair_freelist, RF_MCPAIR_INITIAL, next,
107 (RF_MCPair_t *), rf_init_mcpair);
108 return (0);
109 }
110
111 RF_MCPair_t *
112 rf_AllocMCPair(void)
113 {
114 RF_MCPair_t *t;
115
116 RF_FREELIST_GET_INIT(rf_mcpair_freelist, t, next, (RF_MCPair_t *),
117 rf_init_mcpair);
118 if (t) {
119 t->flag = 0;
120 t->next = NULL;
121 }
122 return (t);
123 }
124
125 void
126 rf_FreeMCPair(RF_MCPair_t *t)
127 {
128 RF_FREELIST_FREE_CLEAN(rf_mcpair_freelist, t, next, rf_clean_mcpair);
129 }
130
131
132
133
134
135 void
136 rf_MCPairWakeupFunc(RF_MCPair_t *mcpair)
137 {
138 RF_LOCK_MUTEX(mcpair->mutex);
139 mcpair->flag = 1;
140 #if 0
141 printf("MCPairWakeupFunc called!\n");
142 #endif
143 wakeup(&(mcpair->flag));
144
145
146
147
148
149
150
151
152 wakeup(&(mcpair->cond));
153 RF_UNLOCK_MUTEX(mcpair->mutex);
154 }