Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.68 KB | None | 0 0
  1. diff --git a/framework/src/framework/bot.cr b/framework/src/framework/bot.cr
  2. index 70dec75..aa574cb 100644
  3. --- a/framework/src/framework/bot.cr
  4. +++ b/framework/src/framework/bot.cr
  5. @@ -14,11 +14,11 @@ require "./plugin"
  6.  
  7. module Framework
  8. class Bot
  9. - getter config
  10. - getter! connection
  11. + getter config
  12. + getter! connection
  13. property! user
  14. - delegate channels, config
  15. - delegate logger, config
  16. + delegate channels, config
  17. + delegate logger, config
  18.  
  19. def self.create
  20. new.tap do |bot|
  21. @@ -27,7 +27,7 @@ module Framework
  22. end
  23.  
  24. private def initialize
  25. - @config = Configuration.new
  26. + @config = Configuration.new
  27. @filters = [] of Filter::Item
  28. @started = false
  29.  
  30. @@ -35,7 +35,7 @@ module Framework
  31. end
  32.  
  33. macro add_plugin(klass)
  34. - config.add_plugin Framework::PluginContainer({{klass}}).new
  35. + config.add_plugin Framework::PluginContainer({{klass}}, {{klass}}::Config).new
  36. end
  37.  
  38. def add_filter(filter : Filter::Item)
  39. @@ -54,7 +54,7 @@ module Framework
  40.  
  41. channel.on_message do |message|
  42. message = Message.new self, message
  43. - event = Event.new(self, :message, message)
  44. + event = Event.new(self, :message, message)
  45. config.plugins.each_value &.handle(event)
  46. end
  47.  
  48. diff --git a/framework/src/framework/configuration.cr b/framework/src/framework/configuration.cr
  49. index 31f3a74..fb7c0d7 100644
  50. --- a/framework/src/framework/configuration.cr
  51. +++ b/framework/src/framework/configuration.cr
  52. @@ -35,7 +35,7 @@ module Framework
  53. new false
  54. end
  55.  
  56. - def initialize(channels : Array(String)|Bool)
  57. + def initialize(channels : Array(String) | Bool)
  58. case channels
  59. when Bool
  60. @wants_channel_messsages = channels
  61. @@ -95,14 +95,14 @@ module Framework
  62.  
  63. def to_json(io)
  64. value = if @wants_channel_messsages
  65. - if @channels.empty?
  66. - nil
  67. - else
  68. - @channels
  69. - end
  70. - else
  71. - false
  72. - end
  73. + if @channels.empty?
  74. + nil
  75. + else
  76. + @channels
  77. + end
  78. + else
  79. + false
  80. + end
  81.  
  82. value.to_json io
  83. end
  84. @@ -120,7 +120,7 @@ module Framework
  85. include Plugin
  86.  
  87. JSON.mapping({
  88. - channels: {type: Framework::Configuration::Plugin::ChannelList, nilable: true, emit_null: true}
  89. + channels: {type: Framework::Configuration::Plugin::ChannelList, nilable: true, emit_null: true},
  90. })
  91.  
  92. def initialize_empty
  93. @@ -128,9 +128,9 @@ module Framework
  94. end
  95. end
  96.  
  97. - property! name
  98. + property! name : String
  99. delegate listens_to?, channels!
  100. - delegate wants?, channels!
  101. + delegate wants?, channels!
  102.  
  103. def channels!
  104. @channels ||= ChannelList.default
  105. @@ -144,18 +144,18 @@ module Framework
  106. class Store
  107. JSON.mapping({
  108. server: {type: String},
  109. - port: {type: Int32, nilable: true},
  110. + port: {type: Int32, nilable: true},
  111. channels: {type: Array(String)},
  112. nick: {type: String},
  113. - user: {type: String, nilable: true},
  114. - password: {type: String, nilable: true, emit_null: true},
  115. - nickserv_regain: {type: Bool, nilable: true},
  116. - realname: {type: String, nilable: true},
  117. - ssl: {type: Bool, nilable: true},
  118. - try_sasl: {type: Bool, nilable: true},
  119. - log_level: {type: String, nilable: true},
  120. - ignores: {type: Array(String), nilable: true},
  121. - plugins: {type: Hash(String, JSON::Any), nilable: true}
  122. + user: {type: String, nilable: true},
  123. + password: {type: String, nilable: true, emit_null: true},
  124. + nickserv_regain: {type: Bool, nilable: true},
  125. + realname: {type: String, nilable: true},
  126. + ssl: {type: Bool, nilable: true},
  127. + try_sasl: {type: Bool, nilable: true},
  128. + log_level: {type: String, nilable: true},
  129. + ignores: {type: Array(String), nilable: true},
  130. + plugins: {type: Hash(String, JSON::Any), nilable: true},
  131. }, true)
  132.  
  133. def self.load_plugins(config, json)
  134. @@ -183,33 +183,33 @@ module Framework
  135. end
  136.  
  137. def to_json(config : Configuration)
  138. - self.port = config.port
  139. - self.channels = config.channels
  140. - self.user = config.user
  141. - self.password = config.password
  142. + self.port = config.port
  143. + self.channels = config.channels
  144. + self.user = config.user
  145. + self.password = config.password
  146. self.nickserv_regain = config.nickserv_regain?
  147. - self.realname = config.realname
  148. - self.ssl = config.ssl?
  149. - self.try_sasl = config.try_sasl?
  150. - self.log_level = config.log_level
  151. - self.ignores = config.ignores
  152. + self.realname = config.realname
  153. + self.ssl = config.ssl?
  154. + self.try_sasl = config.try_sasl?
  155. + self.log_level = config.log_level
  156. + self.ignores = config.ignores
  157.  
  158. to_pretty_json
  159. end
  160.  
  161. def restore(config)
  162. - config.server = server
  163. - config.port = port unless port.nil?
  164. - config.channels = channels
  165. - config.nick = nick
  166. - config.user = user unless user.nil?
  167. - config.password = password unless password.nil?
  168. + config.server = server
  169. + config.port = port unless port.nil?
  170. + config.channels = channels
  171. + config.nick = nick
  172. + config.user = user unless user.nil?
  173. + config.password = password unless password.nil?
  174. config.nickserv_regain = nickserv_regain unless nickserv_regain.nil?
  175. - config.realname = realname unless realname.nil?
  176. - config.ssl = ssl unless ssl.nil?
  177. - config.try_sasl = try_sasl unless try_sasl.nil?
  178. - config.log_level = log_level unless log_level.nil?
  179. - config.ignores = ignores unless ignores.nil?
  180. + config.realname = realname unless realname.nil?
  181. + config.ssl = ssl unless ssl.nil?
  182. + config.try_sasl = try_sasl unless try_sasl.nil?
  183. + config.log_level = log_level unless log_level.nil?
  184. + config.ignores = ignores unless ignores.nil?
  185. end
  186. end
  187.  
  188. @@ -218,38 +218,41 @@ module Framework
  189. "info" => Logger::Severity::INFO,
  190. "warn" => Logger::Severity::WARN,
  191. "error" => Logger::Severity::ERROR,
  192. - "fatal" => Logger::Severity::FATAL
  193. + "fatal" => Logger::Severity::FATAL,
  194. }
  195.  
  196. - property! server
  197. - property port
  198. - property channels
  199. + property! server : String?
  200. + property port : Int32?
  201. + property channels
  202. property! nick
  203. - property! user
  204. - property password
  205. - property? nickserv_regain
  206. - property! realname
  207. - property? ssl
  208. - property? try_sasl
  209. - property log_level
  210. - property! ignores
  211. - getter logger
  212. - getter plugins
  213. + property! user : String?
  214. + property password : String?
  215. + property? nickserv_regain : Bool?
  216. + property! realname : String?
  217. + property? ssl : Bool?
  218. + property? try_sasl : Bool?
  219. + property log_level : String?
  220. + property! ignores : Array(String)?
  221. + getter logger
  222. + getter plugins
  223. +
  224. + @config_file : String?
  225. + @store : Store?
  226.  
  227. def initialize
  228. - @plugins = Hash(String, PluginContainer::Workaround).new
  229. + @plugins = Hash(String, PluginContainer::Workaround).new
  230. @channels = [] of String
  231. - @logger = Logger.new(STDOUT)
  232. + @logger = Logger.new(STDOUT)
  233.  
  234. - @nick = "CeBot"
  235. - @user = "cebot"
  236. - @password = nil
  237. + @nick = "CeBot"
  238. + @user = "cebot"
  239. + @password = nil
  240. @nickserv_regain = false
  241. - @realname = "CeBot"
  242. - @ssl = false
  243. - @try_sasl = false
  244. - @log_level = "info"
  245. - @ignores = [] of String
  246. + @realname = "CeBot"
  247. + @ssl = false
  248. + @try_sasl = false
  249. + @log_level = "info"
  250. + @ignores = [] of String
  251.  
  252. set_log_level
  253. end
  254. @@ -301,15 +304,15 @@ module Framework
  255. load if @config_file
  256.  
  257. IRC::Connection.build do |config|
  258. - config.server = server
  259. - config.port = port
  260. - config.nick = nick
  261. - config.user = user
  262. + config.server = server
  263. + config.port = port
  264. + config.nick = nick
  265. + config.user = user
  266. config.password = password
  267. config.realname = realname
  268. - config.ssl = ssl?
  269. + config.ssl = ssl?
  270. config.try_sasl = try_sasl?
  271. - config.logger = logger
  272. + config.logger = logger
  273. end
  274. end
  275.  
  276. diff --git a/framework/src/framework/event.cr b/framework/src/framework/event.cr
  277. index 8090b21..dd88e96 100644
  278. --- a/framework/src/framework/event.cr
  279. +++ b/framework/src/framework/event.cr
  280. @@ -7,9 +7,9 @@ module Framework
  281. class Event
  282. getter context
  283. getter type
  284. - getter! sender
  285. - getter! channel
  286. - getter! message
  287. + getter! sender : User
  288. + getter! channel : Channel
  289. + getter! message : Message
  290.  
  291. def initialize(@context : Bot, @type : Symbol, @message : Message)
  292. @sender = message.sender
  293. diff --git a/framework/src/framework/filter.cr b/framework/src/framework/filter.cr
  294. index 90cd69f..1eaf4ea 100644
  295. --- a/framework/src/framework/filter.cr
  296. +++ b/framework/src/framework/filter.cr
  297. @@ -9,7 +9,7 @@ module Framework
  298. class NickFilter
  299. include Filter
  300.  
  301. - def initialize(@config)
  302. + def initialize(@config : Configuration)
  303. end
  304.  
  305. def call(event)
  306. diff --git a/framework/src/framework/json_store.cr b/framework/src/framework/json_store.cr
  307. index d23a129..b6522ce 100644
  308. --- a/framework/src/framework/json_store.cr
  309. +++ b/framework/src/framework/json_store.cr
  310. @@ -4,7 +4,7 @@ require "thread/read_write_lock"
  311.  
  312. module Framework
  313. class JsonStore(K, V)
  314. - def initialize(@path)
  315. + def initialize(@path : String)
  316. @lock = ReadWriteLock.new
  317. @data = Hash(K, V).new
  318. load
  319. diff --git a/framework/src/framework/plugin.cr b/framework/src/framework/plugin.cr
  320. index 0bd0d20..9c6f871 100644
  321. --- a/framework/src/framework/plugin.cr
  322. +++ b/framework/src/framework/plugin.cr
  323. @@ -9,12 +9,10 @@ module Framework
  324. module Plugin
  325. macro config(properties)
  326. {% for key, value in properties %}
  327. - {% properties[key] = {type: value} unless value.is_a?(HashLiteral) %}
  328. + {% properties[key] = {type: value} unless value.is_a?(HashLiteral) || value.is_a?(NamedTupleLiteral) %}
  329. {% end %}
  330.  
  331. class Config
  332. - include Framework::Configuration::Plugin
  333. -
  334. JSON.mapping({
  335. :channels => {type: Framework::Configuration::Plugin::ChannelList, nilable: true, emit_null: true},
  336. {% for key, value in properties %}
  337. @@ -29,15 +27,19 @@ module Framework
  338. {% end %}
  339. end
  340. end
  341. -
  342. - def self.config_class
  343. - Config
  344. - end
  345. end
  346.  
  347. macro included
  348. + class Config
  349. + include Framework::Configuration::Plugin
  350. +
  351. + JSON.mapping({
  352. + channels: {type: Framework::Configuration::Plugin::ChannelList, nilable: true, emit_null: true},
  353. + })
  354. + end
  355. +
  356. def self.config_class
  357. - Framework::Configuration::Plugin::Default
  358. + Config
  359. end
  360.  
  361. @@matchers = [] of Regex
  362. @@ -88,7 +90,7 @@ module Framework
  363. Timer.new seconds, 1, &block
  364. end
  365.  
  366. - def every(seconds, limit=nil, &block)
  367. + def every(seconds, limit = nil, &block)
  368. Timer.new seconds, limit, &block
  369. end
  370.  
  371. diff --git a/framework/src/framework/plugin_container.cr b/framework/src/framework/plugin_container.cr
  372. index c366cb3..c569a7c 100644
  373. --- a/framework/src/framework/plugin_container.cr
  374. +++ b/framework/src/framework/plugin_container.cr
  375. @@ -3,11 +3,11 @@ require "json"
  376. require "./plugin"
  377.  
  378. module Framework
  379. - class PluginContainer(T)
  380. + class PluginContainer(T, C)
  381. module Workaround; end
  382. include Workaround
  383.  
  384. - getter config
  385. + getter config : C?
  386. delegate channels, config
  387. delegate wants?, config
  388.  
  389. diff --git a/irc/src/irc/connection.cr b/irc/src/irc/connection.cr
  390. index abec039..e0769d9 100644
  391. --- a/irc/src/irc/connection.cr
  392. +++ b/irc/src/irc/connection.cr
  393. @@ -17,25 +17,25 @@ require "./workers"
  394. module IRC
  395. class Connection
  396. class Config
  397. - property! server
  398. - property port
  399. - property nick
  400. - property user
  401. - property! password
  402. - property realname
  403. - property! ssl
  404. - property! try_sasl
  405. - setter logger
  406. + property! server : String?
  407. + property port
  408. + property nick
  409. + property user
  410. + property! password : String?
  411. + property realname
  412. + property! ssl : Bool?
  413. + property! try_sasl : Bool?
  414. + setter logger
  415.  
  416. private def initialize
  417. - @port = 6667
  418. - @nick = "Crystal"
  419. - @user = "crystal"
  420. - @password = nil
  421. - @realname = "Crystal IRC"
  422. - @ssl = false
  423. - @try_sasl = false
  424. - @logger = nil
  425. + @port = 6667
  426. + @nick = "Crystal"
  427. + @user = "crystal"
  428. + @password = nil
  429. + @realname = "Crystal IRC"
  430. + @ssl = false
  431. + @try_sasl = false
  432. + @logger = nil
  433. end
  434.  
  435. def self.new(server : String)
  436. @@ -79,12 +79,12 @@ module IRC
  437. end
  438.  
  439. def initialize(@config : Config)
  440. - @send_queue = ::Channel(String).new(64)
  441. - @users = UserManager.new
  442. - @channels = Repository(String, Channel).new
  443. - @processor = Processor.new(logger)
  444. - @network = Network.new
  445. - @connected = false
  446. + @send_queue = ::Channel(String).new(64)
  447. + @users = UserManager.new
  448. + @channels = Repository(String, Channel).new
  449. + @processor = Processor.new(logger)
  450. + @network = Network.new
  451. + @connected = false
  452. @exit_channel = ::Channel(Int32).new
  453.  
  454. @users.track Mask.parse(@config.nick) # Track self with pseudo mask
  455. @@ -179,9 +179,9 @@ module IRC
  456. logger.info "Connecting to #{config.server}:#{config.port}#{" (SSL enabled)" if config.ssl?}"
  457.  
  458. socket = TCPSocket.new config.server, config.port
  459. - socket.read_timeout = 300
  460. + socket.read_timeout = 300
  461. socket.write_timeout = 5
  462. - socket.keepalive = true
  463. + socket.keepalive = true
  464.  
  465. socket = OpenSSL::SSL::Socket.new socket if config.ssl?
  466.  
  467. @@ -203,7 +203,7 @@ module IRC
  468. end
  469. when "ACK"
  470. network.account_notify = true if cap.parameters.last == "account-notify"
  471. - network.extended_join = true if cap.parameters.last == "extended-join"
  472. + network.extended_join = true if cap.parameters.last == "extended-join"
  473.  
  474. if cap.parameters.last == "sasl"
  475. send Message::AUTHENTICATE, "PLAIN"
  476. @@ -218,10 +218,9 @@ module IRC
  477. send Message::AUTHENTICATE, Base64.strict_encode("#{config.nick}\0#{config.nick}\0#{config.password}")
  478. end
  479.  
  480. - on(Message::RPL_LOGGEDIN, Message::RPL_LOGGEDOUT, Message::ERR_NICKLOCKED,
  481. - Message::RPL_SASLSUCCESS, Message::ERR_SASLFAIL, Message::ERR_SASLTOOLONG,
  482. - Message::RPL_SASL_ABORTED, Message::ERR_SASLALREADY) do |message|
  483. -
  484. + on(Message::RPL_LOGGEDIN, Message::RPL_LOGGEDOUT, Message::ERR_NICKLOCKED,
  485. + Message::RPL_SASLSUCCESS, Message::ERR_SASLFAIL, Message::ERR_SASLTOOLONG,
  486. + Message::RPL_SASL_ABORTED, Message::ERR_SASLALREADY) do |message|
  487. if {Message::RPL_LOGGEDIN, Message::RPL_SASLSUCCESS, Message::ERR_SASLALREADY}.includes? message.type
  488. logger.info "SASL authentication succeeded"
  489. else
  490. @@ -289,14 +288,14 @@ module IRC
  491. logger.info "Connected"
  492. end
  493.  
  494. - def quit(message="Crystal IRC")
  495. + def quit(message = "Crystal IRC")
  496. send Message::QUIT, message
  497. @processor.handle_others
  498. stop_workers
  499. exit
  500. end
  501.  
  502. - def exit(code=0)
  503. + def exit(code = 0)
  504. @exit_channel.send code
  505. @exit_channel.close
  506. @processor.handle_others
  507. diff --git a/irc/src/irc/modes.cr b/irc/src/irc/modes.cr
  508. index 6f78d72..1bda871 100644
  509. --- a/irc/src/irc/modes.cr
  510. +++ b/irc/src/irc/modes.cr
  511. @@ -3,9 +3,9 @@ module IRC
  512. module Parser
  513. def self.parse(modes)
  514. parameters = modes.split(" ")
  515. - modes = seperate_flags parameters.shift? || ""
  516. + modes = seperate_flags parameters.shift? || ""
  517.  
  518. - (modes.size-parameters.size).times do
  519. + (modes.size - parameters.size).times do
  520. mode = modes.shift
  521. modifier, flag = mode
  522.  
  523. @@ -36,12 +36,12 @@ module IRC
  524. end
  525. end
  526.  
  527. - record Flag, flag, parameter
  528. + record Flag, flag : Char, parameter : String?
  529.  
  530. include Enumerable(Flag)
  531.  
  532. - def initialize(modes="")
  533. - @plain_flags = Set(Flag).new
  534. + def initialize(modes = "")
  535. + @plain_flags = Set(Flag).new
  536. @parameterized_flags = Set(Flag).new
  537. parse modes
  538. end
  539. @@ -57,10 +57,10 @@ module IRC
  540. end
  541.  
  542. def get(flag : Char)
  543. - @parameterized_flags.find {|item| item.flag == flag }.try(&.parameter)
  544. + @parameterized_flags.find { |item| item.flag == flag }.try(&.parameter)
  545. end
  546.  
  547. - def set(flag : Char, parameter=nil)
  548. + def set(flag : Char, parameter = nil)
  549. mode = Flag.new(flag, parameter)
  550.  
  551. if parameter
  552. @@ -70,7 +70,7 @@ module IRC
  553. end
  554. end
  555.  
  556. - def unset(flag : Char, parameter=nil)
  557. + def unset(flag : Char, parameter = nil)
  558. mode = Flag.new(flag, parameter)
  559.  
  560. if parameter
  561. @@ -82,13 +82,13 @@ module IRC
  562.  
  563. # pass false as parameter to look only at the flag but only in the
  564. # parameterized flags
  565. - def set?(flag : Char, parameter=nil)
  566. + def set?(flag : Char, parameter = nil)
  567. mode = Flag.new(flag, parameter)
  568.  
  569. if parameter
  570. @parameterized_flags.includes? mode
  571. elsif parameter == false
  572. - @parameterized_flags.any? &.flag==(flag)
  573. + @parameterized_flags.any? &.flag == (flag)
  574. else
  575. @plain_flags.includes? mode
  576. end
  577. diff --git a/irc/src/irc/user.cr b/irc/src/irc/user.cr
  578. index a6a2829..544e3be 100644
  579. --- a/irc/src/irc/user.cr
  580. +++ b/irc/src/irc/user.cr
  581. @@ -36,8 +36,8 @@ module IRC
  582. # +x - Gives the user Hidden Hostname (security)
  583. # +Z, +z - Is connected via SSL (cannot be set or unset).
  584. class User
  585. - property authname
  586. - property realname
  587. + property authname : String?
  588. + property realname : String?
  589. getter channels
  590. getter mask
  591. getter modes
  592. @@ -45,11 +45,11 @@ module IRC
  593. delegate user, mask
  594. delegate host, mask
  595.  
  596. - def initialize(@mask)
  597. + def initialize(@mask : Mask)
  598. @authname = nil
  599. @realname = nil
  600. @channels = Repository(String, Membership).new
  601. - @modes = Modes.new
  602. + @modes = Modes.new
  603. end
  604.  
  605. def name
  606. @@ -65,12 +65,12 @@ module IRC
  607. end
  608.  
  609. {% for item in [{['A'], "server_admin"}, {['a'], "service_admin"}, {['B'], "bot"},
  610. - {['C'], "co_admin"}, {['D', 'd'], "deaf"}, {['h'], "available_for_help"},
  611. - {['i'], "invisible"}, {['N'], "network_admin"}, {['o'], "operator"},
  612. - {['O'], "local_operator"}, {['r'], "registered"}, {['S'], "service"},
  613. - {['w'], "receive_wallops"}, {['z', 'Z'], "secure"},] %}
  614. + {['C'], "co_admin"}, {['D', 'd'], "deaf"}, {['h'], "available_for_help"},
  615. + {['i'], "invisible"}, {['N'], "network_admin"}, {['o'], "operator"},
  616. + {['O'], "local_operator"}, {['r'], "registered"}, {['S'], "service"},
  617. + {['w'], "receive_wallops"}, {['z', 'Z'], "secure"}] %}
  618. {% flags = item[0] %}
  619. - {% name = item[1] %}
  620. + {% name = item[1] %}
  621. def {{name.id}}?
  622. {% for flag in flags %}
  623. @modes.set?({{flag}}) ||
  624. diff --git a/irc/src/irc/workers.cr b/irc/src/irc/workers.cr
  625. index 8e77c1e..6952cd3 100644
  626. --- a/irc/src/irc/workers.cr
  627. +++ b/irc/src/irc/workers.cr
  628. @@ -98,7 +98,7 @@ module IRC
  629. class Processor
  630. getter channel
  631. getter handlers
  632. - private getter logger
  633. + private getter logger : Logger
  634.  
  635. def initialize(@logger)
  636. @channel = ::Channel(Message).new(64)
  637. diff --git a/thread/src/thread/lib_pthread.cr b/thread/src/thread/lib_pthread.cr
  638. index 1a1ba40..451a940 100644
  639. --- a/thread/src/thread/lib_pthread.cr
  640. +++ b/thread/src/thread/lib_pthread.cr
  641. @@ -1,19 +1,17 @@
  642. -lib LibPThread
  643. - EDEADLK = 35
  644. +lib LibC
  645. + # MUTEX_RECURSIVE = 1
  646. + # MUTEX_ERRORCHECK = 2
  647.  
  648. - MUTEX_RECURSIVE = 1
  649. - MUTEX_ERRORCHECK = 2
  650. + fun pthread_mutexattr_init(mutex_attr : PthreadMutexattrT*) : Int32
  651. + fun pthread_mutexattr_settype(mutex_attr : PthreadMutexattrT*, type : Int32) : Int32
  652.  
  653. - fun mutexattr_init = pthread_mutexattr_init(mutex_attr : MutexAttr*) : Int32
  654. - fun mutexattr_settype = pthread_mutexattr_settype(mutex_attr : MutexAttr*, type : Int32) : Int32
  655. -
  656. - fun mutex_init_fixed = pthread_mutex_init(mutex : Mutex*, mutex_attr : MutexAttr*) : Int32
  657. + fun pthread_mutex_init(mutex : PthreadMutexT*, mutex_attr : PthreadMutexattrT*) : Int32
  658.  
  659. type Rwlock = Int64[8]
  660. type RwlockAttr = Void*
  661.  
  662. - fun rwlock_init = pthread_rwlock_init(lock : Rwlock*, lock_attr : RwlockAttr*) : Int32
  663. - fun rwlock_rdlock = pthread_rwlock_rdlock(lock : Rwlock*) : Int32
  664. - fun rwlock_wrlock = pthread_rwlock_wrlock(lock : Rwlock*) : Int32
  665. - fun rwlock_unlock = pthread_rwlock_unlock(lock : Rwlock*) : Int32
  666. + fun pthread_rwlock_init(lock : Rwlock*, lock_attr : RwlockAttr*) : Int32
  667. + fun pthread_rwlock_rdlock(lock : Rwlock*) : Int32
  668. + fun pthread_rwlock_wrlock(lock : Rwlock*) : Int32
  669. + fun pthread_rwlock_unlock(lock : Rwlock*) : Int32
  670. end
  671. diff --git a/thread/src/thread/read_write_lock.cr b/thread/src/thread/read_write_lock.cr
  672. index 63e7c02..f1ca706 100644
  673. --- a/thread/src/thread/read_write_lock.cr
  674. +++ b/thread/src/thread/read_write_lock.cr
  675. @@ -2,25 +2,25 @@ require "./lib_pthread"
  676.  
  677. class ReadWriteLock
  678. def initialize
  679. - LibPThread.rwlock_init(out @lock, nil)
  680. + LibC.pthread_rwlock_init(out @lock, nil)
  681. end
  682.  
  683. def read_lock
  684. - LibPThread.rwlock_rdlock(self)
  685. + LibC.pthread_rwlock_rdlock(self)
  686. yield
  687. ensure
  688. unlock
  689. end
  690.  
  691. def write_lock
  692. - LibPThread.rwlock_wrlock(self)
  693. + LibC.pthread_rwlock_wrlock(self)
  694. yield
  695. ensure
  696. unlock
  697. end
  698.  
  699. def unlock
  700. - LibPThread.rwlock_unlock(self)
  701. + LibC.pthread_rwlock_unlock(self)
  702. end
  703.  
  704. def to_unsafe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement