src/server/daemon/event.c

changeset 193
aa8393527b1e
parent 159
9ba9f8befa80
child 254
4784c14aa639
equal deleted inserted replaced
183:f33974f0dce0 193:aa8393527b1e
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include <ucx/map.h> 29 #include "../../ucx/map.h"
30 #include "../util/atomic.h"
30 31
31 #include "event.h" 32 #include "event.h"
32 33
33 UcxMap *event_handler_map = NULL; 34 UcxMap *event_handler_map = NULL;
34 int numevhandlers = 0; 35 int numevhandlers = 0;
35 36
36 event_handler_t *default_event_handler = NULL; 37 EVHandler *default_event_handler = NULL;
37 38
38 event_handler_t *last_handler_c = NULL; 39 EVHandler *last_handler_c = NULL;
39 40
40 int create_event_handler(EventHandlerConfig *cfg) { 41 int create_event_handler(EventHandlerConfig *cfg) {
41 if(event_handler_map == NULL) { 42 if(event_handler_map == NULL) {
42 event_handler_map = ucx_map_new(16); 43 event_handler_map = ucx_map_new(16);
43 } 44 }
48 /* TODO: set reload status */ 49 /* TODO: set reload status */
49 return 1; 50 return 1;
50 } 51 }
51 52
52 /* create new handler */ 53 /* create new handler */
53 event_handler_t *e = evhandler_create(cfg->nthreads); 54 EVHandler *e = evhandler_create(cfg);
54 if(e == NULL) { 55 if(e == NULL) {
55 return 1; 56 return 1;
56 } 57 }
57 58
58 if(cfg->isdefault) { 59 if(cfg->isdefault) {
93 94
94 return create_event_handler(&cfg); 95 return create_event_handler(&cfg);
95 } 96 }
96 97
97 98
98 event_handler_t* get_default_event_handler() { 99 EVHandler* get_default_event_handler() {
99 return default_event_handler; 100 return default_event_handler;
100 } 101 }
101 102
102 event_handler_t* get_event_handler(char *name) { 103 EVHandler* get_event_handler(char *name) {
103 return ucx_map_cstr_get(event_handler_map, name); 104 return ucx_map_cstr_get(event_handler_map, name);
104 } 105 }
106
107 EventHandler* ev_instance(EVHandler *ev) {
108 int nev = ev->numins;
109 if(nev == 1) {
110 return ev->instances[0];
111 }
112
113 int ins = ev->current & nev;
114 ws_atomic_inc32(&ev->current);
115 return ev->instances[ins];
116 }

mercurial