⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lock.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
字号:
@' The contents of this file are subject to the MonetDB Public License@' Version 1.1 (the "License"); you may not use this file except in@' compliance with the License. You may obtain a copy of the License at@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html@'@' Software distributed under the License is distributed on an "AS IS"@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the@' License for the specific language governing rights and limitations@' under the License.@'@' The Original Code is the MonetDB Database System.@'@' The Initial Developer of the Original Code is CWI.@' Portions created by CWI are Copyright (C) 1997-2007 CWI.@' All Rights Reserved.@f lock@a Peter Boncz@v 1.0@+ Lightweight Lock ModuleThis module provides simple SMP lock and thread functionalityas already present in the MonetDB system.@{@+ Locks@malatom lock:ptr;command create() :lock address LCKcreatecomment "Create an unset lock";command set(l:lock) address LCKsetcomment "Try to set a lock. If set, block till it is freed";command try(l:lock) :int address LCKtrycomment "Try a lock. If free set it, if not return EBUSY";command unset(l:lock) address LCKunsetcomment "Unset a lock";command destroy(l:lock) address LCKdestroycomment "Destroy a lock";command tostr(l:lock) address lockToStrcomment "Overloaded atom function";@+ Implementation@c#include "mal_config.h"#include <gdk.h>#include "mal_exception.h"typedef ptr lock;typedef ptr monet_lock;#ifdef WIN32#ifndef LIBLOCK#define lock_export extern __declspec(dllimport)#else#define lock_export extern __declspec(dllexport)#endif#else#define lock_export extern#endifintcreate_lock(monet_lock *l){	*l = (monet_lock) GDKmalloc(sizeof(MT_Lock));	if (*l == NULL || *l == ptr_nil) return GDK_FAIL;	MT_lock_init((MT_Lock*) *l);	return GDK_SUCCEED;}intset_lock(monet_lock *l){	if (*l == NULL || *l == ptr_nil) return GDK_FAIL;	MT_lock_set((MT_Lock*) *l, "set_lock");	return GDK_SUCCEED;}inttry_lock(int *res, monet_lock *l){	if (*l == NULL || *l == ptr_nil) return GDK_FAIL;	*res = MT_lock_try((MT_Lock*) *l) ? EBUSY : 0;	return GDK_SUCCEED;}intunset_lock(monet_lock *l){	if (*l == NULL || *l == ptr_nil) return GDK_FAIL;	MT_lock_unset((MT_Lock*) *l, "unset_lock");	return GDK_SUCCEED;}intdestroy_lock(monet_lock *l){	if (*l == NULL || *l == ptr_nil) return GDK_FAIL;	MT_lock_destroy((MT_Lock*) *l);	GDKfree(*l);	return GDK_SUCCEED;}@-The old code base is wrapped to ease update propagation.@c#include "mal.h"lock_export int lockToStr(char **dst, int *len, ptr *src);intlockToStr(char **dst, int *len, ptr *src){	(void) len;		/* fool compiler */	(void) src;		/* fool compiler */	if (src == ptr_nil) {		strcpy(*dst, "nil");		return 3;	}	/* sprintf(*dst,"%o", (ptr)*src); */	sprintf(*dst, "redo lockToStr");	return strlen(*dst);}lock_export str LCKcreate(monet_lock *l);strLCKcreate(monet_lock *l){	create_lock(l);	return MAL_SUCCEED;}lock_export str LCKset(int *res, monet_lock *l);strLCKset(int *res, monet_lock *l){	set_lock(l);	*res = 1;	return MAL_SUCCEED;}lock_export str LCKtry(int *res, monet_lock *l);strLCKtry(int *res, monet_lock *l){	try_lock(res, l);	return MAL_SUCCEED;}lock_export str LCKunset(int *res, monet_lock *l);strLCKunset(int *res, monet_lock *l){	unset_lock(l);	*res = 1;	return MAL_SUCCEED;}lock_export str LCKdestroy(int *res, monet_lock *l);strLCKdestroy(int *res, monet_lock *l){	destroy_lock(l);	*res = 1;	return MAL_SUCCEED;}@}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -