dapl_evd_wait.c revision 9e39c5ba00a55fa05777cc94b148296af305e135
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CDDL HEADER START
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The contents of this file are subject to the terms of the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Common Development and Distribution License (the "License").
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * You may not use this file except in compliance with the License.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * See the License for the specific language governing permissions
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and limitations under the License.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * When distributing Covered Code, include this CDDL HEADER in each
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * If applicable, add the following below this CDDL HEADER, with the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * fields enclosed by brackets "[]" replaced with your own identifying
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * information: Portions Copyright [yyyy] [name of copyright owner]
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CDDL HEADER END
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Use is subject to license terms.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * PURPOSE: EVENT management
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Description: Interfaces in this file are completely defined in
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the uDAPL 1.1 API specification
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * $Id: dapl_evd_wait.c,v 1.22 2003/08/20 13:18:36 sjs2 Exp $
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * dapl_evd_wait
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * UDAPL Requirements Version xxx,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Wait, up to specified timeout, for notification event on EVD.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Then return first available event.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * evd_handle
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_SUCCESS
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_INVALID_PARAMETER
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_INVALID_STATE
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "dapl_evd_wait (%p, %d, %d, %p, %p)\n",
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * We return directly rather than bailing because
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * bailing attempts to update the evd, and we don't have
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG4);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG5);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor evd_ptr->completion_type != DAPL_EVD_STATE_THRESHOLD)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG3);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "dapl_evd_wait: EVD %p, CQ %p\n",
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Make sure there are no other waiters and the evd is active.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Currently this means only the OPEN state is allowed.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * We need to take a lock to synchronize with dapl_evd_dequeue().
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (evd_state != DAPL_EVD_STATE_OPEN || !waitable) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * We now own the EVD, we don't have the lock anymore,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * because we're in the WAITED state.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* return pending events immediately without further polling */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (dapls_rbuf_count(&evd_ptr->pending_event_queue) > 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor dat_status = dapls_evd_copy_events(evd_ptr, time_out);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (DAT_GET_TYPE(dat_status) == DAT_INTERRUPTED_CALL) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* See if we were awakened by evd_set_unwaitable */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (dapls_rbuf_count(&evd_ptr->pending_event_queue) == 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor local_event = dapls_rbuf_remove(&evd_ptr->pending_event_queue);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor dat_status = dapls_rbuf_add(&evd_ptr->free_event_queue,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Valid if dat_status == DAT_SUCCESS || dat_status == DAT_TIMEOUT
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Undefined otherwise, so ok to set it.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *nmore = dapls_rbuf_count(&evd_ptr->pending_event_queue);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "dapl_evd_wait () returns 0x%x\n",