Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Thu Jun 29 11:00:41 2017 +0000
Revision:
166:3a9487d57a5c
This is Opencv 3.1 project on GR-PEACH board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 166:3a9487d57a5c 1 /* mbed Microcontroller Library
thedo 166:3a9487d57a5c 2 * Copyright (c) 2006-2013 ARM Limited
thedo 166:3a9487d57a5c 3 *
thedo 166:3a9487d57a5c 4 * Licensed under the Apache License, Version 2.0 (the "License");
thedo 166:3a9487d57a5c 5 * you may not use this file except in compliance with the License.
thedo 166:3a9487d57a5c 6 * You may obtain a copy of the License at
thedo 166:3a9487d57a5c 7 *
thedo 166:3a9487d57a5c 8 * http://www.apache.org/licenses/LICENSE-2.0
thedo 166:3a9487d57a5c 9 *
thedo 166:3a9487d57a5c 10 * Unless required by applicable law or agreed to in writing, software
thedo 166:3a9487d57a5c 11 * distributed under the License is distributed on an "AS IS" BASIS,
thedo 166:3a9487d57a5c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
thedo 166:3a9487d57a5c 13 * See the License for the specific language governing permissions and
thedo 166:3a9487d57a5c 14 * limitations under the License.
thedo 166:3a9487d57a5c 15 */
thedo 166:3a9487d57a5c 16 #include "platform/FileBase.h"
thedo 166:3a9487d57a5c 17 #include "platform/FileLike.h"
thedo 166:3a9487d57a5c 18 #include "platform/FileHandle.h"
thedo 166:3a9487d57a5c 19
thedo 166:3a9487d57a5c 20 namespace mbed {
thedo 166:3a9487d57a5c 21
thedo 166:3a9487d57a5c 22 FileBase *FileBase::_head = NULL;
thedo 166:3a9487d57a5c 23 SingletonPtr<PlatformMutex> FileBase::_mutex;
thedo 166:3a9487d57a5c 24
thedo 166:3a9487d57a5c 25 FileBase::FileBase(const char *name, PathType t) : _next(NULL),
thedo 166:3a9487d57a5c 26 _name(name),
thedo 166:3a9487d57a5c 27 _path_type(t) {
thedo 166:3a9487d57a5c 28 _mutex->lock();
thedo 166:3a9487d57a5c 29 if (name != NULL) {
thedo 166:3a9487d57a5c 30 // put this object at head of the list
thedo 166:3a9487d57a5c 31 _next = _head;
thedo 166:3a9487d57a5c 32 _head = this;
thedo 166:3a9487d57a5c 33 } else {
thedo 166:3a9487d57a5c 34 _next = NULL;
thedo 166:3a9487d57a5c 35 }
thedo 166:3a9487d57a5c 36 _mutex->unlock();
thedo 166:3a9487d57a5c 37 }
thedo 166:3a9487d57a5c 38
thedo 166:3a9487d57a5c 39 FileBase::~FileBase() {
thedo 166:3a9487d57a5c 40 _mutex->lock();
thedo 166:3a9487d57a5c 41 if (_name != NULL) {
thedo 166:3a9487d57a5c 42 // remove this object from the list
thedo 166:3a9487d57a5c 43 if (_head == this) { // first in the list, so just drop me
thedo 166:3a9487d57a5c 44 _head = _next;
thedo 166:3a9487d57a5c 45 } else { // find the object before me, then drop me
thedo 166:3a9487d57a5c 46 FileBase *p = _head;
thedo 166:3a9487d57a5c 47 while (p->_next != this) {
thedo 166:3a9487d57a5c 48 p = p->_next;
thedo 166:3a9487d57a5c 49 }
thedo 166:3a9487d57a5c 50 p->_next = _next;
thedo 166:3a9487d57a5c 51 }
thedo 166:3a9487d57a5c 52 }
thedo 166:3a9487d57a5c 53 _mutex->unlock();
thedo 166:3a9487d57a5c 54
thedo 166:3a9487d57a5c 55 if (getPathType() == FilePathType) {
thedo 166:3a9487d57a5c 56 extern void remove_filehandle(FileHandle *file);
thedo 166:3a9487d57a5c 57 remove_filehandle(static_cast<FileHandle*>(static_cast<FileLike*>(this)));
thedo 166:3a9487d57a5c 58 }
thedo 166:3a9487d57a5c 59 }
thedo 166:3a9487d57a5c 60
thedo 166:3a9487d57a5c 61 FileBase *FileBase::lookup(const char *name, unsigned int len) {
thedo 166:3a9487d57a5c 62 _mutex->lock();
thedo 166:3a9487d57a5c 63 FileBase *p = _head;
thedo 166:3a9487d57a5c 64 while (p != NULL) {
thedo 166:3a9487d57a5c 65 /* Check that p->_name matches name and is the correct length */
thedo 166:3a9487d57a5c 66 if (p->_name != NULL && std::strncmp(p->_name, name, len) == 0 && std::strlen(p->_name) == len) {
thedo 166:3a9487d57a5c 67 _mutex->unlock();
thedo 166:3a9487d57a5c 68 return p;
thedo 166:3a9487d57a5c 69 }
thedo 166:3a9487d57a5c 70 p = p->_next;
thedo 166:3a9487d57a5c 71 }
thedo 166:3a9487d57a5c 72 _mutex->unlock();
thedo 166:3a9487d57a5c 73 return NULL;
thedo 166:3a9487d57a5c 74 }
thedo 166:3a9487d57a5c 75
thedo 166:3a9487d57a5c 76 FileBase *FileBase::get(int n) {
thedo 166:3a9487d57a5c 77 _mutex->lock();
thedo 166:3a9487d57a5c 78 FileBase *p = _head;
thedo 166:3a9487d57a5c 79 int m = 0;
thedo 166:3a9487d57a5c 80 while (p != NULL) {
thedo 166:3a9487d57a5c 81 if (m == n) {
thedo 166:3a9487d57a5c 82 _mutex->unlock();
thedo 166:3a9487d57a5c 83 return p;
thedo 166:3a9487d57a5c 84 }
thedo 166:3a9487d57a5c 85
thedo 166:3a9487d57a5c 86 m++;
thedo 166:3a9487d57a5c 87 p = p->_next;
thedo 166:3a9487d57a5c 88 }
thedo 166:3a9487d57a5c 89 _mutex->unlock();
thedo 166:3a9487d57a5c 90 return NULL;
thedo 166:3a9487d57a5c 91 }
thedo 166:3a9487d57a5c 92
thedo 166:3a9487d57a5c 93 const char* FileBase::getName(void) {
thedo 166:3a9487d57a5c 94 // Constant read so no lock needed
thedo 166:3a9487d57a5c 95 return _name;
thedo 166:3a9487d57a5c 96 }
thedo 166:3a9487d57a5c 97
thedo 166:3a9487d57a5c 98 PathType FileBase::getPathType(void) {
thedo 166:3a9487d57a5c 99 // Constant read so no lock needed
thedo 166:3a9487d57a5c 100 return _path_type;
thedo 166:3a9487d57a5c 101 }
thedo 166:3a9487d57a5c 102
thedo 166:3a9487d57a5c 103 } // namespace mbed
thedo 166:3a9487d57a5c 104
thedo 166:3a9487d57a5c 105