From 4ad564f9120afcd0f1ca486c501f72c93a8cdfb1 Mon Sep 17 00:00:00 2001 From: Alexander Strange Date: Sat, 10 Jan 2009 20:09:29 +0000 Subject: [PATCH] Delete queue.*. It's unused and a very old version. NSArray performance would be good enough these days. --- ITFoundation.xcodeproj/project.pbxproj | 4 - queue.c | 120 ------------------------- queue.h | 49 ---------- 3 files changed, 173 deletions(-) delete mode 100644 queue.c delete mode 100644 queue.h diff --git a/ITFoundation.xcodeproj/project.pbxproj b/ITFoundation.xcodeproj/project.pbxproj index 3e9b6bd..50cae52 100644 --- a/ITFoundation.xcodeproj/project.pbxproj +++ b/ITFoundation.xcodeproj/project.pbxproj @@ -49,8 +49,6 @@ 37B1C5740612599000F99008 /* ITXMLParser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ITXMLParser.h; sourceTree = ""; }; 37B1C5750612599000F99008 /* ITXMLParser.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = ITXMLParser.m; sourceTree = ""; }; 37B1C5760612599000F99008 /* ITXMLNode.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ITXMLNode.h; sourceTree = ""; }; - 3D2D8A10055E07D800F59C27 /* queue.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = queue.c; sourceTree = ""; }; - 3D2D8A11055E07D800F59C27 /* queue.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = queue.h; sourceTree = ""; }; 7C0462070801DC3700433407 /* ITCategory-NSString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ITCategory-NSString.h"; sourceTree = ""; }; 7C0462080801DC3700433407 /* ITCategory-NSString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ITCategory-NSString.m"; sourceTree = ""; }; 7C058DF7072F10530082E1E9 /* ITCategory-NSObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ITCategory-NSObject.h"; sourceTree = ""; }; @@ -184,8 +182,6 @@ children = ( 7CA50D7D054E7C600074E1D9 /* ITFoundation.h */, 32DBCF5E0370ADEE00C91783 /* ITFoundation_Prefix.pch */, - 3D2D8A10055E07D800F59C27 /* queue.c */, - 3D2D8A11055E07D800F59C27 /* queue.h */, ); name = "Other Sources"; sourceTree = ""; diff --git a/queue.c b/queue.c deleted file mode 100644 index 0406e43..0000000 --- a/queue.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * - * Copyright (C) 2003 and beyond by Alexander Strange - * and the Dawn Of Infinity developers. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This license is contained in the file "COPYING", - * which is included with this source code; it is available online at - * http://www.gnu.org/licenses/gpl.html - * - * Additionally, this file can be used with no restrictions or conditions in ITFoundation. - */ - -/* - * $Id$ - * - */ -#include -#include "queue.h" - -queue* -qinit(queue *q,size_t defaultsize) -{ - pthread_rwlock_init(&q->pmutex, NULL); - if (!defaultsize) defaultsize = 16; - q->data = (void **) calloc(defaultsize, sizeof(void *)); - q->begin = q->end = 0; - q->allocated = defaultsize; - q->filled = 0; - return q; -} - -void -qdel(queue * q) -{ - pthread_rwlock_destroy(&q->pmutex); - free(q->data); -} - -void * -qpop(queue * q) -{ -if (q->filled == 0) return (void*)0xABCDEF00; - int err = pthread_rwlock_wrlock(&q->pmutex); - void *v = q->data[q->begin++]; - q->filled--; - if (q->filled == 0) {q->begin = q->end = 0;} - if (q->begin >= q->allocated) q->begin = 0; - if(err == 0) - { - err = pthread_rwlock_unlock(&q->pmutex); - } - return v; -} - -void -qpush(queue * q, void *p) -{ - int err = pthread_rwlock_wrlock(&q->pmutex); - if (q->allocated == q->filled) q->allocated = growarray(&q->data,q->allocated); - q->data[q->end++] = p; - q->filled++; - if (q->end >= q->allocated) q->end = 0; - if(err == 0) - { - err = pthread_rwlock_unlock(&q->pmutex); - } -} - -void -qperform(queue *q, qperformer p, void *pctx) -{ - if (q->end == q->begin) return; //no handling wrapped around status - //in fact no handling anything but we'll handle nonwrapped first - int err = pthread_rwlock_rdlock(&q->pmutex); - if (q->end > q->begin) { - int i = q->begin, c = q->end - q->begin; - do - { - p(pctx,q->data[i++]); - } while (c--); - } else { - int i = q->begin, c = q->filled; - while (c--) { - p(pctx,q->data[i++]); - } - i = 0; - c = q->end; - do { - p(pctx,q->data[i++]); - } while (c--); - } - q->filled = q->begin = q->end = 0; - if (err = 0) pthread_rwlock_unlock(&q->pmutex); -} - -/* XXX this should not be in here, but whatever */ -/* - * XXX there should also be a reverse shrinkarray for when the fill size hits - * a low-water-mark point. FreeBSD at least will free up memory if you - * realloc something smaller. - */ -size_t -growarray(void ***datap, size_t oldsize) -{ - size_t newsize = oldsize + 8, diff = 8; - void **data = *datap; - *datap = reallocf(data, sizeof(void *[newsize])); - while (diff--) {data[oldsize+diff] = (void*)0xDDDADEDC;} - return newsize; -} diff --git a/queue.h b/queue.h deleted file mode 100644 index ff43e78..0000000 --- a/queue.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * Copyright (C) 2003 and beyond by Alexander Strange - * and the Dawn Of Infinity developers. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This license is contained in the file "COPYING", - * which is included with this source code; it is available online at - * http://www.gnu.org/licenses/gpl.html - * - */ - -/* - * $Id$ - * - */ -#pragma once only -#ifndef _QUEUE_H -#define _QUEUE_H -#include -#include - -typedef struct queue { - void **data; - size_t begin; - size_t end; - size_t allocated; - size_t filled; - pthread_rwlock_t pmutex; -} queue; - -typedef void (*qperformer) (void *context, void *p); - -extern queue *qinit(queue *q,size_t defaultsize); -extern void qdel(queue *q); -extern void *qpop(queue *q); -extern void qpush(queue *q, void *p); -extern size_t growarray(void ***datap, size_t oldsize); -extern void qperform(queue *q, qperformer p, void *pctx); -#endif \ No newline at end of file -- 2.20.1