2 * (c) 2010 Cyrill Gorcunov, gorcunov@gmail.com
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 #include <sys/param.h>
30 #include <sys/types.h>
34 #include "backend-proto.h"
37 static pthread_rwlock_t rwlock
= PTHREAD_RWLOCK_INITIALIZER
;
38 static struct backend_proto protocols
[BACKEND_PROTO_MAX
];
40 struct backend_proto
*backend_proto_register(struct backend_proto
*proto
)
42 struct backend_proto
*p
= NULL
;
43 unsigned int i
, j
= -1U;
45 pthread_rwlock_rdlock(&rwlock
);
47 for (i
= 0; i
< ARRAY_SIZE(protocols
); i
++) {
48 if (protocols
[i
].protocol
== BACKEND_PROTO_NONE
) {
51 } else if (protocols
[i
].protocol
== proto
->protocol
) {
57 protocols
[j
] = *proto
;
63 pthread_rwlock_unlock(&rwlock
);
67 void backend_proto_unregister(struct backend_proto
*proto
)
71 pthread_rwlock_wrlock(&rwlock
);
73 for (i
= 0; i
< ARRAY_SIZE(protocols
); i
++) {
74 if (protocols
[i
].protocol
== proto
->protocol
) {
75 protocols
[i
].protocol
= BACKEND_PROTO_NONE
;
80 pthread_rwlock_unlock(&rwlock
);
83 struct backend_proto
*backend_proto_find(enum backend_protocols proto
)
85 struct backend_proto
*p
= NULL
;
88 pthread_rwlock_rdlock(&rwlock
);
90 for (i
= 0; i
< ARRAY_SIZE(protocols
); i
++) {
91 if (protocols
[i
].protocol
== proto
) {
97 pthread_rwlock_unlock(&rwlock
);