/alps/pcitool

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

« back to all changes in this revision

Viewing changes to tools.c

  • Committer: Suren A. Chilingaryan
  • Date: 2011-12-08 02:47:23 UTC
  • Revision ID: csa@dside.dyndns.org-20111208024723-ym9uf3uoll6ym2a9
new event architecture, first trial

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#include <assert.h>
6
6
#include <ctype.h>
7
7
#include <arpa/inet.h>
 
8
#include <sys/time.h>
8
9
 
9
10
#include "tools.h"
10
11
 
238
239
    }
239
240
240
241
 
241
 
 
242
242
int pcilib_get_page_mask() {
243
243
    int pagesize,pagemask,temp;
244
244
 
250
250
    }
251
251
    return pagemask;
252
252
}
 
253
 
 
254
int calc_deadline(struct timeval *tv, pcilib_timeout_t timeout) {
 
255
    gettimeofday(tv, NULL);
 
256
    tv->tv_usec += timeout%1000000;
 
257
    if (tv->tv_usec > 999999) {
 
258
        tv->tv_usec -= 1000000;
 
259
        tv->tv_sec = 1 + timeout/1000000;
 
260
    } else {
 
261
        tv->tv_sec = timeout/1000000;
 
262
    }
 
263
    
 
264
    return 0;
 
265
}
 
266
 
 
267
int check_deadline(struct timeval *tve, pcilib_timeout_t timeout) {
 
268
    int64_t res;
 
269
    struct timeval tvs;
 
270
    
 
271
    if (!tve->tv_sec) return 0;
 
272
    
 
273
    gettimeofday(&tvs, NULL);
 
274
    res = ((tve->tv_sec - tvs.tv_sec)*1000000 + (tve->tv_usec - tvs.tv_usec));
 
275
    if (res < timeout) return 1;
 
276
 
 
277
    return 0;
 
278
}
 
279
 
 
280
pcilib_timeout_t calc_time_to_deadline(struct timeval *tve) {
 
281
    int64_t res;
 
282
    struct timeval tvs;
 
283
    
 
284
    gettimeofday(&tvs, NULL);
 
285
    res = ((tve->tv_sec - tvs.tv_sec)*1000000 + (tve->tv_usec - tvs.tv_usec));
 
286
    
 
287
    if (res < 0) return 0;
 
288
    return res;
 
289
}