1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * User-level event queue management routines
7 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
8 * Copyright (c) 2001-2002 Sandia National Laboratories
10 * This file is part of Lustre, http://www.sf.net/projects/lustre/
12 * Lustre is free software; you can redistribute it and/or
13 * modify it under the terms of version 2 of the GNU General Public
14 * License as published by the Free Software Foundation.
16 * Lustre is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with Lustre; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <portals/api-support.h>
30 /* Nothing to do anymore... */
34 void ptl_eq_fini(void)
36 /* Nothing to do anymore... */
39 int ptl_eq_ni_init(nal_t * nal)
41 /* Nothing to do anymore... */
45 void ptl_eq_ni_fini(nal_t * nal)
47 /* Nothing to do anymore... */
50 int ptl_get_event (ptl_eq_t *eq, ptl_event_t *ev)
52 int new_index = eq->sequence & (eq->size - 1);
53 ptl_event_t *new_event = &eq->base[new_index];
56 CDEBUG(D_INFO, "new_event: %p, sequence: %lu, eq->size: %u\n",
57 new_event, eq->sequence, eq->size);
59 if (PTL_SEQ_GT (eq->sequence, new_event->sequence)) {
65 /* ensure event is delivered correctly despite possible
66 races with lib_finalize */
67 if (eq->sequence != new_event->sequence) {
68 CERROR("DROPPING EVENT: eq seq %lu ev seq %lu\n",
69 eq->sequence, new_event->sequence);
70 RETURN(PTL_EQ_DROPPED);
73 eq->sequence = new_event->sequence + 1;
77 int PtlEQGet(ptl_handle_eq_t eventq, ptl_event_t * ev)
81 return (PtlEQPoll (&eventq, 1, 0, ev, &which));
84 int PtlEQWait(ptl_handle_eq_t eventq_in, ptl_event_t *event_out)
88 return (PtlEQPoll (&eventq_in, 1, PTL_TIME_FOREVER,
92 int PtlEQPoll(ptl_handle_eq_t *eventqs_in, int neq_in, int timeout,
93 ptl_event_t *event_out, int *which_out)
104 RETURN(PTL_EQ_INVALID);
106 nal = ptl_hndl2nal(&eventqs_in[0]);
108 RETURN(PTL_EQ_INVALID);
110 nal->lock(nal, &flags);
113 for (i = 0; i < neq_in; i++) {
114 ptl_eq_t *eq = ptl_handle2usereq(&eventqs_in[i]);
117 ptl_hndl2nal(&eventqs_in[i]) != nal) {
118 nal->unlock(nal, &flags);
119 RETURN (PTL_EQ_INVALID);
122 /* size must be a power of 2 to handle a wrapped sequence # */
123 LASSERT (eq->size != 0 &&
124 eq->size == LOWEST_BIT_SET (eq->size));
126 rc = ptl_get_event (eq, event_out);
127 if (rc != PTL_EQ_EMPTY) {
128 nal->unlock(nal, &flags);
135 nal->unlock(nal, &flags);
136 RETURN (PTL_EQ_EMPTY);
139 timeout = nal->yield(nal, &flags, timeout);