comparison libfdcore/hooks.c @ 1196:90d1222a65a8

Rename HOOK_PEER_LAST to HOOK_LAST
author Sebastien Decugis <sdecugis@freediameter.net>
date Tue, 11 Jun 2013 14:04:40 +0800
parents 56c36d1007b4
children 40330b75c044
comparison
equal deleted inserted replaced
1195:dcc467aeda12 1196:90d1222a65a8
53 53
54 #define sizeof_pmd(hdl) (((size_t)&((struct pmd_list_item *)0)->pmd) + hdl->pmd_size) 54 #define sizeof_pmd(hdl) (((size_t)&((struct pmd_list_item *)0)->pmd) + hdl->pmd_size)
55 55
56 /* Now a hook registered by an extension */ 56 /* Now a hook registered by an extension */
57 struct fd_hook_hdl { 57 struct fd_hook_hdl {
58 struct fd_list chain[HOOK_PEER_LAST+1]; 58 struct fd_list chain[HOOK_LAST+1];
59 void (*fd_hook_cb)(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata); 59 void (*fd_hook_cb)(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata);
60 void *regdata; 60 void *regdata;
61 struct fd_hook_data_hdl *data_hdl; 61 struct fd_hook_data_hdl *data_hdl;
62 }; 62 };
63 63
64 /* Array of those hooks */ 64 /* Array of those hooks */
65 struct { 65 struct {
66 struct fd_list sentinel; 66 struct fd_list sentinel;
67 pthread_rwlock_t rwlock; 67 pthread_rwlock_t rwlock;
68 } HS_array[HOOK_PEER_LAST+1]; 68 } HS_array[HOOK_LAST+1];
69 69
70 /* Initialize the array of sentinels for the hooks */ 70 /* Initialize the array of sentinels for the hooks */
71 int fd_hooks_init(void) 71 int fd_hooks_init(void)
72 { 72 {
73 int i; 73 int i;
74 for (i=0; i <= HOOK_PEER_LAST; i++) { 74 for (i=0; i <= HOOK_LAST; i++) {
75 fd_list_init(&HS_array[i].sentinel, NULL); 75 fd_list_init(&HS_array[i].sentinel, NULL);
76 CHECK_POSIX( pthread_rwlock_init(&HS_array[i].rwlock, NULL) ); 76 CHECK_POSIX( pthread_rwlock_init(&HS_array[i].rwlock, NULL) );
77 } 77 }
78 return 0; 78 return 0;
79 } 79 }
126 126
127 newhdl->fd_hook_cb = fd_hook_cb; 127 newhdl->fd_hook_cb = fd_hook_cb;
128 newhdl->regdata = regdata; 128 newhdl->regdata = regdata;
129 newhdl->data_hdl = data_hdl; 129 newhdl->data_hdl = data_hdl;
130 130
131 for (i=0; i <= HOOK_PEER_LAST; i++) { 131 for (i=0; i <= HOOK_LAST; i++) {
132 fd_list_init(&newhdl->chain[i], newhdl); 132 fd_list_init(&newhdl->chain[i], newhdl);
133 if (type_mask & (1<<i)) { 133 if (type_mask & (1<<i)) {
134 CHECK_POSIX( pthread_rwlock_wrlock(&HS_array[i].rwlock) ); 134 CHECK_POSIX( pthread_rwlock_wrlock(&HS_array[i].rwlock) );
135 fd_list_insert_before( &HS_array[i].sentinel, &newhdl->chain[i]); 135 fd_list_insert_before( &HS_array[i].sentinel, &newhdl->chain[i]);
136 CHECK_POSIX( pthread_rwlock_unlock(&HS_array[i].rwlock) ); 136 CHECK_POSIX( pthread_rwlock_unlock(&HS_array[i].rwlock) );
146 { 146 {
147 int i; 147 int i;
148 TRACE_ENTRY("%p", handler); 148 TRACE_ENTRY("%p", handler);
149 CHECK_PARAMS( handler ); 149 CHECK_PARAMS( handler );
150 150
151 for (i=0; i <= HOOK_PEER_LAST; i++) { 151 for (i=0; i <= HOOK_LAST; i++) {
152 if ( ! FD_IS_LIST_EMPTY(&handler->chain[i])) { 152 if ( ! FD_IS_LIST_EMPTY(&handler->chain[i])) {
153 CHECK_POSIX( pthread_rwlock_wrlock(&HS_array[i].rwlock) ); 153 CHECK_POSIX( pthread_rwlock_wrlock(&HS_array[i].rwlock) );
154 fd_list_unlink(&handler->chain[i]); 154 fd_list_unlink(&handler->chain[i]);
155 CHECK_POSIX( pthread_rwlock_unlock(&HS_array[i].rwlock) ); 155 CHECK_POSIX( pthread_rwlock_unlock(&HS_array[i].rwlock) );
156 } 156 }
269 uint32_t ret = 0; 269 uint32_t ret = 0;
270 int next; 270 int next;
271 271
272 va_start(ap, dummy); 272 va_start(ap, dummy);
273 while ((next = va_arg(ap, int)) >= 0) { 273 while ((next = va_arg(ap, int)) >= 0) {
274 if (next > HOOK_PEER_LAST) 274 if (next > HOOK_LAST)
275 break; /* invalid parameter */ 275 break; /* invalid parameter */
276 ret |= (1<<next); 276 ret |= (1<<next);
277 } 277 }
278 va_end(ap); 278 va_end(ap);
279 279
282 282
283 /* The function that does the work of calling the extension's callbacks and also managing the permessagedata structures */ 283 /* The function that does the work of calling the extension's callbacks and also managing the permessagedata structures */
284 void fd_hook_call(enum fd_hook_type type, struct msg * msg, struct fd_peer * peer, void * other, struct fd_msg_pmdl * pmdl) 284 void fd_hook_call(enum fd_hook_type type, struct msg * msg, struct fd_peer * peer, void * other, struct fd_msg_pmdl * pmdl)
285 { 285 {
286 struct fd_list * li; 286 struct fd_list * li;
287 ASSERT(type <= HOOK_PEER_LAST); 287 ASSERT(type <= HOOK_LAST);
288 int call_default = 0; 288 int call_default = 0;
289 289
290 /* lock the list of hooks for this type */ 290 /* lock the list of hooks for this type */
291 CHECK_POSIX_DO( pthread_rwlock_rdlock(&HS_array[type].rwlock), ); 291 CHECK_POSIX_DO( pthread_rwlock_rdlock(&HS_array[type].rwlock), );
292 292
"Welcome to our mercurial repository"