A streamlined version (for embedded use) of Jeff Brown's ZBar library. Visit <http://zbar.sourceforge.net> for more details.
Dependents: BarcodeReader_F103
refcnt.h@1:4f5c042a2d34, 2020-01-10 (annotated)
- Committer:
- hudakz
- Date:
- Fri Jan 10 22:06:18 2020 +0000
- Revision:
- 1:4f5c042a2d34
- Parent:
- 0:e33621169e44
Streamlined barcode reader library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:e33621169e44 | 1 | /*------------------------------------------------------------------------ |
hudakz | 0:e33621169e44 | 2 | * Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net> |
hudakz | 0:e33621169e44 | 3 | * |
hudakz | 0:e33621169e44 | 4 | * This file is part of the ZBar Bar Code Reader. |
hudakz | 0:e33621169e44 | 5 | * |
hudakz | 0:e33621169e44 | 6 | * The ZBar Bar Code Reader is free software; you can redistribute it |
hudakz | 0:e33621169e44 | 7 | * and/or modify it under the terms of the GNU Lesser Public License as |
hudakz | 0:e33621169e44 | 8 | * published by the Free Software Foundation; either version 2.1 of |
hudakz | 0:e33621169e44 | 9 | * the License, or (at your option) any later version. |
hudakz | 0:e33621169e44 | 10 | * |
hudakz | 0:e33621169e44 | 11 | * The ZBar Bar Code Reader is distributed in the hope that it will be |
hudakz | 0:e33621169e44 | 12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
hudakz | 0:e33621169e44 | 13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
hudakz | 0:e33621169e44 | 14 | * GNU Lesser Public License for more details. |
hudakz | 0:e33621169e44 | 15 | * |
hudakz | 0:e33621169e44 | 16 | * You should have received a copy of the GNU Lesser Public License |
hudakz | 0:e33621169e44 | 17 | * along with the ZBar Bar Code Reader; if not, write to the Free |
hudakz | 0:e33621169e44 | 18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
hudakz | 0:e33621169e44 | 19 | * Boston, MA 02110-1301 USA |
hudakz | 0:e33621169e44 | 20 | * |
hudakz | 0:e33621169e44 | 21 | * http://sourceforge.net/projects/zbar |
hudakz | 0:e33621169e44 | 22 | *------------------------------------------------------------------------*/ |
hudakz | 0:e33621169e44 | 23 | #ifndef _REFCNT_H_ |
hudakz | 0:e33621169e44 | 24 | #define _REFCNT_H_ |
hudakz | 0:e33621169e44 | 25 | |
hudakz | 0:e33621169e44 | 26 | #include <config.h> |
hudakz | 0:e33621169e44 | 27 | #include <assert.h> |
hudakz | 0:e33621169e44 | 28 | |
hudakz | 0:e33621169e44 | 29 | #if defined(_WIN32) |
hudakz | 0:e33621169e44 | 30 | # include <windows.h> |
hudakz | 0:e33621169e44 | 31 | |
hudakz | 0:e33621169e44 | 32 | typedef volatile LONG refcnt_t; /* FIXME where did volatile come from? */ |
hudakz | 0:e33621169e44 | 33 | |
hudakz | 0:e33621169e44 | 34 | static inline int _zbar_refcnt (refcnt_t *cnt, |
hudakz | 0:e33621169e44 | 35 | int delta) |
hudakz | 0:e33621169e44 | 36 | { |
hudakz | 0:e33621169e44 | 37 | int rc = -1; |
hudakz | 0:e33621169e44 | 38 | if(delta > 0) |
hudakz | 0:e33621169e44 | 39 | while(delta--) |
hudakz | 0:e33621169e44 | 40 | rc = InterlockedIncrement(cnt); |
hudakz | 0:e33621169e44 | 41 | else if(delta < 0) |
hudakz | 0:e33621169e44 | 42 | while(delta++) |
hudakz | 0:e33621169e44 | 43 | rc = InterlockedDecrement(cnt); |
hudakz | 0:e33621169e44 | 44 | assert(rc >= 0); |
hudakz | 0:e33621169e44 | 45 | return(rc); |
hudakz | 0:e33621169e44 | 46 | } |
hudakz | 0:e33621169e44 | 47 | |
hudakz | 0:e33621169e44 | 48 | |
hudakz | 0:e33621169e44 | 49 | #elif defined(HAVE_LIBPTHREAD) |
hudakz | 0:e33621169e44 | 50 | # include <pthread.h> |
hudakz | 0:e33621169e44 | 51 | |
hudakz | 0:e33621169e44 | 52 | typedef int refcnt_t; |
hudakz | 0:e33621169e44 | 53 | |
hudakz | 0:e33621169e44 | 54 | extern pthread_mutex_t _zbar_reflock; |
hudakz | 0:e33621169e44 | 55 | |
hudakz | 0:e33621169e44 | 56 | static inline int _zbar_refcnt (refcnt_t *cnt, |
hudakz | 0:e33621169e44 | 57 | int delta) |
hudakz | 0:e33621169e44 | 58 | { |
hudakz | 0:e33621169e44 | 59 | pthread_mutex_lock(&_zbar_reflock); |
hudakz | 0:e33621169e44 | 60 | int rc = (*cnt += delta); |
hudakz | 0:e33621169e44 | 61 | pthread_mutex_unlock(&_zbar_reflock); |
hudakz | 0:e33621169e44 | 62 | assert(rc >= 0); |
hudakz | 0:e33621169e44 | 63 | return(rc); |
hudakz | 0:e33621169e44 | 64 | } |
hudakz | 0:e33621169e44 | 65 | |
hudakz | 0:e33621169e44 | 66 | |
hudakz | 0:e33621169e44 | 67 | #else |
hudakz | 0:e33621169e44 | 68 | |
hudakz | 0:e33621169e44 | 69 | typedef int refcnt_t; |
hudakz | 0:e33621169e44 | 70 | |
hudakz | 0:e33621169e44 | 71 | static inline int _zbar_refcnt (refcnt_t *cnt, |
hudakz | 0:e33621169e44 | 72 | int delta) |
hudakz | 0:e33621169e44 | 73 | { |
hudakz | 0:e33621169e44 | 74 | int rc = (*cnt += delta); |
hudakz | 0:e33621169e44 | 75 | assert(rc >= 0); |
hudakz | 0:e33621169e44 | 76 | return(rc); |
hudakz | 0:e33621169e44 | 77 | } |
hudakz | 0:e33621169e44 | 78 | |
hudakz | 0:e33621169e44 | 79 | #endif |
hudakz | 0:e33621169e44 | 80 | |
hudakz | 0:e33621169e44 | 81 | |
hudakz | 0:e33621169e44 | 82 | void _zbar_refcnt_init(void); |
hudakz | 0:e33621169e44 | 83 | |
hudakz | 0:e33621169e44 | 84 | #endif |