Пример #1
0
// CHECK-LABEL: define void @test_conditional_bzero
void test_conditional_bzero() {
  char dst[20];
  int _sz = 20, len = 20;
  return (_sz
          ? ((_sz >= len)
              ? __builtin_bzero(dst, len)
              : foo())
          : __builtin_bzero(dst, len));
  // CHECK: call void @llvm.memset
  // CHECK: call void @llvm.memset
  // CHECK-NOT: phi
}
Пример #2
0
void z(int n, ...)
{
  va_list list;

  va_start (list, n);
  while (n--)
    {
      int *a = va_arg (list, int *);
      __builtin_bzero (a, sizeof (l));
    }
  va_end (list);
}
Пример #3
0
static _ais_t       *_getAIS    (unsigned int mmsi)
{
    // return this
    _ais_t *ais = NULL;

    // check that gps_done() haven't flush this
    if (NULL == _ais_list) {
        g_print("s52ais:_getAIS() no AIS list\n");
        return NULL;
    }

    unsigned int i = 0;
    for (i=0; i<_ais_list->len; ++i) {
        ais = &g_array_index(_ais_list, _ais_t, i);
        if (mmsi == ais->mmsi) {
            return ais;
        }
    }

    {   // NEW AIS (not found hence new)
        _ais_t newais;
        __builtin_bzero(&newais, sizeof(_ais_t));
        newais.mmsi     = mmsi;
        newais.status   = -1;     // 0 indicate that status form report is needed
        //newais.name[AIS_SHIPNAME_MAXLEN + 1] = '\0';
        newais.name[0]  = '\0';
        g_get_current_time(&newais.lastUpdate);
        newais.course   = -1.0;
        newais.speed    =  0.0;

        // create an active symbol, put mmsi since status is not known yet
        g_sprintf(newais.name, "%i", mmsi);

#ifdef S52_USE_SOCK
        // debug: make ferry acte as ownshp
        if (OWNSHIP == mmsi) {
            gchar *resp = _encodeNsend("S52_newOWNSHP", "\"%s\"", newais.name);
            if (NULL != resp) {
                sscanf(resp, "[ %lu", (long unsigned int *) &newais.vesselH);
            }
            g_print("s52ais:_getAIS(): new ownshpH:%lu\n", (long unsigned int) newais.vesselH);
        } else {
            gchar *resp = _encodeNsend("S52_newVESSEL", "%i,\"%s\"", 2, newais.name);
            if (NULL != resp) {
                sscanf(resp, "[ %lu", (long unsigned int *) &newais.vesselH);
            }
            g_print("s52ais:_getAIS(): new vesselH:%lu\n", (long unsigned int) newais.vesselH);
        }

#else   // S52_USE_SOCK

        // debug: make ferry acte as ownshp
        if (OWNSHIP == mmsi) {
            newais.vesselH = S52_newOWNSHP(newais.name);
        } else {
            //int vesrce = 1;  // ARPA
            int vesrce = 2;  // AIS
            //int vesrce = 3;  // VTS
            newais.vesselH = S52_newVESSEL(vesrce, newais.name);
        }

#endif  // S52_USE_SOCK

        // new AIS failed
        if (NULL == newais.vesselH) {
            g_print("s52ais:_getAIS(): new vesselH fail\n");
            return NULL;
        }

#ifdef S52_USE_AFGLOW
#ifdef S52_USE_SOCK
        // debug: make ferry acte as ownshp
        if (OWNSHIP == mmsi) {
            gchar *resp = _encodeNsend("S52_newMarObj", "\"%s\",%i,%i", "afgshp", S52_LINES, MAX_AFGLOW_PT);
            if (NULL != resp) {
                sscanf(resp, "[ %lu", (long unsigned int *) &newais.afglowH);
            }
            g_print("s52ais:_getAIS(): new afglowH:%lu\n", (long unsigned int) newais.afglowH);

        } else {
            gchar *resp = _encodeNsend("S52_newMarObj", "\"%s\",%i,%i", "afgves", S52_LINES, MAX_AFGLOW_PT);
            if (NULL != resp) {
                sscanf(resp, "[ %lu", (long unsigned int *) &newais.afglowH);
            }
            g_print("s52ais:_getAIS(): new afglowH:%lu\n", (long unsigned int) newais.afglowH);

        }

#else   // S52_USE_SOCK

        // debug: make ferry acte as ownshp
        if (OWNSHIP == mmsi)
            newais.afglowH = S52_newMarObj("afgshp", S52_LINES, MAX_AFGLOW_PT, NULL, NULL);
        else
            newais.afglowH = S52_newMarObj("afgves", S52_LINES, MAX_AFGLOW_PT, NULL, NULL);

#endif  // S52_USE_SOCK

        if (NULL == newais.afglowH) {
            g_print("s52ais:_getAIS(): new afglowH fail\n");
            return NULL;
        }
#endif

        // save S52obj handle after registered in libS52
        g_array_append_val(_ais_list, newais);
        ais = &g_array_index(_ais_list, _ais_t, _ais_list->len - 1);


#ifdef S52_USE_DBUS
        _signal_newVESSEL(_dbus, newais.vesselH, newais.name);
#endif

    }

    return ais;
}
Пример #4
0
static gpointer      _gpsdClientRead(gpointer dummy)
// start gpsd client - loop forever
// return if _ais_list is NULL or 10 failed attempt to connect
{
    int nWait = 0;

    g_print("s52ais:_gpsdClientRead(): start looping ..\n");
    __builtin_bzero(&_gpsdata, sizeof(_gpsdata));

    //*
    while (0 != gps_open(GPSD_HOST, GPSD_PORT, &_gpsdata)) {   // android (gpsd 2.96)
        g_print("s52ais:_gpsdClientRead(): no gpsd running or network error, wait 1 sec: %d, %s\n", errno, gps_errstr(errno));

        // try to connect to GPSD server, bailout after 10 failed attempt
        g_static_mutex_lock(&_ais_list_mutex);
        if ((NULL==_ais_list) || (10 <= ++nWait)) {
            g_print("s52ais:_gpsdClientRead() no AIS list (main exited) or no GPSD server.. terminate _gpsClientRead thread\n");

            g_static_mutex_unlock(&_ais_list_mutex);

            return NULL;
        }
        g_static_mutex_unlock(&_ais_list_mutex);

        g_usleep(1000 * 1000); // 1.0 sec
    }

    if (-1 == gps_stream(&_gpsdata, WATCH_ENABLE|WATCH_NEWSTYLE, NULL)) {
        g_print("s52ais:_gpsdClientRead():gps_stream() failed .. exiting\n");
        return NULL;
    }
    //*/


    // debug
    //gps_enable_debug(3, stderr);
    //gps_enable_debug(8, stderr);

    // heart of the client
    for (;;) {
        g_static_mutex_lock(&_ais_list_mutex);
        if (NULL == _ais_list) {
            g_print("s52ais:_gpsdClientRead() no AIS list .. main exited .. terminate gpsRead thread\n");
            goto exit;
        }
        g_static_mutex_unlock(&_ais_list_mutex);

        if (FALSE == gps_waiting(&_gpsdata,  500*1000)) {    // wait 0.5 sec     (500*1000 uSec)
            //g_print("s52ais:_gpsdClientRead():gps_waiting() timed out\n");

            g_static_mutex_lock(&_ais_list_mutex);
            _updateTimeTag();
            g_static_mutex_unlock(&_ais_list_mutex);

        } else {
            errno = 0;

            int ret = gps_read(&_gpsdata);
            if (0 < ret) {
                // no error
                //g_print("s52ais:_gpsdClientRead():gps_read() ..\n");

                // handle AIS data
                g_static_mutex_lock(&_ais_list_mutex);
                _updateAISdata(&_gpsdata);
                g_static_mutex_unlock(&_ais_list_mutex);

                continue;
            }

            if (0 == ret) {
                g_print("s52ais:_gpsdClientRead():gps_read(): NO DATA .. [ret=0, errno=%i]\n", errno);
                continue;
            } else {
                g_print("s52ais:_gpsdClientRead():gps_read(): socket error 4 .. GPSD died [ret=%i, errno=%i]\n", ret, errno);

                goto exit;
            }
        }
    }

exit:
    // exit thread
    g_static_mutex_unlock(&_ais_list_mutex);

    gps_stream(&_gpsdata, WATCH_DISABLE, NULL);
    gps_close(&_gpsdata);

    return dummy;
}
Пример #5
0
void
builtin_bzero (char *s, size_t n)
{
  __builtin_bzero (s, n);
}