📄 sema.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 sema@a Peter Boncz@v 1.0@-This module provides simple SMP lock and thread functionalityas already present in the MonetDB system.@{@+ semaphores@malatom sema:ptr;command create(init:int ) :sema address SEMAcreatecomment "Create an unset sema, with an initial value";command down(s:sema) address SEMAdowncomment "Decrement the semaphpore if >0; else block";command up(s:sema) address SEMAupcomment "Increment the semaphore";command destroy(s:sema) address SEMAdestroycomment "Destroy a semaphore";@+ Implementation@c#include "mal_config.h"#include <gdk.h>#include "mal_exception.h"typedef ptr sema;typedef ptr monet_sema;#ifdef WIN32#ifndef LIBSEMA#define sema_export extern __declspec(dllimport)#else#define sema_export extern __declspec(dllexport)#endif#else#define sema_export extern#endifintcreate_sema(monet_sema *s, int *init){ *s = (monet_sema) GDKmalloc(sizeof(MT_Sema)); if (*s == NULL || *s == ptr_nil) return GDK_FAIL; MT_sema_init((MT_Sema *) *s, *init); return GDK_SUCCEED;}intup_sema(monet_sema *s){ if (*s == NULL || *s == ptr_nil) return GDK_FAIL; MT_sema_up((MT_Sema*) *s, "up_sema"); return GDK_SUCCEED;}intdown_sema(monet_sema *s){ if (*s == NULL || *s == ptr_nil) return GDK_FAIL; MT_sema_down((MT_Sema*) *s, "down_sema"); return GDK_SUCCEED;}intdestroy_sema(monet_sema *s){ if (*s == NULL || *s == ptr_nil) return GDK_FAIL; MT_sema_destroy((MT_Sema*) *s); GDKfree(*s); return GDK_SUCCEED;}@-The old code base is wrapped to ease update propagation.@c#include "mal.h"sema_export str SEMAcreate(monet_sema *res, int *init);strSEMAcreate(monet_sema *res, int *init){ create_sema(res, init); return MAL_SUCCEED;}sema_export str SEMAup(int *res, monet_sema *s);strSEMAup(int *res, monet_sema *s){ up_sema(s); *res = 1; return MAL_SUCCEED;}sema_export str SEMAdown(int *res, monet_sema *s);strSEMAdown(int *res, monet_sema *s){ down_sema(s); *res = 1; return MAL_SUCCEED;}sema_export str SEMAdestroy(int *res, monet_sema *s);strSEMAdestroy(int *res, monet_sema *s){ destroy_sema(s); *res = 1; return MAL_SUCCEED;}@}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -