status_t WatchNode (BEntry *entry, uint32 flags, const BHandler *handler, const BLooper *looper) { codeLocker.Lock(); /* Derive a node_ref from the entry received */ node_ref node; entry->GetNodeRef (&node); /* Allocate a node monitor normally */ status_t result = watch_node (&node, flags, handler, looper); if (result == B_OK || result != B_NO_MEMORY) { codeLocker.Unlock(); return result; } /* Failed to start monitor, try to allocate more monitors */ result = NeedMoreNodeMonitors(); /* Failed to allocate more monitors */ if (result != B_OK) { codeLocker.Unlock(); return result; } codeLocker.Unlock(); /* Try again, this time with more node monitors */ return watch_node (&node, flags, handler, looper); }
status_t WatchNode (node_ref node, uint32 flags, const BHandler *handler, const BLooper *looper) { /* Allocate a node monitor normally */ codeLocker.Lock(); status_t result = watch_node (&node, flags, handler, looper); if (result == B_OK || result != B_NO_MEMORY) { codeLocker.Unlock(); return result; } /* Failed to start monitor, try to allocate more monitors */ result = NeedMoreNodeMonitors(); /* Failed to allocate more monitors */ if (result != B_OK) { codeLocker.Unlock(); return result; } /* Try again, this time with more node monitors */ codeLocker.Unlock(); return watch_node (&node, flags, handler, looper); }
void RegisterWindow(void) { sWindowLocker.Lock(); sWindowCount++; sWindowLocker.Unlock(); }
int getextmntent_haiku(int* cookie, struct extmnttab *mp, int len) { static BLocker extmntent_locker; extmntent_locker.Lock(); BVolumeRoster roster; BVolume volume; int ret = -1; roster.Rewind(); for (int i = 0; i <= *cookie; i++) if (roster.GetNextVolume(&volume) != B_NO_ERROR) return -1; if (getmntent_haiku(cookie, (struct mnttab*)mp) == 0) { mp->mnt_major = volume.Device(); mp->mnt_minor = volume.Device(); ret = 0; } extmntent_locker.Unlock(); return ret; }
static void listener_output(syslog_message &message) { // compose the message to be sent to all listeners; just convert // the syslog_message into a BMessage BMessage output(SYSLOG_MESSAGE); output.AddInt32("from", message.from); output.AddInt32("when", message.when); output.AddString("ident", message.ident); output.AddString("message", message.message); output.AddInt32("options", message.options); output.AddInt32("priority", message.priority); sLocker.Lock(); for (int32 i = sListeners.CountItems(); i-- > 0;) { BMessenger *target = (BMessenger *)sListeners.ItemAt(i); status_t status = target->SendMessage(&output); if (status < B_OK) { // remove targets once they can't be reached anymore sListeners.RemoveItem(target); } } sLocker.Unlock(); }
void GlobalMutex::Unlock() { // assert( g_cLock.LockingThread() == getpid() ); // assert( g_cLock.LockingThread() == GetCurLooper()->Thread() ); // assert( g_cLock.LockingThread() == find_thread(NULL) ); assert( g_cLock.IsLocked() ); g_cLock.Unlock(); }
Status* FindStatus(BString abbreviation) { statLock.Lock(); Status *status = statusses[abbreviation]; statLock.Unlock(); return status; }
status_t NeedMoreNodeMonitors () { /* Bump node monitor count up BY "bumpValue" */ codeLocker.Lock(); nodeCount += bumpValue; codeLocker.Unlock(); return _kset_mon_limit_ (nodeCount); }
void add_listener(BMessenger *messenger) { if (sLocker.Lock()) { sListeners.AddItem(messenger); sLocker.Unlock(); } }
void remove_listener(BMessenger *messenger) { if (sLocker.Lock()) { sListeners.RemoveItem(messenger); sLocker.Unlock(); } }
void DeleteStatusses() { statLock.Lock(); for (SI p = statusses.begin(); p != statusses.end(); ++p) { delete (*p).second; } statLock.Unlock(); }
int32 CountRegisteredWindows(void) { int32 count; sWindowLocker.Lock(); count = sWindowCount; sWindowLocker.Unlock(); return count; }
void PObjectBroker::RegisterObject(PObject *obj) { if (obj) { sIDLock.Lock(); obj->fObjectID = sNextID++; sIDLock.Unlock(); } }
void PObjectBroker::UnregisterObject(PObject *obj) { if (obj && !fQuitting) { sIDLock.Lock(); fObjectList->RemoveItem(obj,false); sIDLock.Unlock(); } }
void BufferProc(void *cookie, void *buff, size_t len, const media_raw_audio_format &format) { if(settings.sound.s9x_mute) { memset(buff, 0, len); return; } sound_locker.Lock(); S9xMixSamples((uint8 *)buff,(so.sixteen_bit?so.buffer_size>>1:so.buffer_size)); sound_locker.Unlock(); }
Decoder * mp3DecoderPlugin::NewDecoder(uint index) { static BLocker locker; static bool initdone = false; locker.Lock(); if (!initdone) { InitMpgLib(); initdone = true; } locker.Unlock(); return new mp3Decoder; }
void DeregisterWindow(void) { bool quit = false; sWindowLocker.Lock(); sWindowCount--; if (sWindowCount == 0) quit = true; sWindowLocker.Unlock(); if (quit) { if (gQuitOnZeroWindows) be_app->PostMessage(B_QUIT_REQUESTED); else gQuitOnZeroWindows = 1; } }
void WPASupplicantApp::_NotifyInterfaceStateChanged(BMessage *message) { const wpa_supplicant *interface; if (message->FindPointer("interface", (void **)&interface) != B_OK) return; if (!fWatchingEntryListLocker.Lock()) return; for (int32 i = 0; i < fWatchingEntryList.CountItems(); i++) { StateChangeWatchingEntry *entry = fWatchingEntryList.ItemAt(i); if (entry->MessageReceived(interface, message)) { delete fWatchingEntryList.RemoveItemAt(i); i--; } } fWatchingEntryListLocker.Unlock(); }
status_t WPASupplicantApp::_StartWatchingInterfaceChanges( const wpa_supplicant *interface, StateChangeCallback callback, void *data) { StateChangeWatchingEntry *entry = new(std::nothrow) StateChangeWatchingEntry(interface, callback, data); if (entry == NULL) return B_NO_MEMORY; if (!fWatchingEntryListLocker.Lock()) { delete entry; return B_ERROR; } status_t result = B_OK; if (!fWatchingEntryList.AddItem(entry)) { result = B_ERROR; delete entry; } fWatchingEntryListLocker.Unlock(); return result; }
void ArpUnlockDebugOut() { gDebugLock.Unlock(); }
status_t LoadStatusses(BPath statFilePath) { status_t error = B_OK; //open file BFile statFile(statFilePath.Path(), B_READ_ONLY); error = statFile.InitCheck(); if (error != B_ERROR) { StringList *tokenList = new StringList(); //read line off_t fileSize; if (statFile.GetSize(&fileSize) == B_OK) { ssize_t bytesRead = 0; BString* token = new BString(""); bool newToken = false; do { char c[2]; bytesRead += statFile.Read(c,1); c[1] = '\0'; if (c[0] == '\t' || c[0] == '\n') { //clear token if (!newToken) { //add token to list tokenList->AddItem(token); token = new BString(""); newToken = true; } } else { token->Append(c); newToken = false; } } while (bytesRead < fileSize); } int32 startIndex = -1; int32 endIndex = -1; for (int32 i = 0; i < tokenList->CountItems(); i++) { if ((*tokenList)[i].ICompare("<status>") == 0) startIndex = i; else if ((*tokenList)[i].ICompare("</status>") == 0) { endIndex = i; break; } } if (startIndex != -1 && endIndex != -1) { //start past the <status> tag startIndex++; for (int32 i = startIndex; i < endIndex; i++) { int32 lastLineIndex = i + 4; if (lastLineIndex < endIndex) { //parse lines BString bitmapString = (*tokenList)[i]; BString statusName = (*tokenList)[i+1]; BString abbreviation = (*tokenList)[i+2]; bool userChoice = atoi((*tokenList)[i+3].String()); BString colourString = (*tokenList)[i+4]; i += 4; //construct bitmap path BPath bitmapPath; statFilePath.GetParent(&bitmapPath); bitmapPath.Append(bitmapString.String()); BBitmap *icon = BTranslationUtils::GetBitmap(bitmapPath.Path()); //construct status object Status *status = FindStatus(abbreviation); if (status != NULL) { status->AddIcon(icon); } else { //remove brackets from colourString colourString.RemoveAll("{"); colourString.RemoveAll("}"); int32 colours[4]; int32 startIndex = 0; for (int i = 0; i < 4; i++) { int32 commaIndex = colourString.FindFirst(",",startIndex); if (commaIndex != B_ERROR) { BString colourValue; colourString.CopyInto(colourValue,startIndex, commaIndex-startIndex); colours[i] = atoi(colourValue.String()); startIndex = commaIndex + 1; } else if (i < 3) { BString colourValue; colourString.CopyInto(colourValue, startIndex, colourString.CountChars() - startIndex); colours[i] = atoi(colourValue.String()); } else if (i == 3) { colours[i] = 255; } } //construct status colour rgb_color statusColour; statusColour.red = colours[0]; statusColour.green = colours[1]; statusColour.blue = colours[2]; statusColour.alpha = colours[3]; //construct new status object Status *status = new Status(statusName,abbreviation, icon, userChoice, statusColour); statLock.Lock(); statusses[abbreviation] = status; statLock.Unlock(); } } } } StringList::deleteStrings(tokenList); delete tokenList; } else { error = B_ERROR; } return error; }
void _cairo_beos_unlock (void* locker) { BLocker* bLocker = reinterpret_cast<BLocker*>(locker); bLocker->Unlock(); }
void BMediaFormats::Unlock() { sLock.Unlock(); }
int getmntent_haiku(int* cookie, struct mnttab* mp) { static BLocker mntent_locker; mntent_locker.Lock(); int ret = -1; BVolumeRoster roster; char buf[B_PATH_NAME_LENGTH]; int buflen = 0; BVolume volume; BDirectory rootDir; BEntry rootDirEntry; BPath rootDirPath; roster.Rewind(); for (int i = 0; i <= *cookie; i++) if (roster.GetNextVolume(&volume) != B_NO_ERROR) goto bail; // volume name volume.GetName(buf); buflen = strlen(buf); if (buflen == 0) { buflen = strlen(MNTENT_MP_UNKNOWN); strlcpy(buf, MNTENT_MP_UNKNOWN, buflen + 1); } mp->mnt_special = (char* )malloc(sizeof(char) * (buflen+1)); strlcpy(mp->mnt_special, buf, buflen+1); // mount point if (volume.GetRootDirectory(&rootDir) != B_OK || rootDir.GetEntry(&rootDirEntry) != B_OK || rootDirEntry.GetPath(&rootDirPath) != B_OK) goto bail; buflen = strlen(rootDirPath.Path()); mp->mnt_mountp = (char* )malloc(sizeof(char) * (buflen+1)); strlcpy(mp->mnt_mountp, rootDirPath.Path(), buflen + 1); // partition type. fs_info info; if (fs_stat_dev(volume.Device(), &info) != B_OK) goto bail; buflen = strlen(info.fsh_name); mp->mnt_fstype = (char* )malloc(sizeof(char) * (buflen+1)); strlcpy(mp->mnt_fstype, info.fsh_name, buflen+1); // fs options. set default options for all file systems for now. buflen = strlen(MNTENT_MP_DEFAULT_OPTS); mp->mnt_mntopts = (char* )malloc(sizeof(char) * (buflen+2+1)); // extra space for ro/rw strlcpy(mp->mnt_mntopts, MNTENT_MP_DEFAULT_OPTS, buflen + 2 + 1); strcat(mp->mnt_mntopts, volume.IsReadOnly() ? ",ro":",rw"); // mount time. no idea how i can get this. set it to 0 for now. buflen = 1; mp->mnt_time = (char* )malloc(sizeof(char) * (buflen+1)); strlcpy(mp->mnt_time, "0", buflen + 1); (*cookie)++; ret = 0; /* success! */ bail: mntent_locker.Unlock(); return ret; }