function obtainMutex($filename, $mode)
    {
        if (isset($this->fplock[md5($filename)])) {
            $this->debug("Lock for $filename already exists");

            return FALSE;
        }
        $this->fplock[md5($filename)] = fopen($filename . ".lock", "w");
        if ($mode == "r") {
            return flock($this->fplock[md5($filename)], LOCK_SH);
        } else {
            return flock($this->fplock[md5($filename)], LOCK_EX);
        }
    }