Ejemplo n.º 1
0
void JUCETaskCreate(void (*pvTaskCode)(void * ), const signed char *pcName,
					void *pvParameters, int uxPriority, int *pxCreatedTask)
{
	tasklistmutex.enter();
	if (arrayinited != true)
	{
		for (unsigned int i = 0; i < MAX_JUCETASKS; i++)
		{
			taskArray[i] = NULL;
		}
		arrayinited = true;
	}
	unsigned int thisID = MAX_JUCETASKS;
	for (unsigned int i = 0; i < MAX_JUCETASKS; i++)
	{
		if (taskArray[i] == NULL)
		{
			thisID = i;
			break;
		}
	}
	if (thisID == MAX_JUCETASKS) return;
	JUCETask *newtask;
	String newname = (const char*) pcName;
	newtask = new JUCETask(newname);
	newtask->TaskFunction = pvTaskCode;
	newtask->parameters = pvParameters;
	newtask->iD = thisID;
	taskArray[thisID] = newtask;
	if (pxCreatedTask != NULL) *pxCreatedTask = thisID;

	newtask->startThread(uxPriority);
	tasklistmutex.exit();
}
Ejemplo n.º 2
0
int ServiceManager::registerService(waServiceFactory *service, GUID owner) {
  ASSERT(owner != INVALID_GUID);
  if (owner == INVALID_GUID) return 0;
  GUID svctype = GetServiceTypeL(service);
  cs.enter();
  if (!services.multiHaveItem(svctype, service)) {
    services.multiAddItem(svctype, service);

    ownermap.addItem(service, owner);

    GUID svcguid = service->getGuid();
    if (svcguid != INVALID_GUID) services_by_guid.addItem(svcguid, service);
  }
  cs.leave();

  service->serviceNotify(SvcNotify::ONREGISTERED);

#ifdef WASABI_COMPILE_SYSCB
  CallbackManager::issueCallback(SysCallback::SERVICE,
    SvcCallback::ONREGISTER,
    reinterpret_cast<long>(&svctype), reinterpret_cast<long>(service));
#endif

  return 1;
}
Ejemplo n.º 3
0
void MutexList_Del(CriticalSection *mutexPointer)
{
	queuelistmutex.enter();
	if (mutexPointer != NULL &&
		MutexList != NULL) 
	{
		MutexList_t *temp = MutexList;
		MutexList_t *prev = NULL;
		
		while (temp != NULL)
		{
			if (temp->mutexPointer == mutexPointer)
			{
				break;
			}
			prev = temp;
			temp = temp->next;
		}
		
		if (prev == NULL) 
		{
			MutexList = temp->next;
		} else {
			prev->next = temp->next;
		}
		
		delete temp;
		queuelistmutex.exit();
	}
}
Ejemplo n.º 4
0
 bool empty() 
 {
     c_region.enter();
     bool res = (active_buffers == 0);
     c_region.leave();
     return res;
 }
Ejemplo n.º 5
0
void ServiceManager::sendNotification(int msg, int param1, int param2) {
  cs.enter();
  for (int x = 0; x < services.multiGetNumPairs(); x++) {
    for (int y = 0; ; y++) {
      waServiceFactory *svc;
      if (!services.multiGetItemDirect(x, y, &svc)) {
        break;
      }
      svc->serviceNotify(msg, param1, param2);
    }
  }
  cs.leave();
#ifdef WASABI_COMPILE_COMPONENTS
  // also notify components
  for (int i = 0; ; i++) {
    WaComponent *wac = ComponentManager::enumComponent(i);
    if (wac == NULL) break;
    wac->onNotify(WAC_NOTIFY_SERVICE_NOTIFY, msg, param1, param2);
  }
#endif
#ifdef WASABI_COMPILE_SYSCB
  // and syscallbacks
  CallbackManager::issueCallback(SysCallback::RUNLEVEL, msg);
#endif
}
Ejemplo n.º 6
0
	void lock()
	{
#ifdef DEBUG
		if (locked) throw "Already locked";
#endif
		cs->enter();
		locked = true;
	}
Ejemplo n.º 7
0
void JUCETaskResume(int taskID)
{
	tasklistmutex.enter();
	JUCETask *thistask;
	thistask = taskArray[taskID];
	tasklistmutex.exit();
	if (thistask != NULL) thistask->startThread();
}
Ejemplo n.º 8
0
 void pop (_et &element) 
 {
     data_avail.wait();
     c_region.enter();
     element = elements[first];
     first = (first + 1) % element_count;
     active_buffers--;
     c_region.leave();
     free_space.signal();
 }
Ejemplo n.º 9
0
 void push(const _et &element)
 {
     free_space.wait();
     c_region.enter();
     int next = (last + 1) % element_count;
     elements[last] = element;
     last = next;
     active_buffers++;
     c_region.leave();
     data_avail.signal();
 }
Ejemplo n.º 10
0
void MutexList_Add(CriticalSection *mutexPointer, int mutexID)
{
	queuelistmutex.enter();
	MutexList_t *root = MutexList;
	MutexList_t *newentry = new MutexList_t;
	newentry->mutexID = mutexID;
	newentry->mutexPointer = mutexPointer;
	newentry->next = root;
	MutexList = newentry;
	queuelistmutex.exit();
}
Ejemplo n.º 11
0
 bool lock(SessionId owner,bool exclusive, unsigned timeout)
 {
     CTimeMon tm(timeout);
     sect.enter();
     loop {
         unsigned num = owners.ordinality();
         if (exclusive) {
             if (num==0) {
                 owners.append(owner);
                 exclusivenest = 1;
                 break;
             }
             else if (exclusivenest && (owners.item(0)==owner)) {
                 exclusivenest++;
                 break;
             }
         }
         else if (!exclusivenest) {
             owners.append(owner);
             break;
         }
         waiting++;
         sect.leave();
         unsigned remaining;
         if (tm.timedout(&remaining)||!sem.wait(remaining)) {
             sect.enter();
             if (!sem.wait(0)) {
                 waiting--;
                 sect.leave();
                 return false;
             }
         }
         else
             sect.enter();
     }
     sect.leave();
     return true;
 }
Ejemplo n.º 12
0
 bool push(const _et &element,long timeout)
 {
     if (free_space.wait(timeout) ) {
         c_region.enter();
         int next = (last + 1) % element_count;
         elements[last] = element;
         last = next;
         active_buffers++;
         c_region.leave();
         data_avail.signal();
         return true;
     }
     return false;
 }
Ejemplo n.º 13
0
int ServiceManager::release(void *svcptr) {
  if (svcptr == NULL) return 0;

  waServiceFactory *wsvc = NULL;
  cs.enter();	// note cs getting locked twice via release+unlock
  if (!lockmap.getItem(svcptr, &wsvc)) {
    cs.leave();
    DebugString("WARNING: got release with no lock record!");
    return 0;
  }
  unlock(svcptr);
  cs.leave();

  ASSERT(wsvc != NULL);
  return wsvc->releaseInterface(svcptr);
}
Ejemplo n.º 14
0
void JUCETaskSuspend(int taskID)
{
	tasklistmutex.enter();
	JUCETask *thistask;
	thistask = taskArray[taskID];
	tasklistmutex.exit();
	if (thistask != NULL) 
	{
		if (Thread::getCurrentThreadId() != thistask->getThreadId())
		{
			thistask->stopThread(5000);
		}
		
		else thistask->signalThreadShouldExit();
		
	}
	
}
Ejemplo n.º 15
0
int MutexListList_GetID(CriticalSection *mutexPointer)
{
	queuelistmutex.enter();
	MutexList_t *temp = MutexList;
	int returnID = -1;
	
	while (temp != NULL)
	{
		if (temp->mutexPointer == mutexPointer)
		{
			returnID = temp->mutexID;
			break;
		}
		
		temp = temp->next;
	}
	queuelistmutex.exit();
	
	return returnID;
}
Ejemplo n.º 16
0
void JUCETaskResumeAll(void)
{
	tasklistmutex.enter();
	JUCETask *thistaskArray[MAX_JUCETASKS];
	for (unsigned int i = 0; i < MAX_JUCETASKS; i++)
	{
		thistaskArray[i] = taskArray[i];		
	}
	tasklistmutex.exit();
	
	for (unsigned int i = 0; i < MAX_JUCETASKS; i++)
	{
		if (thistaskArray[i] != NULL)
		{
			thistaskArray[i]->startThread();
		}
		
	}
	
}
Ejemplo n.º 17
0
CriticalSection *MutexList_GetPointer(int mutexID)
{
	queuelistmutex.enter();
	MutexList_t *temp = MutexList;
	CriticalSection *returnPointer = NULL;
	
	while (temp != NULL)
	{
		if (temp->mutexID == mutexID)
		{
			returnPointer = temp->mutexPointer;
			break;
		}
		
		temp = temp->next;
	}
	
	queuelistmutex.exit();
	return returnPointer;
	
}
Ejemplo n.º 18
0
int ServiceManager::unlock(void *svcptr) {
  if (svcptr == NULL) return 0;

  waServiceFactory *wsvc = NULL;
  cs.enter();
  if (!lockmap.getItem(svcptr, &wsvc)) {
    cs.leave();
    DebugString("WARNING: got unlock with no lock record!");
    return 0;
  }

  int r = lockmap.delItem(svcptr);
  ASSERT(r);

  //CUT  // this might fail, client locking isn't enforceable
  //CUT  clientmap.delItem(svcptr);

  cs.leave();

  return 1;
}
Ejemplo n.º 19
0
int ServiceManager::deregisterService(waServiceFactory *service, int internal) {
  GUID svctype = GetServiceTypeL(service);
  // make sure it was there
  cs.enter();
  if (services.multiHaveItem(svctype, service)) {
    // make sure there aren't still services issued by this guy
    //  ASSERT(internal || !lockmap.reverseGetItem(service));
    services.multiDelItem(svctype, service);
    ownermap.delItem(service);
    services_by_guid.reverseDelItem(service);
  }
  cs.leave();
  service->serviceNotify(SvcNotify::ONDEREGISTERED);

#ifdef WASABI_COMPILE_SYSCB
  CallbackManager::issueCallback(SysCallback::SERVICE,
    SvcCallback::ONDEREGISTER,
    reinterpret_cast<long>(&svctype), reinterpret_cast<long>(service));
#endif

  return 1;
}
Ejemplo n.º 20
0
 void unlock(SessionId owner)
 {
     sect.enter();
     if (exclusivenest) {
         exclusivenest--;
         if (exclusivenest) { // still locked
             assertex(owners.item(0)==owner);
             sect.leave();
             return;
         }
     }
     verifyex(owners.zap(owner));
     if (owners.ordinality()==0) {
         exclusivenest = 0;
         if (waiting) {
             sem.signal(waiting);
             waiting = 0;
         }
     }
     else {
         assertex(!exclusivenest);
     }
     sect.leave();
 }
Ejemplo n.º 21
0
void JUCETaskSuspendAll(void)
{
	tasklistmutex.enter();
	JUCETask *thistaskArray[MAX_JUCETASKS];
	for (unsigned int i = 0; i < MAX_JUCETASKS; i++)
	{
		thistaskArray[i] = taskArray[i];		
	}
	tasklistmutex.exit();
	
	for (unsigned int i = 0; i < MAX_JUCETASKS; i++)
	{
		if (thistaskArray[i] != NULL)
		{
			if ( Thread::getCurrentThreadId() != thistaskArray[i]->getThreadId() )
			{
				thistaskArray[i]->stopThread(5000);
			}
			
		}
		
	}
	
}
Ejemplo n.º 22
0
 unsigned in_queue() {
     c_region.enter();
     unsigned res = active_buffers;
     c_region.leave();
     return res;
 }
Ejemplo n.º 23
0
void TrackComponent::mouseDown(const MouseEvent &e) {

	ModifierKeys modifiers = ModifierKeys::getCurrentModifiersRealtime();

    int posX;
	// check the mod keys ..
	if (modifiers.isPopupMenu() || modifiers.isCtrlDown())
	{
		ScopedPointer<PopupMenu> trackMenu_ = new PopupMenu();
		trackMenu_->clear();
		trackMenu_->addCommandItem(&_commands, MainWindow::showMixer);
		trackMenu_->addItem(1, "Add Region", true);
        MouseEvent ev = e.getEventRelativeTo(this);
        for(auto region : _regionComponents)
        {
            posX = ev.x;
            region->setBroughtToFrontOnMouseClick(true);
            if(region->getPositionX() < posX && posX < (region->getPositionX() + region->getRegionWidth()))
            {
                trackMenu_->addItem(2, "Remove Region", true);
            }
        }
        switch (trackMenu_->show())
        {
            case 1:
            {
                FileChooser chooser("Select an audio file to add...",
                                    File::nonexistent,
                                    "*.wav; *aif; *.flac");
                if (chooser.browseForFileToOpen()) {
                    File audioFile(chooser.getResult());
                    const String fileString = audioFile.getFullPathName();
                    String format;
                    if (fileString.contains(".wav"))
                        format = "WAV";
                    else if (fileString.contains(".aif") || fileString.contains(".aiff"))
                        format = "AIFF";
                    else if (fileString.contains(".flac"))
                        format = "FLAC";
                    AudioFormatManager formatManager;
                    formatManager.registerBasicFormats();
                    
                    AudioFormatReader* reader = formatManager.createReaderFor(audioFile);
                    Audio::Region* region = new Audio::SampleRegion(reader, 1, &audioFile);
                    Point<int> position = e.getPosition();
                    int x = position.getX();
                    
                    if (x > _mixerOffset)
                    {
                        int64 samplesRange = secondsToSamples(100, _sampleRate);
                        int64 positionSamples = pixelsToSamples(x - _mixerOffset, 100 * _pixelsPerClip, samplesRange);
                        
                        _track->add(positionSamples, region);
                        createRegionGUI(x, region, formatManager, audioFile);
                        getParentComponent()->resized();
                    }
                    else if (x < _mixerOffset)
                    {
                        _track->add(0, region);
                        createRegionGUI(_mixerOffset, region, formatManager, audioFile);
                        getParentComponent()->resized();
                    }
                }
            }
                break;
            case 2:
            {
                CriticalSection critical;
                critical.enter();
                for(size_t i = 0; i < _regionComponents.size(); ++i)
                {
                    
                    Rectangle<int> bounds_ = _regionComponents.at(i)->getBounds();
					posX = ev.x;
                    if((int)_regionComponents.at(i)->getPositionX() < posX && posX < ((int)_regionComponents.at(i)->getPositionX() + (int)_regionComponents.at(i)->getRegionWidth()))
                    {
                        _track->remove(_regionComponents.at(i)->getRegion(), _posX.at(i));
                        std::vector<RegionComponent*>::iterator regit = _regionComponents.begin() + i;
                        RegionComponent* component = _regionComponents.at(i);
                        removeChildComponent(_regionComponents.at(i));
                        _regionComponents.erase(regit);
                        delete component;
                        _regions.erase(_posX.at(i));
                        std::vector<int64>::iterator posit = _posX.begin() + i;;
                        _posX.erase(posit);
                        std::vector<int64>::iterator sampsit = _sizeSamps.begin() + i;;
                        _sizeSamps.erase(sampsit);
                    }
                }
                critical.exit();
            }
            default:
                break;
        }
    }
}