# Bryan Schumaker (5 / 7 / 2011)

import threading
from libsaria import callbacks
queue_lock   = threading.Lock()
lock_queue   = queue_lock.acquire
unlock_queue = queue_lock.release

# List of queued songs
queue_list = []

def add_ids(id_list):
	lock_queue()
	queue_list.extend(id_list)
	unlock_queue()

def rm_ids(id_list):
	lock_queue()
	for id in id_list:
		if id in queue_list:
			queue_list.remove(id)
	unlock_queue()
	callbacks.queue_changed()

def pop():
	lock_queue()
	id = None
	if len(queue_list) > 0:
		id = queue_list.pop(0)
	unlock_queue()
	callbacks.queue_changed()
	return id

def reset():
	global queue_list
	lock_queue()
	queue_list = []
	unlock_queue()

def as_set():
	lock_queue()
	song_set = set(queue_list)
	unlock_queue()
	return song_set
