summaryrefslogtreecommitdiff
path: root/libhurd-cap-server/bucket-inhibit.c
diff options
context:
space:
mode:
authormarcus <marcus>2004-04-08 00:40:38 +0000
committermarcus <marcus>2004-04-08 00:40:38 +0000
commitd6c70dba6b1f3cb64c38fbaa4c8b14dbb257a10c (patch)
tree153d25793fb71603311f2c2d17309bcfe2f88537 /libhurd-cap-server/bucket-inhibit.c
parenta93fd7dadd804e2765de74a8792d2608505ed93c (diff)
2004-04-08 Marcus Brinkmann <marcus@gnu.org>
* bucket-inject.c, obj-copy-out.c: New files. * Makefile.am (libhurd_cap_server_a_SOURCES): Add bucket-inject.c and obj-copy-out.c * bucket-create.c (hurd_cap_bucket_create): Initialize members is_managed, nr_caps, waiting_rpcs of BUCKET. Set R_BUCKET. * cap-server-intern.h (_hurd_cap_client_dealloc): Add new argument BUCKET to prototype. (struct hurd_cap_client): Remove declaration. (struct _hurd_cap_list_item): Add new member tid. Change type for member client to _hurd_cap_client_t. (_hurd_cap_list_item_add, _hurd_cap_list_item_remove, _hurd_cap_list_item_dequeued): New inline functions. (struct _hurd_cap_obj_entry): Rename member IDX to ID. (_hurd_cap_obj_copy_out): New prototype. (_hurd_cap_client_create): Remove argument R_IDX from prototype. (struct _hurd_cap_bucket): Add new members MANAGER, IS_MANAGED, IS_MANAGER_WAITING, NR_CAPS, WAITING_RPCS, and FREE_WORKER. (_hurd_cap_client_t): Type definition moved to ... * cap-server.h (_hurd_cap_client_t): Here. (struct _hurd_cap_client_t): New declaration. (struct hurd_cap_rpc_context): Define it. (hurd_cap_class_demux_t): Renamed to ... (hurd_cap_class_demuxer_t): ... this. (hurd_cap_class_create, hurd_cap_class_init): Use new type for demuxer argument in prototype. (hurd_cap_bucket_inject): New prototype. * cap-server.h: Include <hurd/types.h> * class-create (hurd_cap_class_create): Use new type for demuxer argument. Set R_CLASS. * class-init (hurd_cap_class_init): Use new type for demuxer argument. * client-release.c (_hurd_cap_client_dealloc): Take new argument BUCKET. New local variable NR_CAPS. Keep track of number of capabilities removed. Update BUCKET->nr_caps before return. (_hurd_cap_client_release): Pass new argument BUCKET to _hurd_cap_client_release. * client-create.c (_hurd_cap_client_create): Remove argument R_IDX. Consequently, do not set R_IDX anymore. Set R_CLIENT. Pass new argument BUCKET to _hurd_cap_client_dealloc. * bucket-inhibit.c (hurd_cap_bucket_end): Check BUCKET->nr_caps if FORCE flag is not set. Cancel the manager thread if needed. (_hurd_cap_bucket_cond_busy): Move to ... * cap-server-intern.h (_hurd_cap_bucket_cond_busy): ... here. Add attribute always-inline. (_hurd_cap_bucket_cond_check): New inline function. * client-inhibit.c (_hurd_cap_client_cond_busy): Move to ... * cap-server-intern.h (_hurd_cap_client_cond_busy): ... here. Add attribute always-inline. (_hurd_cap_client_cond_check): New inline function. * class-inhibit.c (_hurd_cap_class_cond_busy): Move to ... * cap-server-intern.h (_hurd_cap_class_cond_busy): ... here. Add attribute always-inline. (_hurd_cap_class_cond_check): New inline function. * obj-inhibit.c (_hurd_cap_obj_cond_busy): Move to ... * cap-server-intern.h (_hurd_cap_obj_cond_busy): ... here. Add attribute always-inline. (_hurd_cap_obj_cond_check): New inline function.
Diffstat (limited to 'libhurd-cap-server/bucket-inhibit.c')
-rw-r--r--libhurd-cap-server/bucket-inhibit.c34
1 files changed, 9 insertions, 25 deletions
diff --git a/libhurd-cap-server/bucket-inhibit.c b/libhurd-cap-server/bucket-inhibit.c
index 1e0d400..09e15f9 100644
--- a/libhurd-cap-server/bucket-inhibit.c
+++ b/libhurd-cap-server/bucket-inhibit.c
@@ -30,23 +30,6 @@
#include "cap-server-intern.h"
-/* Return true if there are still outstanding RPCs in this bucket, and
- fails if not. This is only valid if hurd_cap_bucket_inhibit is in
- progress (ie, if bucket->state is _HURD_CAP_STATE_YELLOW).
- FIXME: We will need this in the RPC worker thread code, where the
- last worker will get false as return value and then has to change
- the state to RED and signal (broadcast?) the condition. */
-static inline int
-_hurd_cap_bucket_cond_busy (hurd_cap_bucket_t bucket)
-{
- /* We have to remain in the state yellow until there are no pending
- RPC threads except maybe the waiter. */
- return bucket->pending_rpcs
- && (bucket->pending_rpcs->thread != bucket->cond_waiter
- || bucket->pending_rpcs->next);
-}
-
-
/* Inhibit all RPCs on the capability bucket BUCKET (which must not
be locked). You _must_ follow up with a hurd_cap_bucket_resume
operation, and hold at least one reference to the object
@@ -62,6 +45,8 @@ hurd_cap_bucket_inhibit (hurd_cap_bucket_t bucket)
this function is called within an RPC, we are going to be
canceled anyway. Otherwise, it ensures that bucket inhibitions
are fully serialized (per bucket). */
+ /* FIXME: Do something if the state is _HURD_CAP_STATE_BLACK? Can
+ only happen if we are called from outside any RPCs. */
while (bucket->state != _HURD_CAP_STATE_GREEN)
{
err = hurd_cond_wait (&bucket->cond, &bucket->lock);
@@ -137,20 +122,19 @@ hurd_cap_bucket_end (hurd_cap_bucket_t bucket, bool force)
{
pthread_mutex_lock (&bucket->lock);
- /* FIXME: Check if we can go away while honoring the FORCE flag. */
+ if (!force && bucket->nr_caps)
+ {
+ pthread_mutex_unlock (&bucket->lock);
+ return EBUSY;
+ }
bucket->state = _HURD_CAP_STATE_BLACK;
/* Broadcast the change to all potential waiters. */
pthread_cond_broadcast (&bucket->cond);
- /* FIXME: This is not enough. We need to cancel or otherwise notify
- the manager thread that it is supposed to go away, if it is
- currently blocking in an open receive. For example, we could
- send it a special message. However, the manager thread must
- ensure that our own thread is correctly finished (ie, if we are
- called from within an RPC, the RPC must finish before the manager
- thread is allowed to go away. */
+ if (bucket->is_managed && bucket->cond_waiter != bucket->manager)
+ pthread_cancel (bucket->manager);
pthread_mutex_unlock (&bucket->lock);
}