* Made BTokenSpace not throw any exceptions on memory shortage.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33874 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-11-04 12:19:59 +00:00
parent 8286bcb32e
commit 29e37d8842
2 changed files with 19 additions and 6 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ class BTokenSpace : public BLocker {
~BTokenSpace(); ~BTokenSpace();
int32 NewToken(int16 type, void* object); int32 NewToken(int16 type, void* object);
void SetToken(int32 token, int16 type, void* object); bool SetToken(int32 token, int16 type, void* object);
bool RemoveToken(int32 token); bool RemoveToken(int32 token);
bool CheckToken(int32 token, int16 type) const; bool CheckToken(int32 token, int16 type) const;
+18 -5
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2007, Haiku. * Copyright 2001-2009, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -38,9 +38,15 @@ BTokenSpace::NewToken(int16 type, void* object)
BAutolock locker(this); BAutolock locker(this);
token_info tokenInfo = { type, object, NULL }; token_info tokenInfo = { type, object, NULL };
int32 token = fTokenCount++; int32 token = fTokenCount;
fTokenMap[token] = tokenInfo; try {
fTokenMap[token] = tokenInfo;
} catch (std::bad_alloc& exception) {
return -1;
}
fTokenCount++;
return token; return token;
} }
@@ -52,17 +58,24 @@ BTokenSpace::NewToken(int16 type, void* object)
Don't mix NewToken() and this method unless you know what you're Don't mix NewToken() and this method unless you know what you're
doing. doing.
*/ */
void bool
BTokenSpace::SetToken(int32 token, int16 type, void* object) BTokenSpace::SetToken(int32 token, int16 type, void* object)
{ {
BAutolock locker(this); BAutolock locker(this);
token_info tokenInfo = { type, object, NULL }; token_info tokenInfo = { type, object, NULL };
fTokenMap[token] = tokenInfo;
try {
fTokenMap[token] = tokenInfo;
} catch (std::bad_alloc& exception) {
return false;
}
// this makes sure SetToken() plays more or less nice with NewToken() // this makes sure SetToken() plays more or less nice with NewToken()
if (token >= fTokenCount) if (token >= fTokenCount)
fTokenCount = token + 1; fTokenCount = token + 1;
return true;
} }