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 #define DEBUG_SUBSYSTEM S_PORTALS
27 #include <portals/api-support.h>
29 int ptl_get_event (ptl_eq_t *eq, ptl_event_t *ev)
31 int new_index = eq->sequence & (eq->size - 1);
32 ptl_event_t *new_event = &eq->base[new_index];
35 CDEBUG(D_INFO, "new_event: %p, sequence: %lu, eq->size: %u\n",
36 new_event, eq->sequence, eq->size);
38 if (PTL_SEQ_GT (eq->sequence, new_event->sequence)) {
44 /* ensure event is delivered correctly despite possible
45 races with lib_finalize */
46 if (eq->sequence != new_event->sequence) {
47 CERROR("DROPPING EVENT: eq seq %lu ev seq %lu\n",
48 eq->sequence, new_event->sequence);
49 RETURN(PTL_EQ_DROPPED);
52 eq->sequence = new_event->sequence + 1;
56 int PtlEQGet(ptl_handle_eq_t eventq, ptl_event_t * ev)
60 return (PtlEQPoll (&eventq, 1, 0, ev, &which));
63 int PtlEQWait(ptl_handle_eq_t eventq_in, ptl_event_t *event_out)
67 return (PtlEQPoll (&eventq_in, 1, PTL_TIME_FOREVER,
71 int PtlEQPoll(ptl_handle_eq_t *eventqs_in, int neq_in, int timeout,
72 ptl_event_t *event_out, int *which_out)
83 RETURN(PTL_EQ_INVALID);
85 nal = ptl_hndl2nal(&eventqs_in[0]);
87 RETURN(PTL_EQ_INVALID);
89 nal->lock(nal, &flags);
92 for (i = 0; i < neq_in; i++) {
93 ptl_eq_t *eq = ptl_handle2usereq(&eventqs_in[i]);
96 ptl_hndl2nal(&eventqs_in[i]) != nal) {
97 nal->unlock(nal, &flags);
98 RETURN (PTL_EQ_INVALID);
101 /* size must be a power of 2 to handle a wrapped sequence # */
102 LASSERT (eq->size != 0 &&
103 eq->size == LOWEST_BIT_SET (eq->size));
105 rc = ptl_get_event (eq, event_out);
106 if (rc != PTL_EQ_EMPTY) {
107 nal->unlock(nal, &flags);
114 nal->unlock(nal, &flags);
115 RETURN (PTL_EQ_EMPTY);
118 timeout = nal->yield(nal, &flags, timeout);