| 1 | /* |
| 2 | * Copyright 2011 Red Hat Inc., Durham, North Carolina. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | * |
| 19 | * Authors: |
| 20 | * Daniel Kopecek <[email protected]> |
| 21 | */ |
| 22 | #ifndef ICACHE_H |
| 23 | #define ICACHE_H |
| 24 | |
| 25 | #include <stddef.h> |
| 26 | #include <sexp.h> |
| 27 | #include "../SEAP/generic/rbt/rbt.h" |
| 28 | #include "common/compat_pthread_barrier.h" |
| 29 | |
| 30 | #ifndef PROBE_IQUEUE_CAPACITY |
| 31 | #define PROBE_IQUEUE_CAPACITY 1024 |
| 32 | #endif |
| 33 | |
| 34 | typedef struct { |
| 35 | SEXP_t *cobj; |
| 36 | union { |
| 37 | SEXP_t *item; |
| 38 | pthread_cond_t *cond; |
| 39 | } p; |
| 40 | } probe_iqpair_t; |
| 41 | |
| 42 | typedef struct { |
| 43 | rbt_t *tree; /* XXX: rewrite to extensible or linear hashing */ |
| 44 | pthread_t thid; |
| 45 | pthread_barrier_t *th_barrier; |
| 46 | |
| 47 | pthread_mutex_t queue_mutex; |
| 48 | pthread_cond_t queue_notempty; |
| 49 | pthread_cond_t queue_notfull; |
| 50 | |
| 51 | probe_iqpair_t queue[PROBE_IQUEUE_CAPACITY]; |
| 52 | uint16_t queue_beg; |
| 53 | uint16_t queue_end; |
| 54 | uint16_t queue_cnt; |
| 55 | uint16_t queue_max; |
| 56 | } probe_icache_t; |
| 57 | |
| 58 | typedef struct { |
| 59 | SEXP_t **item; |
| 60 | uint16_t count; |
| 61 | } probe_citem_t; |
| 62 | |
| 63 | probe_icache_t *probe_icache_new(pthread_barrier_t *th_barrier); |
| 64 | int probe_icache_add(probe_icache_t *cache, SEXP_t *cobj, SEXP_t *item); |
| 65 | int probe_icache_nop(probe_icache_t *cache); |
| 66 | void probe_icache_free(probe_icache_t *cache); |
| 67 | |
| 68 | #endif /* ICACHE_H */ |