| 1 | /*************************************************************************** |
|---|
| 2 | * pcSyncDataObject.cc |
|---|
| 3 | * |
|---|
| 4 | * Sun Jul 22 2007 |
|---|
| 5 | * Copyright 2007 Dmytro Milinevskyy |
|---|
| 6 | * milinevskyy@gmail.com |
|---|
| 7 | ****************************************************************************/ |
|---|
| 8 | |
|---|
| 9 | /* |
|---|
| 10 | * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | * it under the terms of the GNU Lesser General Public License version 2.1 as published by |
|---|
| 12 | * the Free Software Foundation; |
|---|
| 13 | * |
|---|
| 14 | * This program is distributed in the hope that it will be useful, |
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | * GNU Library General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU Lesser General Public License |
|---|
| 20 | * along with this program; if not, write to the Free Software |
|---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * vim indentation settings |
|---|
| 26 | * set tabstop=4 |
|---|
| 27 | * set shiftwidth=4 |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | #include <libdodo/directives.h> |
|---|
| 31 | |
|---|
| 32 | #include <libdodo/pcSyncDataObject.h> |
|---|
| 33 | #include <libdodo/pcSyncDataObjectEx.h> |
|---|
| 34 | #include <libdodo/pcSyncProtector.h> |
|---|
| 35 | #include <libdodo/pcSyncStack.h> |
|---|
| 36 | #include <libdodo/types.h> |
|---|
| 37 | |
|---|
| 38 | using namespace dodo::pc::sync::data; |
|---|
| 39 | |
|---|
| 40 | object::object(protector &lock) : data(NULL), |
|---|
| 41 | lock(lock) |
|---|
| 42 | { |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | //------------------------------------------------------------------- |
|---|
| 46 | |
|---|
| 47 | object::~object() |
|---|
| 48 | { |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | //------------------------------------------------------------------- |
|---|
| 52 | |
|---|
| 53 | void |
|---|
| 54 | object::set(void *a_data) |
|---|
| 55 | { |
|---|
| 56 | sync::stack g(&lock); |
|---|
| 57 | |
|---|
| 58 | data = a_data; |
|---|
| 59 | } |
|---|
| 60 | //------------------------------------------------------------------- |
|---|
| 61 | |
|---|
| 62 | const void * |
|---|
| 63 | object::get() |
|---|
| 64 | { |
|---|
| 65 | sync::stack g(&lock); |
|---|
| 66 | |
|---|
| 67 | return data; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | //------------------------------------------------------------------- |
|---|
| 71 | |
|---|
| 72 | void * |
|---|
| 73 | object::acquire(unsigned long timeout) |
|---|
| 74 | { |
|---|
| 75 | if (!lock.acquire(timeout)) |
|---|
| 76 | dodo_throw exception::basic(exception::MODULE_PCSYNCDATAOBJECT, DATAOBJECTEX_ACQUIRE, exception::ERRNO_LIBDODO, DATAOBJECTEX_CANNOTLOCK, PCSYNCDATAOBJECTEX_CANNOTLOCK_STR, __LINE__, __FILE__); |
|---|
| 77 | |
|---|
| 78 | return data; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | //------------------------------------------------------------------- |
|---|
| 82 | |
|---|
| 83 | void |
|---|
| 84 | object::release() |
|---|
| 85 | { |
|---|
| 86 | lock.release(); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | //------------------------------------------------------------------- |
|---|