Merged in v 26.12.
[AROS-Contrib.git] / mui / classes / thebar / mcc / utils.c
blobcac86a89ac04f82816bd4e1a7af3416dd591d0e6
1 /***************************************************************************
3 TheBar.mcc - Next Generation Toolbar MUI Custom Class
4 Copyright (C) 2003-2005 Alfonso Ranieri
5 Copyright (C) 2005-2013 by TheBar.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 TheBar class Support Site: http://www.sf.net/projects/thebar
19 $Id$
21 ***************************************************************************/
23 #include "class.h"
25 /***********************************************************************/
27 // DoSuperNew()
28 // Calls parent NEW method within a subclass
29 #if !defined(__MORPHOS__)
30 #ifdef __AROS__
31 Object * VARARGS68K DoSuperNew(struct IClass *cl, Object *obj, Tag tag1, ...)
33 AROS_SLOWSTACKTAGS_PRE_AS(tag1, Object *)
34 retval = (Object *)DoSuperMethod(cl, obj, OM_NEW, AROS_SLOWSTACKTAGS_ARG(tag1), NULL);
35 AROS_SLOWSTACKTAGS_POST
37 #else
38 Object * VARARGS68K DoSuperNew(struct IClass *cl, Object *obj, ...)
40 Object *rc;
41 VA_LIST args;
43 VA_START(args, obj);
44 rc = (Object *)DoSuperMethod(cl, obj, OM_NEW, VA_ARG(args, ULONG), NULL);
45 VA_END(args);
47 return rc;
49 #endif
50 #endif
52 /***********************************************************************/
53 static APTR sharedPool;
54 #if !defined(__amigaos4__) && !defined(__MORPHOS__)
55 static struct SignalSemaphore sharedPoolSema;
56 #endif
58 BOOL CreateSharedPool(void)
60 BOOL success = FALSE;
62 ENTER();
64 #if defined(__amigaos4__)
65 sharedPool = AllocSysObjectTags(ASOT_MEMPOOL, ASOPOOL_MFlags, MEMF_SHARED,
66 ASOPOOL_Puddle, 2048,
67 ASOPOOL_Threshold, 1024,
68 #if defined(VIRTUAL)
69 ASOPOOL_Name, "TheBarVirt.mcc shared pool",
70 #else
71 ASOPOOL_Name, "TheBar.mcc shared pool",
72 #endif
73 ASOPOOL_Protected, TRUE,
74 ASOPOOL_LockMem, FALSE,
75 TAG_DONE);
76 #elif defined(__MORPHOS__)
77 sharedPool = CreatePool(MEMF_SEM_PROTECTED, 2048, 1024);
78 #else
79 sharedPool = CreatePool(MEMF_ANY, 2048, 1024);
80 memset(&sharedPoolSema, 0, sizeof(sharedPoolSema));
81 InitSemaphore(&sharedPoolSema);
82 #endif
84 if(sharedPool != NULL)
85 success = TRUE;
87 RETURN(success);
88 return(success);
91 void DeleteSharedPool(void)
93 ENTER();
95 if(sharedPool != NULL)
97 #if defined(__amigaos4__)
98 FreeSysObject(ASOT_MEMPOOL, sharedPool);
99 #else
100 DeletePool(sharedPool);
101 #endif
103 sharedPool = NULL;
107 APTR SharedAlloc(ULONG size)
109 ULONG *mem;
111 ENTER();
113 #if defined(__amigaos4__) || defined(__MORPHOS__)
114 mem = AllocVecPooled(sharedPool, size);
115 #else // __amigaos4__ || __MORPHOS__
116 size += sizeof(ULONG);
118 ObtainSemaphore(&sharedPoolSema);
120 if((mem = AllocPooled(sharedPool, size)) != NULL)
121 *mem++ = size;
123 ReleaseSemaphore(&sharedPoolSema);
124 #endif // __amigaos4__ || __MORPHOS__
126 RETURN(mem);
127 return mem;
130 /****************************************************************************/
132 void SharedFree(APTR mem)
134 ENTER();
136 if(mem != NULL)
138 #if defined(__amigaos4__) || defined(__MORPHOS__)
139 FreeVecPooled(sharedPool, mem);
140 #else // __amigaos4__ || __MORPHOS__
141 ULONG *_mem = (ULONG *)mem;
143 ObtainSemaphore(&sharedPoolSema);
145 FreePooled(sharedPool, &_mem[-1], _mem[-1]);
147 ReleaseSemaphore(&sharedPoolSema);
148 #endif // __amigaos4__ || __MORPHOS__
151 LEAVE();
154 /****************************************************************************/