root/src/eventer/eventer_impl_private.h

Revision 602270e2de465d232fd9d53d4c4354fa733294b1, 2.6 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 4 years ago)

silly GNU CPP...

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef LOCAL_EVENTER
34 #error You are not using eventer_impl_private.h correctly
35 #endif
36
37 typedef enum { EV_OWNED, EV_ALREADY_OWNED } ev_lock_state_t;
38 static ev_lock_state_t
39 acquire_master_fd(int fd) {
40   if(noit_spinlock_trylock(&master_fds[fd].lock)) {
41     master_fds[fd].executor = pthread_self();
42     return EV_OWNED;
43   }
44   if(pthread_equal(master_fds[fd].executor, pthread_self())) {
45     return EV_ALREADY_OWNED;
46   }
47   noit_spinlock_lock(&master_fds[fd].lock);
48   master_fds[fd].executor = pthread_self();
49   return EV_OWNED;
50 }
51 static void
52 release_master_fd(int fd, ev_lock_state_t as) {
53   if(as == EV_OWNED) {
54     memset(&master_fds[fd].executor, 0, sizeof(master_fds[fd].executor));
55     noit_spinlock_unlock(&master_fds[fd].lock);
56   }
57 }
58
59 static void
60 LOCAL_EVENTER_foreach_fdevent (void (*f)(eventer_t e, void *),
61                                void *closure) {
62   int fd;
63   for(fd = 0; fd < maxfds; fd++) {
64     ev_lock_state_t ls;
65     ls = acquire_master_fd(fd);
66     if(master_fds[fd].e) f(master_fds[fd].e, closure);
67     release_master_fd(fd, ls);
68   }
69 }
Note: See TracBrowser for help on using the browser.