]>
git.proxmox.com Git - ovs.git/blob - lib/guarded-list.c
2 * Copyright (c) 2013 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "guarded-list.h"
22 guarded_list_init(struct guarded_list
*list
)
24 ovs_mutex_init(&list
->mutex
);
25 list_init(&list
->list
);
30 guarded_list_destroy(struct guarded_list
*list
)
32 ovs_mutex_destroy(&list
->mutex
);
36 guarded_list_is_empty(const struct guarded_list
*list
)
40 ovs_mutex_lock(&list
->mutex
);
42 ovs_mutex_unlock(&list
->mutex
);
47 /* If 'list' has fewer than 'max' elements, adds 'node' at the end of the list
48 * and returns the number of elements now on the list.
50 * If 'list' already has at least 'max' elements, returns 0 without modifying
53 guarded_list_push_back(struct guarded_list
*list
,
54 struct ovs_list
*node
, size_t max
)
58 ovs_mutex_lock(&list
->mutex
);
60 list_push_back(&list
->list
, node
);
63 ovs_mutex_unlock(&list
->mutex
);
69 guarded_list_pop_front(struct guarded_list
*list
)
71 struct ovs_list
*node
= NULL
;
73 ovs_mutex_lock(&list
->mutex
);
75 node
= list_pop_front(&list
->list
);
78 ovs_mutex_unlock(&list
->mutex
);
84 guarded_list_pop_all(struct guarded_list
*list
, struct ovs_list
*elements
)
88 ovs_mutex_lock(&list
->mutex
);
89 list_move(elements
, &list
->list
);
92 list_init(&list
->list
);
94 ovs_mutex_unlock(&list
->mutex
);