libbe.so: Avoid static BLockers.
They don't work properly after a fork, and if exit() is called from the forked child, the parent won't be able to use them anymore. In BBitmap and BPicture, replace them with mutexes. For AppServerLink, make the private ServerLink inherit from BLocker, and then use that one directly. This also is a slight efficiency gain, as we don't need to create multiple semaphores from the static initializers now, which is just a waste of time in the case of applications that don't even need these locks but link to libbe.so (e.g. CLI tools.) Part of #18576.
This commit is contained in:
@@ -12,13 +12,16 @@
|
||||
|
||||
|
||||
#include <OS.h>
|
||||
#include <Locker.h>
|
||||
#include <LinkReceiver.h>
|
||||
#include <LinkSender.h>
|
||||
|
||||
|
||||
class BShape;
|
||||
class BString;
|
||||
class BGradient;
|
||||
|
||||
|
||||
/*
|
||||
* Error checking rules: (for if you don't want to check every return code)
|
||||
* - Calling EndMessage() is optional, implied by Flush() or StartMessage().
|
||||
@@ -31,7 +34,7 @@ class BGradient;
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
class ServerLink {
|
||||
class ServerLink : public BLocker {
|
||||
public:
|
||||
ServerLink();
|
||||
virtual ~ServerLink();
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
|
||||
#include <Application.h>
|
||||
#include <Locker.h>
|
||||
|
||||
#include <ApplicationPrivate.h>
|
||||
#include <AppServerLink.h>
|
||||
@@ -23,17 +22,13 @@
|
||||
*/
|
||||
|
||||
|
||||
static BLocker sLock("AppServerLink_sLock");
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
AppServerLink::AppServerLink(void)
|
||||
AppServerLink::AppServerLink()
|
||||
{
|
||||
sLock.Lock();
|
||||
|
||||
// if there is no be_app, we can't do a whole lot, anyway
|
||||
if (be_app) {
|
||||
if (be_app != NULL) {
|
||||
BApplication::Private::ServerLink()->Lock();
|
||||
fReceiver = &BApplication::Private::ServerLink()->Receiver();
|
||||
fSender = &BApplication::Private::ServerLink()->Sender();
|
||||
} else {
|
||||
@@ -44,7 +39,7 @@ AppServerLink::AppServerLink(void)
|
||||
|
||||
AppServerLink::~AppServerLink()
|
||||
{
|
||||
sLock.Unlock();
|
||||
BApplication::Private::ServerLink()->Unlock();
|
||||
}
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
@@ -40,17 +40,6 @@
|
||||
#define DBG(x) ;
|
||||
#define PRINT(x) DBG({ printf("[%6" B_PRId32 "] ", find_thread(NULL)); printf x; })
|
||||
|
||||
/*
|
||||
#include <Autolock.h>
|
||||
#include <Locker.h>
|
||||
static BLocker sDebugPrintLocker("BLooper debug print");
|
||||
#define PRINT(x) DBG({ \
|
||||
BAutolock _(sDebugPrintLocker); \
|
||||
debug_printf("[%6ld] ", find_thread(NULL)); \
|
||||
debug_printf x; \
|
||||
})
|
||||
*/
|
||||
|
||||
|
||||
#define FILTER_LIST_BLOCK_SIZE 5
|
||||
#define DATA_BLOCK_SIZE 5
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace BPrivate {
|
||||
|
||||
|
||||
ServerLink::ServerLink()
|
||||
:
|
||||
BLocker()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -32,10 +32,10 @@
|
||||
|
||||
#include <ApplicationPrivate.h>
|
||||
#include <AppServerLink.h>
|
||||
#include <Autolock.h>
|
||||
#include <ObjectList.h>
|
||||
#include <ServerMemoryAllocator.h>
|
||||
#include <ServerProtocol.h>
|
||||
#include <locks.h>
|
||||
|
||||
#include "ColorConversion.h"
|
||||
#include "BitmapPrivate.h"
|
||||
@@ -45,13 +45,13 @@ using namespace BPrivate;
|
||||
|
||||
|
||||
static BObjectList<BBitmap> sBitmapList;
|
||||
static BLocker sBitmapListLock;
|
||||
static mutex sBitmapListLock = MUTEX_INITIALIZER("BBitmap list");
|
||||
|
||||
|
||||
void
|
||||
reconnect_bitmaps_to_app_server()
|
||||
{
|
||||
BAutolock _(sBitmapListLock);
|
||||
MutexLocker _(sBitmapListLock);
|
||||
for (int32 i = 0; i < sBitmapList.CountItems(); i++) {
|
||||
BBitmap::Private bitmap(sBitmapList.ItemAt(i));
|
||||
bitmap.ReconnectToAppServer();
|
||||
@@ -1198,7 +1198,7 @@ BBitmap::_InitObject(BRect bounds, color_space colorSpace, uint32 flags,
|
||||
// NOTE: why not "0" in case of error?
|
||||
fFlags = flags;
|
||||
} else {
|
||||
BAutolock _(sBitmapListLock);
|
||||
MutexLocker _(sBitmapListLock);
|
||||
sBitmapList.AddItem(this);
|
||||
}
|
||||
}
|
||||
@@ -1276,7 +1276,7 @@ BBitmap::_CleanUp()
|
||||
fServerToken = -1;
|
||||
fAreaOffset = -1;
|
||||
|
||||
BAutolock _(sBitmapListLock);
|
||||
MutexLocker _(sBitmapListLock);
|
||||
sBitmapList.RemoveItem(this);
|
||||
}
|
||||
fBasePointer = NULL;
|
||||
|
||||
@@ -24,22 +24,22 @@
|
||||
#include <Message.h>
|
||||
|
||||
#include <AppServerLink.h>
|
||||
#include <Autolock.h>
|
||||
#include <ObjectList.h>
|
||||
#include <PicturePlayer.h>
|
||||
#include <ServerProtocol.h>
|
||||
#include <locks.h>
|
||||
|
||||
#include "PicturePrivate.h"
|
||||
|
||||
|
||||
static BObjectList<BPicture> sPictureList;
|
||||
static BLocker sPictureListLock;
|
||||
static mutex sPictureListLock = MUTEX_INITIALIZER("BPicture list");
|
||||
|
||||
|
||||
void
|
||||
reconnect_pictures_to_app_server()
|
||||
{
|
||||
BAutolock _(sPictureListLock);
|
||||
MutexLocker _(sPictureListLock);
|
||||
for (int32 i = 0; i < sPictureList.CountItems(); i++) {
|
||||
BPicture::Private picture(sPictureList.ItemAt(i));
|
||||
picture.ReconnectToAppServer();
|
||||
@@ -215,14 +215,14 @@ BPicture::_InitData()
|
||||
|
||||
fExtent = new (std::nothrow) _BPictureExtent_;
|
||||
|
||||
BAutolock _(sPictureListLock);
|
||||
MutexLocker _(sPictureListLock);
|
||||
sPictureList.AddItem(this);
|
||||
}
|
||||
|
||||
|
||||
BPicture::~BPicture()
|
||||
{
|
||||
BAutolock _(sPictureListLock);
|
||||
MutexLocker _(sPictureListLock);
|
||||
sPictureList.RemoveItem(this, false);
|
||||
_DisposeData();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user