/alps/ipecamera

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to tools.c

  • Committer: Suren A. Chilingaryan
  • Date: 2011-12-12 04:45:35 UTC
  • Revision ID: csa@dside.dyndns.org-20111212044535-6no1q7g230i8uvlv
multithread preprocessing of ipecamera frames and code reorganization

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#define _POSIX_C_SOURCE 200112L
 
2
#define _GNU_SOURCE
2
3
 
3
4
#include <stdio.h>
4
5
#include <string.h>
7
8
#include <assert.h>
8
9
#include <ctype.h>
9
10
#include <time.h>
 
11
#include <sched.h>
10
12
#include <arpa/inet.h>
11
13
#include <sys/time.h>
12
14
 
13
15
#include "tools.h"
 
16
#include "error.h"
14
17
 
15
18
int pcilib_isnumber(const char *str) {
16
19
    int i = 0;
240
243
            --n;
241
244
        }
242
245
    }
 
246
 
 
247
    return dst;
243
248
244
249
 
245
250
int pcilib_get_page_mask() {
254
259
    return pagemask;
255
260
}
256
261
 
 
262
int pcilib_get_cpu_count() {
 
263
    int err;
 
264
 
 
265
    int cpu_count;
 
266
    cpu_set_t mask;
 
267
 
 
268
    err = sched_getaffinity(getpid(), sizeof(mask), &mask);
 
269
    if (err) return 1;
 
270
 
 
271
#ifdef CPU_COUNT
 
272
    cpu_count = CPU_COUNT(&mask);
 
273
#else
 
274
    for (cpu_count = 0; cpu_count < CPU_SETSIZE; cpu_count++) {
 
275
        if (!CPU_ISSET(cpu_count, &mask)) break;
 
276
    }
 
277
#endif
 
278
 
 
279
    if (!cpu_count) cpu_count = PCILIB_DEFAULT_CPU_COUNT;
 
280
    return cpu_count;    
 
281
}
 
282
 
 
283
 
257
284
int pcilib_add_timeout(struct timeval *tv, pcilib_timeout_t timeout) {
258
285
    tv->tv_usec += timeout%1000000;
259
286
    if (tv->tv_usec > 999999) {
262
289
    } else {
263
290
        tv->tv_sec += timeout/1000000;
264
291
    }
 
292
 
 
293
    return 0;
265
294
}
266
295
 
267
296
int pcilib_calc_deadline(struct timeval *tv, pcilib_timeout_t timeout) {
268
297
    gettimeofday(tv, NULL);
269
298
    pcilib_add_timeout(tv, timeout);
270
 
        
 
299
 
271
300
    return 0;
272
301
}
273
302
 
274
303
int pcilib_check_deadline(struct timeval *tve, pcilib_timeout_t timeout) {
275
304
    int64_t res;
276
305
    struct timeval tvs;
277
 
    
 
306
 
278
307
    if (!tve->tv_sec) return 0;
279
 
    
 
308
 
280
309
    gettimeofday(&tvs, NULL);
281
310
    res = ((tve->tv_sec - tvs.tv_sec)*1000000 + (tve->tv_usec - tvs.tv_usec));
282
311
        // Hm... Some problems comparing signed and unsigned. So, sign check first