+/*
+ * Copyright 2012 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <signal.h>
+
+#ifdef ST_THREADS
#include <st.h>
+uint32_t ta = 0;
+#endif
unsigned int verbose;
struct log_ctx lc;
-uint32_t ta = 0;
inline int canDefer(struct peerd *peer)
{
free_peer_req(peer, pr);
}
-void pending(struct peerd *peer, struct peer_req *pr)
-{
- pr->req->state = XS_PENDING;
-}
-
static void handle_accepted(struct peerd *peer, struct peer_req *pr,
struct xseg_request *req)
{
//assert xreq == req;
XSEGLOG2(&lc, D, "Handle accepted");
xreq->serviced = 0;
- //xreq->state = XS_ACCEPTED;
pr->retval = 0;
dispatch(peer, pr, req, dispatch_accept);
}
struct xseg_request *req)
{
//struct xseg_request *req = pr->req;
- //assert req->state != XS_ACCEPTED;
XSEGLOG2(&lc, D, "Handle received \n");
dispatch(peer, pr, req, dispatch_receive);
if (check_ports(peer))
loops = threshold;
}
+#ifdef ST_THREADS
if (ta){
st_sleep(0);
} else {
+#endif
XSEGLOG2(&lc, I, "Peer goes to sleep\n");
xseg_wait_signal(xseg, 10000000UL);
xseg_cancel_wait(xseg, peer->portno_start);
XSEGLOG2(&lc, I, "Peer woke up\n");
+#ifdef ST_THREADS
}
+#endif
}
xseg_quit_local_signal(xseg, peer->portno_start);
return 0;
struct peerd *peer;
struct xseg_port *port;
+#ifdef ST_THREADS
st_init();
-
+#endif
peer = malloc(sizeof(struct peerd));
if (!peer) {
perror("malloc");
peer->peer_reqs[i].retval = 0;
peer->peer_reqs[i].priv = NULL;
peer->peer_reqs[i].portno = NoPort;
+#ifdef ST_THREADS
peer->peer_reqs[i].cond = st_cond_new(); //FIXME err check
+#endif
}
return peer;
}
r = custom_peer_init(peer, argc, argv);
if (r < 0)
return -1;
+#ifdef ST_THREADS
st_thread_t st = st_thread_create(peerd_loop, peer, 1, 0);
return st_thread_join(st, NULL);
-// return peerd_loop(peer);
+#else
+ return peerd_loop(peer);
+#endif
}