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 PtlEQGet(ptl_handle_eq_t eventq, ptl_event_t * ev)
55 ptl_event_t *new_event;
62 nal = ptl_hndl2nal(&eventq);
66 eq = ptl_handle2usereq(&eventq);
67 nal->lock(nal, &flags);
69 /* size must be a power of 2 to handle a wrapped sequence # */
70 LASSERT (eq->size != 0 &&
71 eq->size == LOWEST_BIT_SET (eq->size));
73 new_index = eq->sequence & (eq->size - 1);
74 new_event = &eq->base[new_index];
75 CDEBUG(D_INFO, "new_event: %p, sequence: %lu, eq->size: %u\n",
76 new_event, eq->sequence, eq->size);
77 if (PTL_SEQ_GT (eq->sequence, new_event->sequence)) {
78 nal->unlock(nal, &flags);
84 /* Set the unlinked_me interface number if there is one to pass
85 * back, since the NAL hasn't a clue what it is and therefore can't
87 if (!PtlHandleEqual (ev->unlinked_me, PTL_HANDLE_NONE))
88 ev->unlinked_me.nal_idx = eventq.nal_idx;
90 /* ensure event is delivered correctly despite possible
91 races with lib_finalize */
92 if (eq->sequence != new_event->sequence) {
93 CERROR("DROPPING EVENT: eq seq %lu ev seq %lu\n",
94 eq->sequence, new_event->sequence);
100 eq->sequence = new_event->sequence + 1;
101 nal->unlock(nal, &flags);
106 int PtlEQWait(ptl_handle_eq_t eventq_in, ptl_event_t *event_out)
110 /* PtlEQGet does the handle checking */
111 while ((rc = PtlEQGet(eventq_in, event_out)) == PTL_EQ_EMPTY) {
112 nal_t *nal = ptl_hndl2nal(&eventq_in);
122 static jmp_buf eq_jumpbuf;
124 static void eq_timeout(int signal)
126 longjmp(eq_jumpbuf, -1);
129 int PtlEQWait_timeout(ptl_handle_eq_t eventq_in, ptl_event_t * event_out,
132 static void (*prev) (int);
133 static int left_over;
134 time_t time_at_start;
137 if (setjmp(eq_jumpbuf)) {
138 signal(SIGALRM, prev);
139 alarm(left_over - timeout);
143 left_over = alarm(timeout);
144 prev = signal(SIGALRM, eq_timeout);
145 time_at_start = time(NULL);
146 if (left_over < timeout)
149 rc = PtlEQWait(eventq_in, event_out);
151 signal(SIGALRM, prev);
152 alarm(left_over); /* Should compute how long we waited */