[hipl-commit] [trunk] Rev 4273: i3: Move cl_init_ping() to the file where it is used and make it static.

  • From: Diego Biurrun <diego@xxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Tue, 13 Apr 2010 20:08:24 +0300

Committer: Diego Biurrun <diego@xxxxxxxxxx>
Date: 13/04/2010 at 20:08:24
Revision: 4273
Revision-id: diego@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: trunk

Log:
  i3: Move cl_init_ping() to the file where it is used and make it static.

Modified:
  D  i3/i3_client/i3_client_api_ext.c
  D  i3/i3_client/i3_client_api_ext.h
  M  Makefile.am
  M  i3/i3_client/i3_client_api_ctx.c

=== modified file 'Makefile.am'
--- Makefile.am 2010-04-13 17:05:02 +0000
+++ Makefile.am 2010-04-13 17:07:56 +0000
@@ -297,7 +297,6 @@
                       i3/i3_client/http.c                \
                       i3/i3_client/i3_client_api.c       \
                       i3/i3_client/i3_client_api_ctx.c   \
-                      i3/i3_client/i3_client_api_ext.c   \
                       i3/i3_client/i3_client_callback.c  \
                       i3/i3_client/i3_client_context.c   \
                       i3/i3_client/i3_client_fd.c        \

=== modified file 'i3/i3_client/i3_client_api_ctx.c'
--- i3/i3_client/i3_client_api_ctx.c    2010-02-17 17:38:08 +0000
+++ i3/i3_client/i3_client_api_ctx.c    2010-04-13 17:07:56 +0000
@@ -20,11 +20,14 @@
 #include <stdio.h> // printf()
 #include <strings.h> // strcasecmp()
 #include <stdlib.h> // exit()
+#include <pthread.h>
+
 #ifdef _WIN32
 // stg: win does not have strcasecmp():
     #define strcasecmp _stricmp
 #endif
 
+#include "ping_thread.h"
 #include "../i3/i3.h"
 #include "../i3/i3_stack.h"
 #include "i3_client_fun.h"
@@ -42,10 +45,53 @@
 
 
 
-int cl_init_ping(cl_context *ctx, char *url);
 void trigger_set_timer(struct timeval *tv, void (*fun)(void *), cl_trigger 
*ctr);
 
 
+static int cl_init_ping(cl_context *ctx, char *url)
+{
+#ifndef _WIN32
+    pthread_t ping_thread;
+#else
+    uintptr_t err;
+    unsigned ping_thread = 0;
+#endif
+    PingThreadData *data;
+    Coordinates coord;
+    char *temp_str;
+    int i;
+
+    if (ctx == NULL) {
+        return CL_RET_DUP_CONTEXT;
+    }
+
+    ctx->list            = (I3ServerList *) malloc(sizeof(I3ServerList));
+    ctx->ping_start_time = (uint64_t *) malloc(sizeof(uint64_t));
+    init_i3server_list(ctx->list);
+
+    coord.latitude       = COORD_UNDEFINED;
+    coord.longitude      = COORD_UNDEFINED;
+    for (i = 0; i < ctx->num_servers; i++) {
+        create_i3server(ctx->list, ctx->s_array[i].addr.s_addr,
+                        ctx->s_array[i].port, ctx->s_array[i].id, coord);
+    }
+
+    data                  = (PingThreadData *) malloc(sizeof(PingThreadData));
+    temp_str              = (char *) malloc(strlen(url) + 1);
+    strcpy(temp_str, url);
+    data->url             = temp_str;
+    data->list            = ctx->list;
+    data->ping_start_time = ctx->ping_start_time;
+
+#ifndef _WIN32
+    pthread_create(&ping_thread, NULL, ping_thread_entry, (void *) data);
+    return CL_RET_OK;
+#else
+    err = _beginthreadex(NULL, 0, ping_thread_entry, (void *) data, 0, 
&ping_thread);
+    return (0 != err) ? CL_RET_OK : errno;
+#endif
+}
+
 /**
  * @param i3_port_num The port on which i3 should listen.
  */

Other related posts:

  • » [hipl-commit] [trunk] Rev 4273: i3: Move cl_init_ping() to the file where it is used and make it static. - Diego Biurrun