1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Library 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/lib-p30.h>
28 #include <portals/arg-blocks.h>
30 int do_PtlEQAlloc_internal(nal_cb_t * nal, void *private, void *v_args,
35 * ptl_handle_ni_t ni_in
40 * ptl_handle_eq_t * handle_out
43 PtlEQAlloc_in *args = v_args;
44 PtlEQAlloc_out *ret = v_ret;
49 /* api should have rounded up */
50 if (args->count_in != LOWEST_BIT_SET (args->count_in))
51 return ret->rc = PTL_VAL_FAILED;
53 eq = lib_eq_alloc (nal);
55 return (ret->rc = PTL_NOSPACE);
57 state_lock(nal, &flags);
59 if (nal->cb_map != NULL) {
61 .iov_base = args->base_in,
62 .iov_len = args->count_in * sizeof (ptl_event_t) };
64 ret->rc = nal->cb_map (nal, 1, &iov, &eq->eq_addrkey);
65 if (ret->rc != PTL_OK) {
66 lib_eq_free (nal, eq);
68 state_unlock (nal, &flags);
74 eq->base = args->base_in;
75 eq->size = args->count_in;
77 eq->event_callback = args->callback_in;
79 lib_initialise_handle (nal, &eq->eq_lh, PTL_COOKIE_TYPE_EQ);
80 list_add (&eq->eq_list, &nal->ni.ni_active_eqs);
82 state_unlock(nal, &flags);
84 ptl_eq2handle(&ret->handle_out, eq);
85 return (ret->rc = PTL_OK);
88 int do_PtlEQFree_internal(nal_cb_t * nal, void *private, void *v_args,
93 * ptl_handle_eq_t eventq_in
98 PtlEQFree_in *args = v_args;
99 PtlEQFree_out *ret = v_ret;
103 state_lock (nal, &flags);
105 eq = ptl_handle2eq(&args->eventq_in, nal);
107 ret->rc = PTL_INV_EQ;
108 } else if (eq->eq_refcount != 0) {
109 ret->rc = PTL_EQ_INUSE;
111 if (nal->cb_unmap != NULL) {
113 .iov_base = eq->base,
114 .iov_len = eq->size * sizeof (ptl_event_t) };
116 nal->cb_unmap(nal, 1, &iov, &eq->eq_addrkey);
119 lib_invalidate_handle (nal, &eq->eq_lh);
120 list_del (&eq->eq_list);
121 lib_eq_free (nal, eq);
125 state_unlock (nal, &flags);